How to split the string based on delimiter in Teradata
Contents
STRTOK function in Teradata
STRTOK function is used to split the string into tokens based on the specified delimiter. It returns the particular string token based on the tokennum argument.
Syntax for STRTOK function in Teradata
1 |
STRTOK(Input_String,Delimiter,tokennum) |
Input_String : A character string or String expression
Delimiter : A delimiter character. Each character in the string is considered as delimiter.If not specified, the default delimiter character is space.
tokennum : A token number to return. If not specified, the default value is 1.
STRTOK example:1 – To split the name
1 |
SELECT STRTOK('James Daniel',' ',1) AS First_name; |
Here we are splitting the first name and last name from the string using STRTOK function. The delimiter character is specified as space and it returns the first name as we mentioned the token number as 1.
STRTOK example:2 – To split the website url
1 |
SELECT STRTOK('www.revisitclass.com','.',2) AS Domain_Name; |
In this example, we are splitting the website URL based on the delimiter character dot(.).Since we have mentioned the token number as 2, It returns the domain name alone without www and com.
Recommended Articles
- Substring function in Teradata with examples
- Regexp_substr function in Teradata with examples
- How to get the position of the substring in Teradata?