我使用以下SQL来获取表的索引列:
SELECT DISTINCT COLUMN_NAME
FROM DBA_IND_COLUMNS
WHERE TABLE_NAME = 'MY_TABLE' AND TABLE_OWNER = 'SCHEMA'";
我想调整这个SQL,以便我获取索引列及其数据类型:
SELECT DISTINCT COLUMN_NAME, DATA_TYPE
FROM DBA_IND_COLUMNS
WHERE TABLE_NAME = 'MY_TABLE' AND TABLE_OWNER = 'SCHEMA'";
但是这为“DATA_TYPE”提供了无效的标识符错误。有没有办法在不创建其他查询的情况下执行此操作?
答案 0 :(得分:3)
您需要在查询中添加DBA_TAB_COLUMNS
:
SELECT DISTINCT COL.COLUMN_NAME, COL.DATA_TYPE
FROM DBA_IND_COLUMNS IND
INNER JOIN DBA_TAB_COLUMNS COL
ON ( IND.TABLE_OWNER = COL.OWNER AND IND.TABLE_NAME = COL.TABLE_NAME AND IND.COLUMN_NAME = COL.COLUMN_NAME)
WHERE IND.TABLE_NAME = 'MY_TABLE' AND TABLE_OWNER = 'SCHEMA'