user595234
user595234

Reputation: 6259

Oracle PL/SQL how to find this syntax error?

In the Oracle PL/SQL , I have this coding, it gives me complier error. I don't know why, looks like I have everything ...

Please help.

Thanks

 ORA-06550: line 6, column 5:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:

   ( begin case declare end 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
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

Code is

begin
  for c in (select id from tmp_A)
  loop
    dbms_output.put_line(c.id);

    create table tmp_c as 
    select B.name from tmp_B B where B.id = c.id;   

    drop table tmp_c;
  end loop;
end;
/

Upvotes: 0

Views: 3547

Answers (1)

jim mcnamara
jim mcnamara

Reputation: 16399

you cannot call ddl statments (CREATE, DROP, ALTER, etc) in PL/SQL directly. You can, however use an execute immediate statement:

begin
  EXECUTE IMMEDIATE 'CREATE TABLE MYTABLE(DT DATE)';
end;

See:

http://www.orafaq.com/wiki/PL/SQL_FAQ#Can_one_call_DDL_statements_from_PL.2FSQL.3F

Upvotes: 3

Related Questions