Im using the Grails database migration plugin by liquibase. Im trying to use aPLSQL statement in the migration to find and remove a constraint on a table, im using this approach as i dont know the name of the constraint and it will vary on different systems i use.
Some notes:
- Grail 1.3.7
- Database-migration 1.0
This is the code from the migration
sql("declare\n" +
"vOldName all_constraints.constraint_name%TYPE\n" +
"begin\n" +
"select CONSTRAINT_NAME\n" +
"into vOldName\n" +
"from all_constraints\n" +
"where TABLE_NAME='TABLENAME' and CONSTRAINT_TYPE='U' and OWNER='USERNAME'\n" +
"execute immediate 'alter table USERNAME.TABLENAMEdrop constraint '\n" +
"|| vOldName\n" +
"end")
When i run this i get the following error:
java.sql.SQLException: ORA-06550: line 3, column 1:
PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following:
:= ( ; not null range default character
The symbol ";" was substituted for "BEGIN" to continue.
I have tried to add ; to the end of each statement but it them complains about seeing end-of-file in the code.
Any help please ?
I think this will fix it. A PL/SQL block needs a semicolon after each statement. The only thing that doesn’t need a semicolon is dynamic SQL. Also, there was a missing space between
TABLENAMEanddrop.It might help to first make sure the code works in SQL*Plus, or some other database tool. And then paste it into a multi-line string.
Let me know if it doesn’t work.