Difference between revisions of "NVL"

From SQLZOO
Jump to: navigation, search
 
Line 9: Line 9:
 
<tr><td align='left'>sqlserver</td><td>No</td><td>[[COALESCE |COALESCE(f1, f2)]]</td></tr>
 
<tr><td align='left'>sqlserver</td><td>No</td><td>[[COALESCE |COALESCE(f1, f2)]]</td></tr>
 
</table>
 
</table>
 +
 
<h1>NVL</h1>
 
<h1>NVL</h1>
 
<p>NVL takes two arguments and returns the first value that is not null.</p>
 
<p>NVL takes two arguments and returns the first value that is not null.</p>
Line 38: Line 39:
 
   <li>[[COALESCE |COALESCE function]]</li>
 
   <li>[[COALESCE |COALESCE function]]</li>
 
</ul>
 
</ul>
 +
 +
{{Languages}}

Latest revision as of 11:41, 28 October 2012

Compatibility
NVL(f1, f2)
EngineOKAlternative
ingresNoCOALESCE(f1, f2)
mysqlNoCOALESCE(f1, f2)
oracleYesCOALESCE(f1, f2)
postgresNoCOALESCE(f1, f2)
sqlserverNoCOALESCE(f1, f2)

NVL

NVL takes two arguments and returns the first value that is not null.

   NVL(x,y) = x if x is not NULL
   NVL(x,y) = y if x is NULL

NVL can be useful when you want to replace a NULL value with some other value. In this example you show the name of the party for each MSP that has a party. For the MSP with no party (such as Canavan, Dennis) you show the string None.

SELECT name, party
      ,NVL(party,'None') AS aff
  FROM gisq.msp WHERE name LIKE 'C%'
SELECT name, party
      ,COALESCE(party,'None') AS aff
  FROM msp WHERE name LIKE 'C%'

See also

Language: English  • Deutsch
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense