查看Oracle資料庫中某張表的欄位個數

來源:互聯網
上載者:User

Oracle中查詢某個表的總欄位數,要用SQL語句,或者在PL/SQL裡面

  1. select count(column_name) from user_tab_columns where table_name='T_B_AUDITOR'  

能夠查出來指定的那張表的欄位數。

下面是通過大致查看:

select   tname,count(*)   from   col   group   by   tname;
  1. 64  T_A_BOOKSTAGEINFO   4  
  2. 65  T_B_AUDITOR 14  
  3. 66  T_B_BOOKMANAGEMENT  13  
  4. 67  T_B_BOOKSTATUSCONFIG    5  
  5. 68  T_B_CODETREEINFO    8  
  6. 69  T_B_FILTERWORD  11  
  7. 70  T_B_ISBNWHITELIST   11  
  8. 71  T_B_MODEL   10  
  9. 72  T_B_NOTICE  15  
  10. 73  T_B_NOTICEACCEPT    11  
  11. 74  T_B_OPERLOG 10  
  12. 75  T_B_ORGANIZATIONINFO    18  
  13. 76  T_B_PREFIXINFO  15  
  14. 77  T_B_PUBLISHINFO 30  
  15. 78  T_B_ROLE    8  
  16. 79  T_B_ROLEMODEL   6  
  17. 80  T_B_SAMPLEBOOKINFO  89  
  18. 81  T_B_USER    26  
  19. 82  T_B_USERANDROLE 6  
  20. 83  T_B_USERLOGIN   8  
  21. 84  T_B_USERMODEL   6  

此時我就聯想到了mysql上面去:

直接利用函數來解決:

  1. mysql> desc test;  
  2. +---------+-------------+------+-----+---------+----------------+  
  3. | Field   | Type        | Null | Key | Default | Extra          |  
  4. +---------+-------------+------+-----+---------+----------------+  
  5. | id      | int(11)     | NO   | PRI | NULL    | auto_increment |  
  6. | name    | varchar(10) | YES  |     | NULL    |                |  
  7. | address | varchar(30) | YES  |     | NULL    |                |  
  8. +---------+-------------+------+-----+---------+----------------+  
  9. 3 rows in set (0.01 sec)  
  10.   
  11. mysql> select found_rows();  
  12. +--------------+  
  13. | found_rows() |  
  14. +--------------+  
  15. |            3 |  
  16. +--------------+  
  17. 1 row in set (0.01 sec)  
還有就是利用系統資料表:
  1. mysql> use information_schema  
  2. Database changed  
  3. mysql> select count(*) from columns where table_name="test";  
  4. +----------+  
  5. | count(*) |  
  6. +----------+  
  7. |        3 |  
  8. +----------+  
  9. 1 row in set (0.00 sec)  
在mysql中想要知道資料庫中有多少個庫:
  1. mysql> select * from schemata;  
  2. +--------------+--------------------+----------------------------+------------------------+----------+  
  3. | CATALOG_NAME | SCHEMA_NAME        | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH |  
  4. +--------------+--------------------+----------------------------+------------------------+----------+  
  5. | NULL         | information_schema | utf8                       | utf8_general_ci        | NULL     |  
  6. | NULL         | mysql              | utf8                       | utf8_general_ci        | NULL     |  
  7. | NULL         | test               | utf8                       | utf8_general_ci        | NULL     |  
  8. +--------------+--------------------+----------------------------+------------------------+----------+  
  9. 3 rows in set (0.00 sec)  
在mysql資料庫中有多少張表:
  1. mysql> select table_schema,count(*) from tables group by table_schema;  
  2. +--------------------+----------+  
  3. | table_schema       | count(*) |  
  4. +--------------------+----------+  
  5. | information_schema |       17 |  
  6. | mysql              |       17 |  
  7. | test               |        6 |  
  8. +--------------------+----------+  
  9. 3 rows in set (0.00 sec)  

其實在系統資料表information_schema中大多的資料庫,表啊都會有記錄的。所以要好好研究下這張表呢。

更多Oracle相關資訊見Oracle 專題頁面 http://www.bkjia.com/topicnews.aspx?tid=12

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.