Resolve how to view the number of fields of a table in Oracle database
- 2021-08-28 21:27:05
- OfStack
To query the total number of fields of a table in Oracle, use SQL statement or PL/SQL
The number of fields of the specified table can be found out.
The following is through a general view:
select tname,count(*) from col group by tname;
At this time, I think of mysql:
Use functions directly to solve:
There is also the use of system tables:
In mysql, you want to know how many libraries there are in the database:
How many tables are there in the mysql database:
In fact, most databases and tables in the system table information_schema will have records. So we should study this table carefully.
select count(column_name) from user_tab_columns where table_name='T_B_AUDITOR'
The number of fields of the specified table can be found out.
The following is through a general view:
select tname,count(*) from col group by tname;
64 T_A_BOOKSTAGEINFO 4
65 T_B_AUDITOR 14
66 T_B_BOOKMANAGEMENT 13
67 T_B_BOOKSTATUSCONFIG 5
68 T_B_CODETREEINFO 8
69 T_B_FILTERWORD 11
70 T_B_ISBNWHITELIST 11
71 T_B_MODEL 10
72 T_B_NOTICE 15
73 T_B_NOTICEACCEPT 11
74 T_B_OPERLOG 10
75 T_B_ORGANIZATIONINFO 18
76 T_B_PREFIXINFO 15
77 T_B_PUBLISHINFO 30
78 T_B_ROLE 8
79 T_B_ROLEMODEL 6
80 T_B_SAMPLEBOOKINFO 89
81 T_B_USER 26
82 T_B_USERANDROLE 6
83 T_B_USERLOGIN 8
84 T_B_USERMODEL 6
At this time, I think of mysql:
Use functions directly to solve:
mysql> desc test;
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(10) | YES | | NULL | |
| address | varchar(30) | YES | | NULL | |
+---------+-------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
mysql> select found_rows();
+--------------+
| found_rows() |
+--------------+
| 3 |
+--------------+
1 row in set (0.01 sec)
There is also the use of system tables:
mysql> use information_schema
Database changed
mysql> select count(*) from columns where table_name="test";
+----------+
| count(*) |
+----------+
| 3 |
+----------+
1 row in set (0.00 sec)
In mysql, you want to know how many libraries there are in the database:
mysql> select * from schemata;
+--------------+--------------------+----------------------------+------------------------+----------+
| CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH |
+--------------+--------------------+----------------------------+------------------------+----------+
| NULL | information_schema | utf8 | utf8_general_ci | NULL |
| NULL | mysql | utf8 | utf8_general_ci | NULL |
| NULL | test | utf8 | utf8_general_ci | NULL |
+--------------+--------------------+----------------------------+------------------------+----------+
3 rows in set (0.00 sec)
How many tables are there in the mysql database:
mysql> select table_schema,count(*) from tables group by table_schema;
+--------------------+----------+
| table_schema | count(*) |
+--------------------+----------+
| information_schema | 17 |
| mysql | 17 |
| test | 6 |
+--------------------+----------+
3 rows in set (0.00 sec)
In fact, most databases and tables in the system table information_schema will have records. So we should study this table carefully.