Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Best SQL Query

Best SQL Query

From: <techcell_at_my-dejanews.com>
Date: Sat, 12 Dec 1998 06:14:08 GMT
Message-ID: <74t1jg$47r$1@nnrp1.dejanews.com>


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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US