LIKE Command in Teradata


We can see LIKE clause function below.


Suppose if you want to find out particular word or character is present in the starting of the string or ending of the string or middle of the string, You can use Like clause to narrow down the result set.


Syntax of LIKE clause:-


SELECT {*|<ColumnName>}
FROM <TableName>
WHERE <column name> LIKE [ALL | ANY] ‘[% | _] CharString [% | _]’

Here  ‘_’ means single character and ‘%’ means any no.of characters,.

If data value contains underscore and you need to display underscore as a value in the result set , use ESCAPE operator to treat the underscore as a value and not as a wildcard character. 

SELECT f_name, l_name
FROM employee
WHERE lname LIKE (‘S\_%’) ESCAPE ‘\’ 

The above query would find results like S_456, S_mon, Note that the underscore is present at the second position of the string.

Here, we can use any character whatever we like.

For example, both of following statements would return the same results.

SELECT f_name, l_name
FROM employee
WHERE  lname LIKE  (‘S@_%’) ESCAPE ‘@’ 

SELECT f_name, l_name
FROM employee
WHERE  lname LIKE (‘S$_%’) ESCAPE ‘$’


1 comment:

  1. Pretty good post. I found your website perfect for my needs. Thanks for sharing the great ideas.


    Kesh
    www.imarksweb.org

    ReplyDelete