Oracle functions for processing null values

Source: Internet
Author: User
1. nvl (expr1, expr2) If exp1 is null, exp2 is returned; otherwise expr1 is returned; 2. nvl2 (expr1, expr2, expr3) If exp1 is null, expr3 is returned, otherwise, expr2; 3, coalesce (expr [, expr1]...) is returned. the first non-null value in the returned parameter; withtestas (selectc11col_1, col_2, c31col_3fro

1. nvl (expr1, expr2) If exp1 is null, exp2 is returned; otherwise expr1 is returned; 2. nvl2 (expr1, expr2, expr3) If exp1 is null, expr3 is returned, otherwise, expr2; 3, coalesce (expr [, expr1]...) is returned. the first non-null value in the returned parameter; with test as (select 'c11' col_1, ''col_2, 'c31' col_3 fro

1. nvl (expr1, expr2)

If exp1 is a null value, exp2 is returned; otherwise, expr1 is returned;

2. nvl2 (expr1, expr2, expr3)

If exp1 is null, expr3 is returned; otherwise, expr2 is returned;

3. coalesce (expr [, expr1]...)

The first non-null value in the returned parameter;

With test
(Select 'c11' col_1, ''col_2, 'c31' col_3 from dual union all
Select ''col_1, 'c21' col_2, 'c32' col_3 from dual union all
Select 'c13 'col_1, 'c22' col_2, ''col_3 from dual union all
Select ''col_1, 'c23' col_2, 'c33' col_3 from dual union all
Select 'c14' col_1, ''col_2, 'c34' col_3 from dual union all
Select 'c15' col_1, ''col_2,'' col_3 from dual
)
Select col_1, nvl (col_1, col_1) exp_1,
Col_2, nvl2 (col_2, col_2 | ',', 'is null') exp_2,
Col_3, coalesce (col_1, col_2, col_3) exp_3
From test;

COL_1 EXP_1 COL_2 EXP_2 COL_3 EXP_3
--------------------------------------
C11 c11 is null c31 c11
C21 c21, c32 c21
C13 c13 c22 c22, c13
C23 c23, c33 c23
C14 c14 is null c34 c14
C15 c15 is null c15

6 rows selected

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.