Home >Database >Mysql Tutorial >oracle 查询表名以及表的列名

oracle 查询表名以及表的列名

WBOY
WBOYOriginal
2016-06-07 18:06:451556browse

oracle 查询表名以及表的列名的代码。

1.查询表名:
代码如下:
select table_name,tablespace_name,temporary from user_tables [where table_name=表名]

其中:table_name:表名(varchar2(30));
tablespace_name:存储表名的表空间(varchar2(30));
temporary:是否为临时表(varchar2(1))。
eg: select table_name,tablespace_name,temporary from user_tables where table_name='TEST_TEMP';
结果:

--------------------------------------------------------------------------------
table_name tablespace_name temporary
TEST_TEMP SDMP N

--------------------------------------------------------------------------------
注:表名变量值必须大写。
2.查询表列名:
代码如下:
select column_name,data_type ,data_length,data_precision,data_scale from user_tab_columns [where table_name=表名];

其中:column_name:列名(varchar2(30));
data_type:列的数据类型(varchar2(106));
data_length:列的长度(number);
eg:select column_name,data_type ,data_length,data_precision,data_scale from user_tab_columns where table_name='TEST_TEMP';
结果:

--------------------------------------------------------------------------------
column_name data_type data_length data_precision data_scale
ID NUMBER 22 0
NAME NVARCHAR2 20
SEX CHAR 1
GRADE NVARCHAR2 10

--------------------------------------------------------------------------------

注:表名变量值必须大写。
另外,也可以通过 all_tab_columns来获取相关表的数据。
eg:select * from all_tab_columns where table_name='TEST_TEMP';
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn