SQL isnull (Oracle, mysql, mssql)

Source: Internet
Author: User
Tags mysql tutorial

SQL isnull (oracle, mysql tutorial, mssql)

Isnull
Replace null with the specified replacement value.

Syntax
Isnull (check_expression, replacement_value)

Parameters
Check_expression

Whether the expression is null is checked. Check_expression can be of any type.

Replacement_value

The expression returned when check_expression is null. Replacement_value must be the same

Check_expresssion has the same type.

Return type
Returns the same type as check_expression.

Note
If check_expression is not null, the value of this expression is returned; otherwise

Replacement_value

Example
A. Use isnull With avg
The following example finds the average price of all books and replaces the price column in the titles table with the value $10.00.

All null entries.

Use pubs
Go
Select avg (isnull (price, $10.00 ))
From titles
Go

Next, let's take a look at other database tutorials.

Oracle
Oracle does not have the isnull () function. However, we can use the nvl () function to achieve the same result:

Select productname, unitprice * (unitsinstock + nvl (unitsonorder, 0 ))
From products
Mysql
Mysql also has functions similar to isnull. However, it works with Microsoft's isnull () function.

A little different.

In mysql, we can use the ifnull () function, like this:

Select productname, unitprice * (unitsinstock + ifnull (unitsonorder, 0 ))
From products

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.