Unable to create table using pl/sql Unable to create table using pl/sql oracle oracle

Unable to create table using pl/sql


change it so that it is executed in 2 successive steps (NOT in one PL/SQL anonymous block like it is now):

First this

beginexecute immediate 'create table rat1 ( name varchar2(10) )';commit;end;

THEN as a SECOND block this

declaretype yy is table of t12.name%type index by binary_integer;y yy;n number:=1;beginselect name bulk collect into y from t12;for i in (select id,name from t12)loopdbms_output.put_line(y(n));n:=n+1;end loop;forall i in y.first..y.lastinsert into rat1 values(y(i));end;

EDIT - as per comment:

Before execution the WHOLE PL/SQL block is parsed - all objects used in an PL/SQL block must exist BEFORE the PL/SQL block is executed...


You should do it in two separate blocks.

First block:

begin...end;/

The slash indicates that your buffer should be sent to the DBMS and evaluated. It indicates where your PL/SQL code ends and evaluation can begin.

Then the next:

declare...begin...end;/

Thus, you have:

begin...end;/declare...begin...end;/

It works under SQL*Plus and SQLDeveloper.


If working withing within SQLPlus block, all DDL changes mus be performed with execute immediate. Unfortunately, those changes are invisible until block finishes execution.

To work around this problem, please use consequently execute immediate for all following statements that depends on former "hidden" changes. That applies also for DML statements. In your case:

...execute immediate 'insert into rat1 values('||y(i)||')';...