Home » SQL & PL/SQL » SQL & PL/SQL » Modify query based on variable (9i)
Modify query based on variable [message #284700] Fri, 30 November 2007 11:03 Go to next message
Messages: 11
Registered: November 2007
Location: Oklahoma USA
Junior Member
My Oracle is a little rusty, and I'm not sure this is possible in a query, but I need to run one of two different queries based on a variable value:

declare v_test varchar(8);
v_test := 'A';

if v_test = 'A' then
select * from table1


if v_test = 'B' then
select * from table2

end if;

Ultimately this will be a command object in a Crystal Report, and the variable will be set using a Crystal parameter. First job is to get the query working independently - in this case using a stored procedure isn't an option.

Thanks in advance.
Re: Modify query based on variable [message #284702 is a reply to message #284700] Fri, 30 November 2007 11:10 Go to previous message
Michel Cadot
Messages: 64967
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
something like (but not exactly that depending on columns):
select * from table1 where v_test = 'A'
union all
select * from table2 where v_test = 'B'

Previous Topic: Difficult update from sub query SQL statement
Next Topic: using a VARRAY inside a WHERE clause
Goto Forum:

Current Time: Wed Jun 28 16:07:24 CDT 2017

Total time taken to generate the page: 0.31492 seconds