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 -> Re: Best SQL Query

Re: Best SQL Query

From: Michael Ho <hom_at_loyal-holding.com>
Date: Mon, 14 Dec 1998 15:30:13 +0800
Message-ID: <3674BE85.F88C17B5@loyal-holding.com>


All three query is okey, all can use index when p_cust_id is not null, and all full table scan if p_cust_id is null, should be of very similar performance.

But query1, if have null parameter, will need to evaluate nvl(p_cust_id,cust_id) for every row, so should be more CPU intensive.

Personally I prefer Query3, this is more straight forward, so more easily understood and maintained.

Regards,
Michael

techcell_at_my-dejanews.com wrote:

> 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)
>
Received on Mon Dec 14 1998 - 01:30:13 CST

Original text of this message

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