/    /  DBMS – String Operations

String Operations

 

There are the two string operators:

   Percent (%)  :  This Operator (%) matches any substring.

   Underscore ( _ ) : This Operator ( _ ) matches any character.

 Example 1 :

  1. a) ‘Intro%’  matches any word beginning with ‘intro’.
  2. b) ‘%comp%’ matches any string containing ‘comp’ as a substring where before ‘comp’ and after ‘comp’, there can be other substrings.
  3. c) ‘%map’ matches any string where the last characters are ‘map’.
  4. d) ‘ab%yz’ matches any string where the first two characters are ‘ab’ and the last characters are ‘yz’.
  5. e) ‘_ _ _’ matches exactly with three characters.
  6. f) ‘_ _ _ %’ matches any string with at least three characters.

 

Example 2 : Write an SQL query to match cust-name from cust relation where the first four characters are ‘abcd’.

  Select cust-name

   from cust

 wherecust-name like ‘abcd%’ ;

Reference

String Operations