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

Home -> Community -> Usenet -> c.d.o.misc -> Re: [Q] Conditions in the column expression?

Re: [Q] Conditions in the column expression?

From: Daniel Morgan <damorgan_at_x.washington.edu>
Date: Wed, 26 Nov 2003 08:48:07 -0800
Message-ID: <1069865319.230138@yasure>


Ano Nymus wrote:

> I have a table t with columns n and m of type VARCHAR. I
> want to retrieve the entire n column, but I want the entries
> to be ordered such that those entries where m is null come
> first. As pseudo-code:
>
> SELECT n, (IF m IS NULL THEN 0 ELSE 1) AS c
> FROM t
> ORDER BY c, n;
>
> Moreover, I want to retrieve all those entries of n whose
> length is greater than 5, but I want NULL values for all
> those entries whose length is less or equal than 5. In
> pseudo-code:
>
> SELECT (IF LENGTH(m) <= 5 THEN NULL ELSE m)
> FROM t;
>
> How do I do this in Oracle?

SELECT n
FROM t
ORDER BY m NULLS FIRST;

-- 
Daniel Morgan
http://www.outreach.washington.edu/ext/certificates/oad/oad_crs.asp
http://www.outreach.washington.edu/ext/certificates/aoa/aoa_crs.asp
damorgan_at_x.washington.edu
(replace 'x' with a 'u' to reply)
Received on Wed Nov 26 2003 - 10:48:07 CST

Original text of this message

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