How to extract the substring from the value of a column in Teradata?

Contents

Substring() function in Teradata

Substring function is used to extract a portion of a string from the value of a column.It returns the string based on the arguments such as starting position and length of the string.

Syntax of substring()

SUBSTR(STRING,Starting position,Length)

The first argument is the input string that can be either string or column name.

The staring position and length are both integers. Length is the optional arguments. If we are not specify the length, the substring will return string from the starting position to end of the string.

Example 1: (with starting position and length)

SELECT SUBSTR('Computer Science',10,7);

As we mentioned the starting position as 10 and length of the sub string as 7 in the sub string function, the string “Science” is extracted from the given input string as below.

Teradata substring example
Teradata substring example

Result:

Science

Example 2 : (Only starting position of the string)

SELECT SUBSTR('Revisit Class',9);

Result:

Class

Example 3 : (Extract a substring from a column value)

example for substring function
SELECT Country,SUBSTR(City,5,4) as City from Test_Db.Region;

Result:

Substring output in Teradata

Recommended Articles