通過oracle中的user_tab_cols, user_col_comments, user_constraints, user_cons_columns表聯合查詢。
user_tab_cols用來獲取對應使用者表的列資訊;
user_col_comments用來獲取對應使用者表列的注釋資訊;
user_constraints用來獲取使用者表的約束條件;
user_cons_columns約束中使用者可訪問列。
select a.column_id as 列號, a.column_name as 列名, a.data_type as 型別,
decode(a.data_type,'number',a.data_precision,a.data_length) as 長度, a.data_scale as 小數字,
decode(e.uniqueness,'unique','y','n') as 是否是唯一的, decode(e.key,'y','y','n') 是否是主鍵,
f.comments as 注釋, a.nullable as 是否允許空, a.data_default as 預設值
from user_tab_columns a, user_col_comments f,
(select b.table_name, b.index_name,b.uniqueness, c.column_name,
decode(d.constraint_name,null,'n','y') key
from user_indexes b, user_ind_columns c,
( select constraint_name from user_constraints where constraint_type='p' ) d
where b.index_name=c.index_name and b.index_name=d.constraint_name(+) ) e
where a.table_name='temptable' and a.table_name=e.table_name(+) and a.column_name=e.column_name(+)
and a.table_name=f.table_name and a.column_name=f.column_name
order by a.column_id
select tc.table_name , tc.column_name ,tc.data_type,tc.data_length,tc.data_precision,tc.nullable,
tc.char_col_decl_length,
decode(c.constraint_type,'p','pk','u','unique','r','fk','c','check',c.constraint_type)
from user_tab_columns tc,user_cons_columns cc ,user_constraints c
where tc.table_name = 'emp'
and tc.table_name = cc.table_name(+)
and tc.column_name = cc.column_name (+)
and cc.constraint_name = c.constraint_name(+)
select a.column_name 欄位名,a.data_type 資料型別,a.data_length 長度,a.data_precision
整數字, a.data_scale 小數字,a.nullable 允許空值,a.data_default 預設值,b.comments
備註 from user_tab_columns a,user_col_comments b where a.column_name=b.column_name and a.table_name = b.table_name and a.table_name='test'
獲取表:
select table_name from user_tables; //當前使用者的表
select table_name from all_tables; //所有使用者的表
select table_name from dba_tables; //包括系統表
select table_name from dba_tables where owner='使用者名稱'
user_tables:
table_name,tablespace_name,last_analyzed等
dba_tables:
ower,table_name,tablespace_name,last_analyzed等
all_tables:
ower,table_name,tablespace_name,last_analyzed等
all_objects:
ower,object_name,subobject_name,object_id,created,last_ddl_time,timestamp,status等
獲取表字段:
select * from user_tab_columns where table_name='使用者表';
select * from all_tab_columns where table_name='使用者表';
select * from dba_tab_columns where table_name='使用者表';
user_tab_columns:
table_name,column_name,data_type,data_length,data_precision,data_scale,nullable,column_id等
all_tab_columns :
ower,table_name,column_name,data_type,data_length,data_precision,data_scale,nullable,column_id等
dba_tab_columns:
ower,table_name,column_name,data_type,data_length,data_precision,data_scale,nullable,column_id等
獲取表注釋:
select * from user_tab_comments
user_tab_comments:table_name,table_type,comments
--相應的還有dba_tab_comments,all_tab_comments,這兩個比user_tab_comments多了ower列。
獲取字段注釋:
select * from user_col_comments
user_col_comments:table_name,column_name,comments
獲取oracle表結構的字段資訊
select a.column id as 列號,a.column name as 列名,a.data type as 型別,decode a.data type,number a.data precision,a.data length as 長度,a.data scale as 小數字,deco...
SQL 獲取表結構資訊
select 表名 d.name,表說明 isnull f.value,字段序號 a.colorder,欄位名 a.name,標識 case when columnproperty a.id,a.name,isidentity 1 then else end,主鍵 case when exists ...
Oracle 使用者表 結構資訊
oracle資料庫 查詢資料結構 我們在做專案中某些模組的資料結構設計沒有嚴格按照某規範設計,所以只能從資料庫中查詢資料結構,需要查詢的資訊如下 欄位名稱 資料型別 是否為空 預設值 主鍵 外來鍵等。總結如下 1,查詢表基本資訊 select utc.column name,utc.data typ...