正如标题所示,我很好奇是否有人知道如何查询表的主键,其数据类型和主键列的名称。今天早些时候,我单独询问了主键列并且效果很好。但是,我不知道如何提取其数据类型和列名。任何帮助将不胜感激。
谢谢!
答案 0 :(得分:3)
这应该这样做:
SELECT ac.constraint_name, acc.column_name, acc.position
, atc.data_type, atc.data_length
FROM all_constraints ac JOIN all_cons_columns acc
ON (ac.CONSTRAINT_NAME = acc.CONSTRAINT_NAME)
JOIN all_tab_cols atc ON (ac.owner = atc.owner AND
ac.table_name = atc.TABLE_NAME AND
acc.COLUMN_NAME = atc.COLUMN_NAME)
WHERE ac.owner = 'table_owner'
AND ac.table_name = 'your_table'
AND ac.constraint_type = 'P'
ORDER BY acc.position;
答案 1 :(得分:0)
使用查询表user_tab_columns
或all_tab_columns
:
select column_name, data_type, data_length from user_tab_columns
where table_name = 'MY_TABLE';
select * from all_tab_columns
where owner = 'THE_SCHEMA_OWNER';