当前位置: 移动技术网 > IT编程>数据库>Oracle > 解析如何查看Oracle数据库中某张表的字段个数

解析如何查看Oracle数据库中某张表的字段个数

2017年12月12日  | 移动技术网IT编程  | 我要评论
oracle中查询某个表的总字段数,要用sql语句,或者在pl/sql里面
复制代码 代码如下:

select count(column_name) from user_tab_columns where table_name='t_b_auditor'

能够查出来指定的那张表的字段数。
下面是通过大致查看:
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

此时我就联想到了mysql上面去:
直接利用函数来解决:
复制代码 代码如下:

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)

还有就是利用系统表:
复制代码 代码如下:

mysql> use information_schema
database changed
mysql> select count(*) from columns where table_name="test";
+----------+
| count(*) |
+----------+
|        3 |
+----------+
1 row in set (0.00 sec)

在mysql中想要知道数据库中有多少个库:
复制代码 代码如下:

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)

在mysql数据库中有多少张表:
复制代码 代码如下:

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)

其实在系统表information_schema中大多的数据库,表啊都会有记录的。所以要好好研究下这张表呢。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网