Search code examples
oracle-databaseplsqlddlsql-scripts

Why can't I write DDL directly after a PLSQL anonymous block?


I have the following simple script.

declare
begin
  null;
end;

create table &&DB_SCHEMA..test_table (
   test_column varchar(20)
);

Executing it ends with the following error

ORA-06550: line 6, column 1:

PLS-00103: Encountered the symbol "CREATE"

  1. 00000 - "line %s, column %s:\n%s"

*Cause: Usually a PL/SQL compilation error.

*Action:

Can't I use the DDL directly after an anonymous block? Am I forced to do it with EXECUTE IMMEDIATE inside the anonymous block?


Solution

  • You are simply missing a '/':

    SQL> declare
      2  begin
      3    null;
      4  end;
      5  /
    
    PL/SQL procedure successfully completed.
    
    SQL> create table create_test_table (
      2     test_column varchar(20)
      3  );
    
    Table created.
    

    Here you find something more.