I am working on a legacy application using an Oracle 11g database and have come across an issue where I have 5 tables all in different schemas with the same data structure. I need to be able to insert data into these tables and I'm trying to avoid duplicate code.
I know do something like the following
IF p_schema = SCHEMA1 THEN
INSERT INTO SCHEMA1.TABLE_NAME_SCHEMA1 (...) VALUES (...)
ELSIF p_schema = SCHEMA2 THEN
INSERT INTO SCHEMA2.TABLE_NAME_SCHEMA2 (...) VALUES (...)
ELSIF p_schema = SCHEMA3 THEN
INSERT INTO SCHEMA3.TABLE_NAME_SCHEMA3 (...) VALUES (...)
ELSIF p_schema = SCHEMA4 THEN
INSERT INTO SCHEMA4.TABLE_NAME_SCHEMA4 (...) VALUES (...)
ELSIF p_schema = SCHEMA5 THEN
INSERT INTO SCHEMA5.TABLE_NAME_SCHEMA5 (...) VALUES (...)
END IF;
Is there any way to make the table name a variable inside the SQL so that I can just make one insert statement, but insert into the table I want?