select name from users where name like '%\_%';

Posted on 2006-04-21
Last Modified: 2008-01-09
i am totally stunned.

i know that "_" stands for exact one char so that if i want look for "_" i have to escape it.

but why don't i get the answer i expect?

i have user like


this is what i expect to get from:
select name from users where name like '%\_%';

but i get empty result on oracle 9ir2 patchlevel 7

please help
Question by:mightyone
    LVL 6

    Author Comment

    ahh i found out....

    oracle needs to be told to escape \

    select name from users where name like '%\_%' ESCAPE '\';
    LVL 17

    Expert Comment

    An alternative to that,

    select u1 from (select 'user1' u1 from dual)
    where instr(u1,'_') >0
    LVL 2

    Expert Comment

    if I didn't understand wrong,

    that ur trying to search user_
    and then only 1 character after that at end, correct

    if this is the case then u can try:

    where .... like 'user\__'
    where .... like 'user__'

    try & update, if this works.

    cheers ;-)
    LVL 6

    Author Comment


    could you explain what your query does?
    specially what does (select 'user1' u1 from dual)
    exactly do. it writes sth in variable u1 but what?


    no, I use ora9ir2 and looked for names with underscores but got unexpected results even though i escaped the _ with \
    in fact the query i use is far morcomplicated but the prob could be taken down to this point.
    LVL 31

    Accepted Solution

    select name from users where instr(name,chr(95)) > 0;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
    How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now