Teradata SQL LIKE: Contains, Starts With, Ends With Functions

access_time 4 months ago visibility153 comment 0

This page shows how to use LIKE in Teradata to check whether a string column contains, starts with or ends with certain characters. 

All the code snippets are using string literal and you can replace them with your table/view column name if you want to apply them in your queries. 

Starts with a string

We can use % to match a 

select case when 'Kontext.tech' LIKE 'Kontext%' then 1 else 0 end

The above query returns 1 as the string literal starts with Kontext.

Ends with a string

select case when 'Kontext.tech' LIKE '%tech' then 1 else 0 end

The above query returns 1 too as the string literal does end with tech.

Contains a string

select case when 'Kontext.tech' LIKE '%text%' then 1 else 0 end

This query also returns 1 as the string literal has that sub string inside it.

You can also use other functions like INDEX or POSITION.

INDEX function

select case when INDEX('Kontext.tech', 'text')>0 then 1 else 0 end

The function will return 0 if the search string doesn't exist.

POSITION function

sel position('text' in 'Kontext.tech' )

The function will return 0 if the search string doesn't exist.

info Last modified by Administrator at 3 months ago copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Kontext Column

Created for everyone to publish data, programming and cloud related articles.
Follow three steps to create your columns.


Learn more arrow_forward

More from Kontext

local_offer teradata local_offer python local_offer python-database

visibility 14229
thumb_up 1
access_time 3 years ago

Teradata published an official Python module which can be used in DevOps projects. More details can be found at the following GitHub site: https://github.com/Teradata/PyTd If pip is installed, you can directly install this module through the following command: pip install Teradata If not ...

local_offer teradata local_offer SQL local_offer teradata-functions

visibility 308
thumb_up 0
access_time 8 months ago

Extract sub string from a string is a common operation in data analytics. In Teradata, function SUBSTRING (SUBSTR) and REGEXP_SUBSTR are provided to achieve that. SUBSTR is used to extract string from a specified location while REGEXP_SUBSTR is used to extract string using regular expressions. -- ...

local_offer teradata

visibility 634
thumb_up 0
access_time 4 years ago

This post summarizes the tutorials I created in the past about Teradata. It is trying to help you gain the basic SQL skills with Teradata especially if you are a new beginner or you just move from SQL Server or Oracle. It also includes some guides about setting up your own Teradata server (latest Teradata Express version TDExpress16.10.00.03_Sles11_40GB.7z).

About column

Code snippets and tips for various programming languages/frameworks.

rss_feed Subscribe RSS