odd90058
odd90058

Reputation: 5

PL/SQL, Execute Immediate troubles

I learning Pl/SQL and have so problem with EXECUTE IMMEDIATE.

I check this:

 CREATE TABLE x(id number(10) );

and this work correctly. Currently i want do it with BEGIN EXECUTE IMMEDIATE;END, try:

BEGIN
 EXECUTE IMMEDIATE 'CREATE TABLE x(id number(10) );' ;
END

And i have error with 2 messages:

  1. About symbol ";" was replaced to "end-of-file" to be continue
  2. That we meet "end-of-file" symbol when it should be "; identity"

How i should correctly do it with BEGIN/EXECUTE IMMEDIATE/END ? Thanks

Upvotes: 0

Views: 104

Answers (1)

Littlefoot
Littlefoot

Reputation: 142705

In dynamic SQL, you don't terminate the statement - remove this semi-colon:

... number(10) );'
                ^
               this

So:

SQL> BEGIN
  2   EXECUTE IMMEDIATE 'CREATE TABLE x(id number(10) )' ;
  3  END;
  4  /

PL/SQL procedure successfully completed.

SQL> desc x
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                                                 NUMBER(10)

SQL>

Upvotes: 2

Related Questions