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: if then else statement on 2 columns in SQL query?

Re: if then else statement on 2 columns in SQL query?

From: Jeremy Russell <jeremyr_at_no-spam-today-thanks.dircon.co.uk>
Date: Mon, 19 Oct 1998 05:29:22 GMT
Message-ID: <362acd8d.1245833@news.dircon.co.uk>


Depending on the complexity and type of the test, you might be able to use a DECODE function anyways. For example, if the test is on the sign of an amount, then

SELECT decode(sign(balance), -1, 'Negative', 'Zero or more'), ...

would work and return either of the two text strings as appropriate.

If the test is more complex, write it as a 'stored function', with arguments - give EXECUTE privilege to the relevant accounts/roles and call it like this:

SELECT myfunc(value1, value2) ...

Hope that helps
JR

joeyd2335_at_my-dejanews.com wrote

>Hi, I need to do a very simple if then statement on 2 columns and I was
>wondering if it could be done in an SQL query without PL/SQL. ie some
>variation of decode?
>
>say I have 2 columns X and Y I want to do something like
>if X.column ='Apples' then
>decode(Y.column,'oranges','apples',Y.column)
>
>if not then can I embed a PL/SQL function straight into the query? how would
>the syntax work( with the declares and semi-colons )? Or do I have to create a
>function first and then call this function in the SQL query?
>
>Thanks in advance
>
>Joe Grgas
>joeyd_at_hunterlink.net.au
>
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
Received on Mon Oct 19 1998 - 00:29:22 CDT

Original text of this message

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