0

I am trying to run execute immediate statement to create a table and after that I want to insert data to it but it shows me an error that my table doesn't exist:

DECLARE
    liczba NUMBER :=5;
BEGIN
    IF liczba > 1 THEN
      EXECUTE IMMEDIATE 'CREATE TABLE person (name VARCHAR2(10))';
      INSERT INTO person VALUES ('John');
    END IF;
END;

The error is as follows:

ORA-06550: line 9, column 17: PL/SQL: ORA-00942: table or view does not exist ORA-06550: line 9, column 5: PL/SQL: SQL Statement ignored

Is it possible to insert data without adding next execute immediate statement?
Why doesn't it see the table?

vimuth
  • 5,064
  • 33
  • 79
  • 116
SliceOfPig
  • 123
  • 3
  • 10
  • See [this question](http://stackoverflow.com/q/33628951/266304) too, which has more explanation but is about a GTT so some doesn't directly apply. You still shouldn't generally be creating tables at rumtime though. – Alex Poole Apr 09 '16 at 08:26
  • "Why doesn't it see the table?" Because the table doesn't exist *at compile time*. And if it did exist the EXECUTE IMMEDIATE would fail at run time. Basically your code mixes things we do only once (create a table) with things we do any number of times (insert a record). That's wrong. – APC Apr 10 '16 at 07:29

0 Answers0