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()
1 |
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)
1 |
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.
Result:
Science
Example 2 : (Only starting position of the string)
1 |
SELECT SUBSTR('Revisit Class',9); |
Result:
Class
Example 3 : (Extract a substring from a column value)
1 |
SELECT Country,SUBSTR(City,5,4) as City from Test_Db.Region; |
Result:
Recommended Articles
- REGEXP_SUBSTR function in Teradata with examples
- How to use Qualify row number in Teradata?
- REGEXP_REPLACE function in Teradata with examples
- Pivot function in Teradata with examples
- How to write a Nested Case statement in Teradata?