| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Best SQL Query
Hi Everybody,
I have a procedure sp1 which receives a parameter p_cust_id.
If the parameter p_cust_id is null then My query has to fetch all the customers.
If param p_cust_id is not null then
My query has to fetch only the specified customer record.
I have 3 queries which can do the same but I am foxed regarding the fact which
the best one.
Note: p_cust_id is defined as number(4)
They are
Query 1
SELECT cust_name
FROM customer
WHERE cust_id = Nvl(p_cust_id,cust_id)
Query 2
SELECT cust_name
FROM customer
WHERE cust_id LIKE Nvl(p_cust_id,'%')
Query 3
SELECT cust_name
FROM customer
WHERE (cust_id = p_cust_id
OR p_cust_id IS NULL)
All the three use the index but which is the best?
Regards
Rajs(TechCell)
-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own Received on Sat Dec 12 1998 - 00:14:08 CST
![]() |
![]() |