Comparison of NULL characters in Oracle

Source: Internet
Author: User

In Oracle, an empty string is treated as NULL, and any value with a null comparison result is null. As a result, an exception occurs when you compare two strings. Take a look at the following example:

declare     I VARCHAR2: = null;    v VARCHAR2 (Ten): = ' ABC '; begin    IF (i = v) then        Dbms_output. Put_Line (' equal ');    else        Dbms_output. Put_Line (' unequal ');    END IF; End; Please judge with your clever mind, what should be the result? It's easy to get the result: ' Unequal '. Very well, you are right. The result of running on Sqlplus is the same as what you think. Then I change the program, you can judge:declare     I VARCHAR2: = null;    v VARCHAR2 (Ten): = ' ABC '; begin    IF (i <> v) then        Dbms_output. Put_Line (' unequal ');    else        Dbms_output. Put_Line (' equal ');    END IF; END; It seems that there is not much difference between the first program, it is easy to get the result: ' Unequal '. Oh. Are you sure this is the result? Then please test it in sqlplus to verify that you are right. Unfortunately, the correct result should be: ' equal '. Are you surprised? As we said at the beginning: any value with a null comparison result is null. That is, the result of a i=v comparison in the first program should be null, and the result of the I<>v comparison in the second program is null. When the condition in the if structure is null, the current branch is skipped into the else or the end. Can't you? Then you run the following program will be able to wait until validation:begin    IF (NULL) then        Dbms_output. Put_Line (' not NULL ');    else        Dbms_output. Put_Line (' NULL ');    END IF; end; The result is output: ' NULL '.

Comparison of NULL characters 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.