Why can't I write DDL directly after a PLSQL a

2019-03-03 22:34发布

问题:

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?

回答1:

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.