I have the below 2 queries:
SELECT * from mytable; SELECT * from mytable where rownum < 100;
I would like to execute the first one whenever my schema equals 'SCHEMA1' and the second one otherwise. Is there a way to do this without having to rewrite both queries like this:
DECLARE
myschema VARCHAR2(50);
BEGIN
SELECT
sys_context('userenv', 'current_schema')
|| 's'
INTO myschema
FROM
dual;
IF myschema = 'SCHEMA1' THEN
INSERT INTO myothertable
SELECT
*
FROM
mytable;
ELSE
INSERT INTO myothertable
SELECT
*
FROM
mytable
WHERE
ROWNUM < 100;
END IF;
END;
I would also like to avoid dynamic PLSQL.