Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Decode equivalent within pl/sql?
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" - UnknownReceived on Mon Nov 13 2006 - 08:33:38 CST
![]() |
![]() |