I would like it if the code below created tables that reflected the amount or rows in table 'NAMES'.
Example: Starting empty after inserting 1 row in to NAMES a table called t1 should be created.
Instead this will create a table named t0 because the procedure runs before that changes to NAMES are committed. How could I get this procedure to run after the rows are committed?
CREATE TABLE NAMES
(
TABLENAMES varchar(1)
);
/
CREATE OR REPLACE PROCEDURE CREATETABLES AS
NAMESROWS NUMBER(3);
BEGIN
SELECT COUNT(*) INTO NAMESROWS FROM NAMES;
EXECUTE IMMEDIATE 'CREATE TABLE t' || NAMESROWS || ' ( bCOL NUMBER(1))';
END CREATETABLES;
/
CREATE OR REPLACE TRIGGER CREATETABLETRIGGER
AFTER INSERT OR UPDATE OR DELETE ON NAMES
DECLARE PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
CREATETABLES;
END;
/
INSERT INTO NAMES VALUES (2);