Results 1 to 6 of 6

Thread: Difference between LIKE and %

  1. #1
    Geek_Guest
    Guest

    Difference between LIKE and %

    What is the difference between If I use SUBSTR (last_name,-1,1)='n'; or last_name is like'_n' or '%n' for the all the names in last_name which end by letter 'n'

    Question asked by visitor Rajesh


  2. #2
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: Difference between LIKE and %

    Like is used for pattern matching .
    _n means any Last_name where the second character is n.
    %n means any Last_name where the last character is n.


  3. #3
    Junior Member
    Join Date
    Jul 2007
    Answers
    6

    Re: Difference between LIKE and %

    SUBSTR (last_name,-1,1)='n'
    it will return the last leter of the string


  4. #4
    Junior Member
    Join Date
    Oct 2007
    Answers
    12

    Re: Difference between LIKE and %

    In Oracle _ and % are Wild characters, so _ means exactly 1 ..in case of '_n' means max length is 2 and last character has to be n.
    But % is for 0 or any no. of characters/numbers, so %n means length could be any but last character has to be n.


  5. #5
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: Difference between LIKE and %

    Both the wild card characters are used only for patternmatching for charater data not for numbers.


  6. #6
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: Difference between LIKE and %

    Quote Originally Posted by geek_guest View Post
    what is the difference between if i use substr (last_name,-1,1)='n'; or last_name is like'_n' or '%n' for the all the names in last_name which end by letter 'n' question asked by visitor rajesh
    substr(char,m [,n])
    purpose: returns a portion of char, beginning at character m, n characters
    long. If m is positive, oracle counts from the beginning of char to
    find the first character. If m is negative, oracle counts backwards
    from the end of char. The value m cannot be 0. If n is omitted,
    oracle returns all characters to the end of char. The value n
    cannot be less than 1.
    examples:
    select substr('abcdefg',3,2) "substring" from dual
    substring
    cd
    select substr('abcdefg',-3,2) "reversed substring" from dual
    reversed substring
    ef
    LIKE
    The like condition allows you to use wildcards in the where clause of an sql statement. This allows you to perform pattern matching. The like condition can be used in any valid sql statement - select, insert, update, or delete.
    the patterns that you can choose from are:
    % allows you to match any string of any length (including zero length)
    _ allows you to match on a single character
    select * from emp where ename like '_n' return records form emp where second char in ename starts with 'n'
    select * from emp where ename like '%n' return records from emp where ename ends with 'n'


    Last edited by susarlasireesha; 11-10-2007 at 04:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact