1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Doubt???

Discussion in 'SQL PL/SQL' started by sambuduk, Feb 14, 2014.

  1. sambuduk

    sambuduk Forum Advisor

    Messages:
    242
    Likes Received:
    73
    Trophy Points:
    455
    Location:
    Hyderabad , Telangana
    Hi


    Is 'ABC ' is equalts 'ABC' ???

    Why I am asking is if I copmare in sql statement it is returning true. Check the below sql query.

    How it is??

    Code (SQL):
    SELECT LENGTH('ABC       '),LENGTH(('ABC'))
      FROM DUAL
      WHERE 'ABC       ' = ('ABC')


    Regards
    Sambasiva Reddy.K
     
  2. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,347
    Likes Received:
    348
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    Oracle automatically truncates trailing whitespace in strings so the condition actually becomes:


    WHERE 'ABC' = 'ABC'


    which is obviously true. If we put the whitespace at the beginning of the string:


    SQL> SELECT LENGTH('ABC '),LENGTH(('ABC'))
    2 FROM DUAL
    3 WHERE ' ABC' = 'ABC'
    4 /


    no rows selected




    things are no longer equal as the leading whitespace cannot be 'ignored'.
     
    sambuduk likes this.