Conditional SELECT [message #410790] |
Tue, 30 June 2009 05:12 |
|
delna.sexy
Messages: 941 Registered: December 2008 Location: Surat, The Diamond City
|
Senior Member |
|
|
Hello Gurus,
I have two tables, imp_t1 and imp_t2, with different table structures. And I want to fire SELECT statement on these tables based on some condition.
Let's say FLAG.
If FLAG=1 then SELECT * from IMP_T1 should be fired
and SELECT * FROM IMP_T2 otherwise.
Don't know how to do this? Please help.
Following is the demo test case
create table imp_t1
(col1 integer,
col2 varchar2(10),
col3 date default sysdate);
create table imp_t2
col4 integer,
col5 varchar2(10));
insert into imp_t1 values(1,'Naresh',null);
insert into imp_t1 values(2,'Naresh',null);
insert into imp_t1 values(3,'Naresh',null);
insert into imp_t2 values(1,'Raja');
insert into imp_t2 values(2,'Raja');
insert into imp_t2 values(3,'Raja');
regards,
Delna
|
|
|
Re: Conditional SELECT [message #410793 is a reply to message #410790] |
Tue, 30 June 2009 05:23 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
DECLARE
v_flag number := :b1;
v_count number;
BEGIN
IF v_flag = 1 then
SELECT count(*) into v_count from table_1;
ELSE
SELECT count(*) into v_count from table_2;
END IF;
END;
/
|
|
|
|
|
|
|
|
|
|
Re: Conditional SELECT [message #410820 is a reply to message #410790] |
Tue, 30 June 2009 07:42 |
cookiemonster
Messages: 13960 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
If the tables involved have significantly different structures such that you can't use the union trick then the only sensible thing to do is have two different reports and decide which is run based on the parameters.
|
|
|
Re: Conditional SELECT [message #410822 is a reply to message #410805] |
Tue, 30 June 2009 07:54 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
delna.sexy wrote on Tue, 30 June 2009 07:12 | Right cookiemonster sir,
|
Sorry, I really do not have anything relevant to ad here. it's just when I saw that line, it really cracked me up. It's probably just me...I'm sorry.
|
|
|
|
|
Re: Conditional SELECT [message #410915 is a reply to message #410790] |
Wed, 01 July 2009 01:06 |
|
delna.sexy
Messages: 941 Registered: December 2008 Location: Surat, The Diamond City
|
Senior Member |
|
|
Thank you all.
Actually I am using Oracle ApEx and in which There is only one interactive report is allowed on one page.
I was also thinking to use two different pages with different report, having different queries as data source.
But wanted to just know, if this is possible with single report.
Thanks again.
regards,
Delna
|
|
|