I am trying to rewrite the following code, in order to avoid ORA-00942 error (table or view does not exist). It is because during the compilation of my code, the table(MY_TABLE_NAME) still does not exist, therefore I need to make it dynamic.
Here is the code (used generic names)
DECLARE
C INTEGER := 0;
BEGIN
SELECT COUNT(1) INTO C FROM USER_TABLES WHERE TABLE_NAME = 'MY_TABLE_NAME';
IF C > 0 THEN
DECLARE
CURSOR c_var IS SELECT COLUMN_1, COLUMN_2 FROM MY_TABLE_NAME WHERE ACTIVE = 1;
v_id NUMBER(15);
BEGIN
FOR prec IN c_var LOOP
......testcode
END LOOP;
EXECUTE IMMEDIATE 'testcode';
END;
END IF;
END;
/
It is not necessary to use a cursor..so i tried to rewrite it and using a normal for loop because I think it is easier to make the code more dynamic, however I am still struggling