Home » SQL & PL/SQL » SQL & PL/SQL » Opposite function to NVL()?
Opposite function to NVL()? [message #177104] Tue, 13 June 2006 01:41 Go to next message
zodiac_hh
Messages: 10
Registered: June 2006
Junior Member
Hi there,

is there a build-in standard function in SQL that does the opposite of NVL(), so that it sets a field to NULL if it has a specific value?
Re: Opposite function to NVL()? [message #177105 is a reply to message #177104] Tue, 13 June 2006 01:49 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9106
Registered: November 2002
Location: California, USA
Senior Member
decode (column_name, specific_value, null)

or you could use case
Re: Opposite function to NVL()? [message #177142 is a reply to message #177104] Tue, 13 June 2006 04:36 Go to previous messageGo to next message
zodiac_hh
Messages: 10
Registered: June 2006
Junior Member
works fine, thanks! Can I also assume that there is no predefined function for this?
Re: Opposite function to NVL()? [message #177145 is a reply to message #177142] Tue, 13 June 2006 04:39 Go to previous messageGo to next message
JSI2001
Messages: 1016
Registered: March 2005
Location: Scotland
Senior Member
Yes there is, but Barbara chose to give you a different solution because the pre-defined function is a secret Wink
Re: Opposite function to NVL()? [message #177146 is a reply to message #177142] Tue, 13 June 2006 04:42 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
You are right. You could opt for NVL2. From the manuals:
NVL2 ( expr1 , expr2 , expr3 )
If expr1 is not null, NVL2 returns expr2. If expr1 is null, NVL2 returns expr3. The argument expr1 can have any datatype. The arguments expr2 and expr3 can have any datatypes except LONG.
SQL> ed
Wrote file afiedt.buf

  1  select NVL2(NULL
  2             , NULL /* not null becomes null */
  3             , 'your_value_when_null') x
  4* from dual
SQL> /

X
--------------------
your_value_when_null
I think that's not available in PL/SQL but nor is DECODE.

MHE

[Updated on: Tue, 13 June 2006 04:42]

Report message to a moderator

Re: Opposite function to NVL()? [message #177178 is a reply to message #177146] Tue, 13 June 2006 06:25 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
nvl2 does not exactly do what the OP asked for:
so that it sets a field to NULL if it has a specific value?

Re: Opposite function to NVL()? [message #177181 is a reply to message #177178] Tue, 13 June 2006 06:30 Go to previous message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
Good one. I missed that part.

MHE
Previous Topic: User Tables
Next Topic: PLSQL Developer Question
Goto Forum:
  


Current Time: Sat Jun 21 15:03:19 CDT 2025