What are the usage and differences between Decode and nvl functions in Oracle ?, Decodenvl

Source: Internet
Author: User

What are the usage and differences between Decode and nvl functions in Oracle ?, Decodenvl
Decode

Decode (condition, value 1, translation value 1, value 2, translation value 2 ,..., default Value... else if... else has the same meaning

NVL

Format:NVL (string1, replace_with)

Function: If string1 is NULL, The NVL function returns the value of replace_with; otherwise, the value of string1 is returned. If both parameters are NULL, NULL is returned.

Note: string1 and replace_with must be of the same data type, unless explicitly converted using the TO_CHAR function.

Select nvl (sum (t. dwxhl), 1) from tb_jhde t indicates that if sum (t. dwxhl) = NULL, 1 is returned.

Oracle extends NVL functions and provides NVL2 functions.

NVL2

Nvl2 (E1, E2, E3) function: If E1 is NULL, the function returns E3; otherwise, the function returns E2.

Integration

Decode, NVL, and other functions are often used in combination, such

Select monthid, decode (nvl (sale, 6000), 6000, 'ng ',' OK ') from output


The sign () function returns 0, 1,-1, and,

If a smaller value is set to select monthid, decode (sign (sale-6000),-1, sale, 6000) from output, the smaller value is obtained.



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.