Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem when altering tables in PL/SQL

Status
Not open for further replies.

KrisSimonis

Programmer
Jun 28, 2002
37
0
0
NL
I've got the following PL/SQL code:

DECLARE
counter NUMBER(4);
BEGIN
SELECT count(*) INTO counter from all_constraints where constraint_name = 'FK_persoon_afdelingid';
IF counter > 0 THEN
ALTER TABLE PERSOON
DROP CONSTRAINT FK_persoon_afdelingid;
END IF;
END;

Basicly, seek and destroy a foreign key in a table.
( the whole thing is dynamicly created inside my application and then submitted to the Database )
However, when I try to run it, it gives the following
error in the worksheet( in my application I just get ORA-6550 exception ):
-------------------------------------
ALTER TABLE PERSOON
*
ERROR in line 6:
.ORA-06550: Line 6, Column 2:
PLS-00103: Symbol "ALTER" found while expecting:
( bunch of other command words )

Can anyone give me a hand on how to solve this problem?

Kris Simonis
OGD Software.


 
Since you are trying to perform DDL statements, I think you need to use the EXECUTE IMMEDIATE function.

...
IF counter > 0 THEN
EXECUTE IMMEDIATE 'ALTER TABLE PERSOON '
|| ' DROP CONSTRAINT FK_persoon_afdelingid';
END IF;
...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top