Oracle null value processing

Source: Internet
Author: User

1. null Concept

   There is an important concept in the database: null. Sometimes, in a table, some field values may be null because the data does not know the value or does not exist at all.

2. null value judgment

   The null value is not equal to the space in the string or the value of the number type 0. Therefore, =, <> cannot be used to determine whether a field value is null. A special phrase is required: Is
Null is used to select records with null fields. Similarly, records that do not contain null values can be selected using is not null. For example:

Select
* From party where leader is null;

Select
* From party where leader isNot NULL;

3. Convert null values

ORACLE:
Nvl
Nvl function:
The nvl function converts null fields into default fields for output.

Nvl (expr1, expr2)
Expr1, the field name or expression to be converted.
Expr2, null substitution value

The following is an example of number, date, Char or varchar2:
Nvl (commission_pct, 0)
Nvl (hire_date, '01-Jan-97 ')
Nvl (job_id, 'no job yun ')

SQL Server:
Isnull: If it is null, the specified value is returned; otherwise, the original value is returned.
Select username, isnull (address, 'None') from [user]...
------------------------------------------------------------------
Nullif returns NULL when two values (or expressions) are equal. Otherwise, the first parameter is returned.
Select sum (nullif (price, 100) from...
If the price is 100, it is treated as null, sum () will ignore the null value, so...
----------------------------------------------------------------------
Coalesce returns the first non-null value. The parameter value is any number.
Select coalesce (homephone, officephone, mobile) from ....
If a phone number is entered, a value is returned.
-----------------------------------------------------------------------
Access:
NZ
Same as SQL Server isnull. It can only be used in access programs, not supported by jet ado
Select username, NZ (address, 'None') from [user]...
IIF
Select username, IIF (address is null, 'none', address) from [user]...

Select username, IIF (address is null, 'unwrite',' written ') from [user]...

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.