Need to insert data into a table from a table present in different environments. The env list is obtained from my_env table. For my case the number of envs can vary so the env name would be dynamic hence i wrote as under:
DECLARE
WRK_STS VARCHAR2(2) := 'PP';
MY_ENV VARCHAR2(50) := '';
WRK_ENV NUMBER(6) := 0;
BEGIN
FOR t in (SELECT DISTINCT(envid) FROM MY_ENV ORDER BY ENVID ASC)
LOOP
WRK_ENV := WRK_ENV+1;
MY_ENV := 'ENV_' || t.envid || '.table002';
INSERT INTO MYTAB101(DATE,STS, MYENV, nAME, DESCR, MYTYPE)
SELECT null, ' || WRK_STS|| ',' || WRK_ENV || ',NAME, DESCR,MYTYPE from ' || MY_ENV;
END LOOP;
EXCEPTION
/*Handle exception*/
END;
/
COMMIT;
But i am getting error :
ORA-06550: line 15, column 61: PL/SQL: ORA-00942: table or view does not exist ORA-06550: line 12, column 3: PL/SQL: SQL Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action: committed.
If i directly type the env name it works like 'from ENV368.table002'
can someone suggest what is wrong here?
Thanks!!!