Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dynamically Select Tables in a View

979133Dec 10 2012 — edited Dec 10 2012
Can 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 7 2013
Added on Dec 10 2012
2 comments
406 views