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

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Always return at least one value

RE: Always return at least one value

From: Bobak, Mark <Mark.Bobak_at_il.proquest.com>
Date: Fri, 19 Mar 2004 11:34:46 -0500
Message-ID: <4C9B6FDA0B06FE4DAF5918BBF0AD82CF03B45388@bosmail00.bos.il.pqe>


How about this:
select field from table where field='LITERAL' union all
select '-' from dual
where not exists(select field from table where field='LITERAL');

I think that ought to do it....

-Mark

-----Original Message-----

From: Stephen.Lee_at_DTAG.Com [mailto:Stephen.Lee_at_DTAG.Com] Sent: Friday, March 19, 2004 11:27 AM
To: oracle-l_at_freelists.org
Subject: Always return at least one value

Is there is short and sweet way to do:

	Select field from table where field = 'LITERAL'.
	If no rows then return a '-'.
	If there are matches then return all the matches.

I trying to avoid multiple select statements, loops, conditional statements, etc. because it is expected that this could possibly run a couple thousand times per minute.

Something like:

select nvl(field,'-') from (select field from TABLE where character = 'VALUE') A, sys.dual B where A.field(+) = B.dummy;

will work if there is no match in the table. But if there are multiple matches, it will only return one of them because there is only one row in DUAL. Is there something in version 9 that can do this in a single slick and cool query?



Please see the official ORACLE-L FAQ: http://www.orafaq.com

To unsubscribe send email to: oracle-l-request_at_freelists.org put 'unsubscribe' in the subject line.
--

Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html

-----------------------------------------------------------------
----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to: oracle-l-request_at_freelists.org
put 'unsubscribe' in the subject line.
--

Archives are at http://www.freelists.org/archives/oracle-l/ FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
Received on Fri Mar 19 2004 - 10:31:12 CST

Original text of this message

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