Friday, June 8, 2012

Same parameters used multiples times in Oracle Query

If we use same parameters multiple times in a query in oracle as shown in example, it errors out. We need to create another set of variables with same values.


Check the usage of parameters in the below example:
:fromDate
:toDate
:uname


:fromDate1
:toDate1
:uname1



:fromDate2
:toDate2
:uname2


All the above paramaters are having the same values.


For example:-
select user_name,call_reason from call_tbl, users_tbl where call_placed_dt between :fromdate and :toDate
and user_name = :uname order by user_description
FULL JOIN

select user_name,call_reason from call_mrs_tbl, users_tbl where call_placed_dt between :fromdate1 and :toDate1
and user_name = :uname1 order by user_description
FULL JOIN

select user_name,call_reason from call_tbl, users_tbl where call_placed_dt between :fromdate2 and :toDate2
and user_name = :uname2 order by user_description;

We cannot use the above query as below. It errors out saying invalid datatype.


select user_name,call_reason from call_tbl, users_tbl where call_placed_dt between :fromdate and :toDate
and user_name = :uname order by user_description
FULL JOIN
select user_name,call_reason from call_mrs_tbl, users_tbl where call_placed_dt between :fromdate and :toDate
and user_name = :uname order by user_description
FULL JOIN
select user_name,call_reason from call_tbl, users_tbl where call_placed_dt between :fromdate and :toDate
and user_name = :uname order by user_description;











No comments:

Post a Comment