Oracle nvl function Oracle's NVL function usage

When working on a project recently, a customer has a requirement to fill several columns in the data queried from the database with specific content. This function can be achieved by using the nvl function.

 

The following content is transferred from: https://www.cnblogs.com/yhoralce/p/6872121.html

Oracle's NVL function usage

Returns a non-null value from both expressions.

Syntax

NVL(eExpression1, eExpression2)

Parameters
eExpression1, eExpression2

If eExpression1 evaluates to a null value, NVL( ) returns eExpression2. Returns eExpression1 if eExpression1 does not evaluate to a null value. eExpression1 and eExpression2 can be of any data type. NVL( ) returns .NULL. if the results of eExpression1 and eExpression2 are both null values.

Return Value Types

Character, Date, DateTime, Numeric, Currency, Logical, or Null Value

Description

NVL( ) can be used to remove calculations or operations in cases where null values ​​are not supported or null values ​​are irrelevant A null value in .

select nvl(a.name,'空得') as name from student a join school b on a.ID=b.ID

Note: The types of the two parameters must match

copy code
 1 SELECT           T.D_FDATE,
 2  T.VC_ZHCODE,  3 NVL(SUM(T.F_FZQSZ), 0) f_price_b,  4 NVL(SUM(T.F_FZQCB), 0) f_cost_b,  5 NVL(SUM(T.F_FGZ_ZZ), 0) f_gz_b,  6 NVL(SUM(T.F_FYZQSZ), 0) f_price_Y,  7 NVL(SUM(T.F_FYZQCB), 0) f_cost_Y,  8 NVL(SUM(T.F_FYGZ_ZZ), 0) f_gz_Y,  9  T.VC_SOURCE, 10  SYSDATE d_updatetime 11 FROM GZ_FUND_GZB T 
copy code

For example, this kind of judgment is very important, because you don't know which row is not null, and you don't know whether to perform operations on this cell next. Therefore, if you can't fill a column with null, just give it a 0. Easy to view and easy to operate.

 

Returns a non-null value from both expressions.

Syntax

NVL(eExpression1, eExpression2)

Parameters
eExpression1, eExpression2

If eExpression1 evaluates to a null value, NVL( ) returns eExpression2. Returns eExpression1 if eExpression1 does not evaluate to a null value. eExpression1 and eExpression2 can be of any data type. NVL( ) returns .NULL. if the results of eExpression1 and eExpression2 are both null values.

Return Value Types

Character, Date, DateTime, Numeric, Currency, Logical, or Null Value

Description

NVL( ) can be used to remove calculations or operations in cases where null values ​​are not supported or null values ​​are irrelevant A null value in .

select nvl(a.name,'空得') as name from student a join school b on a.ID=b.ID

Note: The types of the two parameters must match

copy code
 1 SELECT           T.D_FDATE,
 2  T.VC_ZHCODE,  3 NVL(SUM(T.F_FZQSZ), 0) f_price_b,  4 NVL(SUM(T.F_FZQCB), 0) f_cost_b,  5 NVL(SUM(T.F_FGZ_ZZ), 0) f_gz_b,  6 NVL(SUM(T.F_FYZQSZ), 0) f_price_Y,  7 NVL(SUM(T.F_FYZQCB), 0) f_cost_Y,  8 NVL(SUM(T.F_FYGZ_ZZ), 0) f_gz_Y,  9  T.VC_SOURCE, 10  SYSDATE d_updatetime 11 FROM GZ_FUND_GZB T 
copy code

For example, this kind of judgment is very important, because you don't know which row is not null, and you don't know whether to perform operations on this cell next. Therefore, if you can't fill a column with null, just give it a 0. Easy to view and easy to operate.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325513467&siteId=291194637