Dynamically Select Tables in a View
979133Dec 10 2012 — edited Dec 10 2012Can anyone advice me on how to create a view that would dynamically select from either one of two tables (T1 or T2).
create table T1 (id integer);
insert into T1 values (1);
insert into T1 values (2);
commit;
create table T2 (id integer);
insert into T2 values (10);
insert into T2 values (20);
commit;
create table control ( active varchar2(1), table_name varchar2(10));
insert into control values ('Y', 'T1');
insert into control values ('N', 'T2');
commit;
I would like a view to be created that will read the control table to check for Active = 'Y' and then return the data from the corresponding table. Ex: Select ID from T1;
This way the users can keep using the view and I can change the underneath data by simply updating the control table.
Greatly appreciate your response.
Thanks,
Praveen