Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6533093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:05:00+00:00 2026-05-25T10:05:00+00:00

I have the following Oracle PL/SQL codes that may be rusty from you guys

  • 0

I have the following Oracle PL/SQL codes that may be rusty from you guys perspective:

 DECLARE
 str1  varchar2(4000);
 str2  varchar2(4000);
 BEGIN
   str1:='';
   str2:='sdd';
   IF(str1<>str2) THEN
    dbms_output.put_line('The two strings is not equal');
   END IF;
 END;
 /

This is very obvious that two strings str1 and str2 are not equal, but why ‘The two strings are not equal’ was not printed out? Do Oracle have another common method to compare two string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:05:00+00:00Added an answer on May 25, 2026 at 10:05 am

    As Phil noted, the empty string is treated as a NULL, and NULL is not equal or unequal to anything. If you expect empty strings or NULLs, you’ll need to handle those with NVL():

     DECLARE
     str1  varchar2(4000);
     str2  varchar2(4000);
     BEGIN
       str1:='';
       str2:='sdd';
    -- Provide an alternate null value that does not exist in your data:
       IF(NVL(str1,'X') != NVL(str2,'Y')) THEN
        dbms_output.put_line('The two strings are not equal');
       END IF;
     END;
     /
    

    Concerning null comparisons:

    According to the Oracle 12c documentation on NULLS, null comparisons using IS NULL or IS NOT NULL do evaluate to TRUE or FALSE. However, all other comparisons evaluate to UNKNOWN, not FALSE. The documentation further states:

    A condition that evaluates to UNKNOWN acts almost like FALSE. For example, a SELECT statement with a condition in the WHERE clause that evaluates to UNKNOWN returns no rows. However, a condition evaluating to UNKNOWN differs from FALSE in that further operations on an UNKNOWN condition evaluation will evaluate to UNKNOWN. Thus, NOT FALSE evaluates to TRUE, but NOT UNKNOWN evaluates to UNKNOWN.

    A reference table is provided by Oracle:

    Condition       Value of A    Evaluation
    ----------------------------------------
    a IS NULL       10            FALSE
    a IS NOT NULL   10            TRUE        
    a IS NULL       NULL          TRUE
    a IS NOT NULL   NULL          FALSE
    a = NULL        10            UNKNOWN
    a != NULL       10            UNKNOWN
    a = NULL        NULL          UNKNOWN
    a != NULL       NULL          UNKNOWN
    a = 10          NULL          UNKNOWN
    a != 10         NULL          UNKNOWN
    

    I also learned that we should not write PL/SQL assuming empty strings will always evaluate as NULL:

    Oracle Database currently treats a character value with a length of zero as null. However, this may not continue to be true in future releases, and Oracle recommends that you do not treat empty strings the same as nulls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following bit of code that reads data from the an Oracle
I have the following iBatis mapping for an Oracle Stored Procedure that returns a
I have the following query that runs in my Oracle database and I want
In the JDBC code, I have the following that is working with SQL Server:
I have a following oracle sql query in which START_DATE is a number column
I have the following Oracle function: function get_job_no return number is V_job_no number; begin
I have a following oracle query: SELECT a.USER_ID, c.first_name, c.last_name, TO_CHAR( b.logon_date, 'MM/DD/YYYY HH:MI:SS
So I have the following user defined type in my oracle database: CREATE OR
I'd need advice on following situation with Oracle/PostgreSQL: I have a db table with
I have following SQL: select origin,destination,to_char(to_date(substr(ship_date,1,6),'YYMMDD'), 'YYYY-MM-DD'),ship_date,trip_number, distinct ship_number from shipment a where a.scc_code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.