What are the uses and differences of decode and NVL functions in Oracle?

Source: Internet
Author: User

Decode

decode (condition, value 1, translation value 1, value 2, translation value 2,..., default) The function is the same as the If...else If...else in the program.

NVL

format: NVL (string1, Replace_with)

function: If string1 is null, the NVL function returns the value of Replace_with, otherwise returns the value of string1, or null if all two parameters are null.

Note:string1 and Replace_with must be of the same data type unless you explicitly use the To_char function for type conversion .

Select NVL (SUM (T.DWXHL), 1) from Tb_jhde t means that if sum (T.DWXHL) = NULL returns 1

Oracle expands on the functionality of the NVL function, providing the NVL2 function

NVL2

The function of Nvl2 (E1, E2, E3) is: If E1 is null, the function returns E3, otherwise returns E2

Combine

Functions such as Decode and NVL are often used in conjunction, such as

Select Monthid,decode (NVL (sale,6000), 6000, ' NG ', ' OK ') from output


The sign () function returns 0, 1,-1, depending on whether a value is 0, positive, or negative.

If you take a smaller value , it's Select Monthid,decode (sale-6000), -1,sale,6000) from output, which is the purpose of taking a smaller value.



What are the uses and differences of decode and NVL functions in Oracle?

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.