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: Decode equivalent within pl/sql?

Re: Decode equivalent within pl/sql?

From: Brian Peasland <dba_at_nospam.peasland.net>
Date: Mon, 13 Nov 2006 14:33:38 GMT
Message-ID: <J8oB4E.1xp@igsrsparc2.er.usgs.gov>


Jeremy wrote:
> 9iR2
>
> As I understand it you can only use DECODE as part of a SQL statement
>
> e.g. select decode(var,
> 'A','LetterA',
> 'B','LetterB',
> 'Lettersomethingelse')
> from dual;
>
> In a pl/sql statement, you cannot code e.g.
>
> l_string := decode(.....
>
> What do you use to achieve a similar result - or do you set the value
> into a variable beforehand with an
> if
> elsif
> end if
>
> structure?
>
> Thanks
>

You can use DECODE in PL/SQL...but put it into a SQL statement. For example, to do the assignment in your example:

SELECT DECODE(...) INTO l_string FROM ....;

You can use the DUAL table if needed in the above.

Otherwise, you might want to look at the CASE statement, depending on your Oracle version. If all else fails, IF_THEN_ELSE constructs will do the trick.

HTH,
Brian

-- 
===================================================================

Brian Peasland
dba_at_nospam.peasland.net
http://www.peasland.net

Remove the "nospam." from the email address to email me.


"I can give it to you cheap, quick, and good.
Now pick two out of the three" - Unknown
Received on Mon Nov 13 2006 - 08:33:38 CST

Original text of this message

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