Friday, June 8, 2012

Order of parameters matters in oracle query

Faced lots of time to figure out why my oracle query was erroring out. It was the order of the dynamic parameters in the query should match the order we pass the parameter with 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;

Here you can see three parameters :fromDate, :toDate & :uname. These parameters needs to be passed from C# using command object in the following order in which it is used in the query, which is as below:
1. :fromDate
2. :toDate
3. :uname

I was passing the parameters in the following order:


1. :uname
2. :fromDate
3. :toDate


Took me a while to figure out. These are some tips which can be used if you stumble across such error again, you need not waste much time to figure out.

Hope this helps others.

No comments:

Post a Comment