How to view the number of fields in a table in the Oracle database

Source: Internet
Author: User

To query the total number of fields in a table in Oracle, use an SQL statement or Copy codeThe Code is as follows: select count (column_name) from user_tab_columns where table_name = 't_ B _AUDITOR'

The number of fields in the specified table can be found.
The following is a rough view:
Select tname, count (*) from col group by tname;
Copy codeThe Code is as follows: 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

Now I think of mysql:
Directly use functions to solve the problem:
Copy codeThe Code is as follows: 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:
Copy codeThe Code is as follows: 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 the number of databases in the database:
Copy codeThe Code is as follows: 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)

The number of tables in the mysql database:
Copy codeThe Code is as follows: 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 study this table.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.