如何修复 "ORA-00950: invalid DROP option"?
How to fix "ORA-00950: invalid DROP option"?
ORA-00950: invalid DROP option
以上是我遇到的错误。我编写了这个程序来删除 emp_1 table 中的所有索引。那么谁能帮我找出错误并解决这个错误?
CREATE OR REPLACE NONEDITIONABLE PROCEDURE sp_drop_indexes (
p_table_name IN VARCHAR2,
p_errormsg OUT VARCHAR2 )
IS
v_sql VARCHAR2(1000);
CURSOR get_indexes IS
SELECT index_name
FROM user_indexes
WHERE table_name = 'EMP_1';
BEGIN
FOR rec IN get_indexes LOOP
v_sql := 'DROP INDEX' || rec.index_name;
EXECUTE IMMEDIATE v_sql;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
p_errormsg := sqlerrm;
END sp_drop_indexes;
您的代码中 DROP INDEX
之后(但仍在引号内)缺少 space:
v_sql := 'DROP INDEX ' || rec.index_name;
确保在 DROP INDEX
关键字后包含 space:
v_sql := 'DROP INDEX ' || rec.index_name;
你需要一个 space after drop 索引,如果你可以有 case-sensitive 个索引名称,你需要双引号:
CREATE OR REPLACE NONEDITIONABLE PROCEDURE sp_drop_indexes (
p_table_name IN VARCHAR2,
p_errormsg OUT VARCHAR2 )
IS
v_sql VARCHAR2(1000);
CURSOR get_indexes IS
SELECT index_name
FROM user_indexes
WHERE table_name = 'EMP_1';
BEGIN
FOR rec IN get_indexes LOOP
v_sql := 'DROP INDEX "' || rec.index_name || '"';
EXECUTE IMMEDIATE v_sql;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
p_errormsg := sqlerrm;
END sp_drop_indexes;
/
ORA-00950: invalid DROP option
以上是我遇到的错误。我编写了这个程序来删除 emp_1 table 中的所有索引。那么谁能帮我找出错误并解决这个错误?
CREATE OR REPLACE NONEDITIONABLE PROCEDURE sp_drop_indexes (
p_table_name IN VARCHAR2,
p_errormsg OUT VARCHAR2 )
IS
v_sql VARCHAR2(1000);
CURSOR get_indexes IS
SELECT index_name
FROM user_indexes
WHERE table_name = 'EMP_1';
BEGIN
FOR rec IN get_indexes LOOP
v_sql := 'DROP INDEX' || rec.index_name;
EXECUTE IMMEDIATE v_sql;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
p_errormsg := sqlerrm;
END sp_drop_indexes;
您的代码中 DROP INDEX
之后(但仍在引号内)缺少 space:
v_sql := 'DROP INDEX ' || rec.index_name;
确保在 DROP INDEX
关键字后包含 space:
v_sql := 'DROP INDEX ' || rec.index_name;
你需要一个 space after drop 索引,如果你可以有 case-sensitive 个索引名称,你需要双引号:
CREATE OR REPLACE NONEDITIONABLE PROCEDURE sp_drop_indexes (
p_table_name IN VARCHAR2,
p_errormsg OUT VARCHAR2 )
IS
v_sql VARCHAR2(1000);
CURSOR get_indexes IS
SELECT index_name
FROM user_indexes
WHERE table_name = 'EMP_1';
BEGIN
FOR rec IN get_indexes LOOP
v_sql := 'DROP INDEX "' || rec.index_name || '"';
EXECUTE IMMEDIATE v_sql;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
p_errormsg := sqlerrm;
END sp_drop_indexes;
/