DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: SQL Query ??

  1. #1
    Join Date
    Jul 2000
    Posts
    23
    I've a situation ..like this

    data in a particular in colum will end with "_XXXX" , I wanted to retreive these records only .
    there are other records in the table with data "XXXXXXXXXX"

    When I run this query ..it is picking everything ..?? how come it is looking for "_" .

    select column_name from table where column_ name like '_XXXX'


    Data in colum

    XXXXXXXX
    ABC_XXXX


    o/p shuld be

    ABC_XXXX

    but I get

    XXXXXXXX
    ABC_XXXX


    why ?






  2. #2
    Join Date
    Sep 2001
    Location
    NJ, USA
    Posts
    1,287
    U should use escape characters for this query:

    select column_name from table where column_ name like '%\_XXXX' escape '\';

  3. #3
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    The underscore is a wild card operator, you have to escape it.

    Code:
    SQL> select * from xyz;
    
    X
    ----------
    AAAA_XXXX
    XXXXXXXX
    XXX_XXXX
    
    SQL> select * from xyz where x like '%_XXXX';
    
    X
    ----------
    AAAA_XXXX
    XXXXXXXX
    XXX_XXXX
    
    SQL> select * from xyz where x like '%\_XXXX' escape '\';
    
    X
    ----------
    AAAA_XXXX
    XXX_XXXX
    Jeff Hunter

  4. #4
    Join Date
    Jul 2000
    Posts
    23
    thank U guys ...Learning Oracle never ends ....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width