我创建了一个包含多个约束的表(主键,外键等)。 Oracle使用代码名称自动生成索引(例如SYS_CO12345)。我想用正确的名称重命名索引。
我知道如何使用诸如
之类的请求来识别索引名称SELECT INDEX_OWNER || '.' || INDEX_NAME
FROM DBA_IND_COLUMNS
WHERE INDEX_OWNER = <my owner>
AND TABLE_OWNER = <my table>
AND TABLE_NAME = <my table>
AND COLUMN_NAME = <my column>;
我也知道如何使用
等请求重命名索引ALTER INDEX <index owner>.<index name>
RENAME TO <index owner>.<index new name>;
现在,我想将这两个请求合并为:
ALTER INDEX
(
SELECT INDEX_OWNER || '.' || INDEX_NAME
FROM DBA_IND_COLUMNS
WHERE INDEX_OWNER = <my owner>
AND TABLE_OWNER = <my owner>
AND TABLE_NAME = <my table>
AND COLUMN_NAME = <my column>
)
RENAME TO <index owner>.<index new name>;
但是我面临以下错误消息:
00953. 00000 - "missing or invalid index name"
*Cause: An index name of the form [ <identifier> . ] <identifier> is
expected but not present. If OIDINDEX clause, index name must be
<identifier>
*Action: Enter an appropriate index name.
关于如何编写正确的组合请求的任何想法?
非常感谢你的帮助!
编辑,在Multisync的建议之后: 我写了以下程序,这是有效的。我不确定它是最优的,但它完成了工作......
DECLARE
index_owner_and_name VARCHAR2(30);
query2execute VARCHAR2(200);
CURSOR myCursor IS SELECT INDEX_OWNER || '.' || INDEX_NAME
FROM DBA_IND_COLUMNS
WHERE INDEX_OWNER = <my owner>
AND TABLE_OWNER = <my owner>
AND TABLE_NAME = <my table>
AND COLUMN_NAME = <my column>;
BEGIN
OPEN myCursor ;
FETCH myCursor INTO index_owner_and_name;
CLOSE myCursor ;
query2execute := 'ALTER INDEX ' || index_owner_and_name || ' RENAME TO <new index name>';
EXECUTE IMMEDIATE query2execute ;
END;
答案 0 :(得分:0)
ALTER INDEX语法不允许像INSERT-SELECT那样从SELECT输入其输入。 ALTER INDEX中不能有子查询。您必须单独准备每个语句并通过动态DDL运行它(因为Multisync已经回答)。这是唯一的方法。