我得到這個錯誤在Oracle中:ORA-00933:SQL命令不能正確地結束
ORA-00933: SQL command not properly ended
for
DROP SEQUENCE IF EXISTS ownername.seq_name;
爲什麼會出現這個?
我得到這個錯誤在Oracle中:ORA-00933:SQL命令不能正確地結束
ORA-00933: SQL command not properly ended
for
DROP SEQUENCE IF EXISTS ownername.seq_name;
爲什麼會出現這個?
IF EXISTS
子句在Oracle中的DROP SEQUENCE
命令中不存在。
你可以使用一個PLSQL塊忽略錯誤:
SQL> DECLARE
2 sequence_doesnt_exist EXCEPTION;
3 PRAGMA EXCEPTION_INIT(sequence_doesnt_exist, -2289);
4 BEGIN
5 EXECUTE IMMEDIATE 'DROP SEQUENCE seq_name';
6 EXCEPTION
7 WHEN sequence_doesnt_exist THEN NULL;
8 END;
9/
PL/SQL procedure successfully completed
的問題是「是否存在」不甲骨文工作。使用:
drop sequence ownername.seq_name;
正如其他人提到的那樣,IF EXISTS對DROP SEQUENCE命令不起作用。
要測試序列的存在,你需要檢查相應的視圖:
SELECT *
FROM USER_SEQUENCES
WHERE sequence_name = ?
SELECT *
FROM DBA_SEQUENCES
WHERE sequence_name = ?
SELECT *
FROM ALL_SEQUENCES
WHERE sequence_name = ?
例子:
BEGIN
FOR i IN (SELECT sequence_name
FROM USER_SEQUENCES
WHERE sequence_name = ?)
LOOP
EXECUTE IMMEDIATE ('DROP SEQUENCE '|| i.sequence_name);
END LOOP;
END;
試試這個:
DECLARE
iNum NUMBER DEFAULT 0;
BEGIN
SELECT COUNT(1)
INTO iNum
FROM ALL_SEQUENCES
WHERE SEQUENCE_OWNER='<OWNER_NAME>'
AND SEQUENCE_NAME = '<YOUR_SEQUENCE_NAME>';
IF iNum> 0 THEN
EXECUTE IMMEDIATE 'DROP SEQUENCE <OWNER_NAME>.<YOUR_SEQUENCE_NAME>';
END IF;
END;
喔,好... ...我怎樣才能檢查是否存在的序列或不基於我可以放棄它。 – CodeRocker 2011-01-27 18:19:22
謝謝文森特:) – CodeRocker 2011-01-27 18:29:48