Introduction to Oracle nvl () and nvl2 () Functions

Source: Internet
Author: User

The Oracle nvl () and nvl2 () functions introduce a function in the NVL function Oracle/PLSQL. Format: www.2cto.com NVL (string1, replace_with) function: If string1 is NULL, The NVL function returns the value of replace_with; otherwise, the value of string1. Note: string1 and replace_with must be of the same data type unless the TO_CHAR function is displayed. For example: NVL (TO_CHAR (numeric_column), 'some string'). numeric_column indicates a numerical value. For example, nvl (yanlei777, 0)> 0 NVL (yanlei777, 0) means that if yanlei777 is NULL, the value 0 is used to obtain the total value of a field through the query, if this value is null, a default value, such as select nvl (sum (t. dwxhl), 1) from tb_jhde t indicates that if sum (t. dwxhl) = NULL returns 1 another useful method related to declare I integer select nvl (sum (t. dwxhl), 1) into I from tb_jhde t where zydm =-1 so that the obtained total value can be stored in variable I, if the queried value is null, set its value to the default value of 1 oracle: www.2cto.com select nvl (rulescore, 0) from zwjc_graderule where ruleco De = 'fwtd '; if the record does not contain data with rulecode = 'fwtd. no data is found. select nvl (rulescore, 0) into rule_score from zwjc_graderule where rulecode = 'fwtd '; select nvl (sum (rulescore), 0) from zwjc_graderule where rulecode = 'fwtd '; if the record does not contain rulecode = 'fwtd' data. you can also obtain data with a column name of nvl (rulescore, 0) and a value of 0. select nvl (sum (rulescore), 0) into rule_score from zwjc_graderule where rulecode = 'fwtd' For NVL2 functions. NVL2 (E1, E2, E3) functions: If E1 is NULL, the function returns E3. If E1 is not null, the function returns E2.
 

Related Article

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.