Tuesday, March 18, 2014

Anonymous Blocks in PL\SQL

Even Anonymous blocks in PL\SQL are compiled first and then executed. This is something new that I learned today.  The below code from yesterday's PL\SQL challenge made me realize this.

BEGIN
   EXECUTE IMMEDIATE
      'CREATE TABLE plch_stuff (stuff_id INTEGER)';

   INSERT INTO plch_stuff
        VALUES (1234);

   DBMS_OUTPUT.put_line (SQL%ROWCOUNT);
END;
/


The above code would fail not at run time but during compile time. All this while I was assuming that anonymous blocks run without being compilation.