How to check if a constraint existed in the table and drop it?
793476Aug 24 2010 — edited Aug 24 2010Hi all,
I want to drop a constraint from a table. I do not know if this constraint already existed in the table. So I want to check if this exists first.
Below is my query:
DECLARE
itemExists NUMBER;
BEGIN
itemExists := 0;
SELECT COUNT(CONSTRAINT_NAME) INTO itemExists
FROM ALL_CONSTRAINTS
WHERE UPPER(CONSTRAINT_NAME) = UPPER('my_constraint');
IF itemExists > 0 THEN
ALTER TABLE my_table DROP CONSTRAINT my_constraint;
END IF;
END;
Here is the error I got when I executed the above query:
ORA-06550: line 11, column 5: PLS-00103: Encountered the symbol "ALTER" when expecting one of the following: ( begin case declare exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge
Please help me with this!
Greatly appreciate!
Khoi Le