Teradata SQL-从字符串/列中查找每个标记之间的值
我想提取标记之间的值,并从中创建新的列 e、 g my列(即varchar)获得以下值:Teradata SQL-从字符串/列中查找每个标记之间的值,sql,regex,teradata,Sql,Regex,Teradata,我想提取标记之间的值,并从中创建新的列 e、 g my列(即varchar)获得以下值: Working : History 0 : <Site Details.Number of Complaints>WAS<>IS<3> 仅供参考-每列将有3个确切的开始和结束标签。我也需要teradata SQL。正如您注意到的STRTOK不能用于此,它用于使用非常基本的规则标记字符串 您需要一个正则表达式: SELECT RegExp_Substr(col
Working : History 0 : <Site Details.Number of Complaints>WAS<>IS<3>
仅供参考-每列将有3个确切的开始和结束标签。我也需要teradata SQL。正如您注意到的
STRTOK
不能用于此,它用于使用非常基本的规则标记字符串
您需要一个正则表达式:
SELECT
RegExp_Substr(col, '<\K.*?(?=>)',1,1)
,RegExp_Substr(col, '<\K.*?(?=>)',1,2)
,RegExp_Substr(col, '<\K.*?(?=>)',1,3)
,'Working : History 0 : <Site Details.Number of Complaints>WAS<>IS<3>' AS col
<\K.*?(?=>)
<\K = check for '<', but don't add it to the result (similar to a positive lookbehind, which will not work in this case)
.*? = any characters, i.e. the expected result
(?=>) = check for '>' without adding it to the result, i.e. positive lookahead
选择
RegExp_Substr(列“)”,1,1)
,RegExp_Substr(col',)',1,2)
,RegExp_Substr(col',)',1,3)
“工作:历史0:WASIS”作为列
)
'而不将其添加到结果中,即正向前瞻
有关详细信息,请参阅
col_a col_b col_c col_d
1 Working : History 0 : Site Details.Number of Complaints IS 3
SELECT
RegExp_Substr(col, '<\K.*?(?=>)',1,1)
,RegExp_Substr(col, '<\K.*?(?=>)',1,2)
,RegExp_Substr(col, '<\K.*?(?=>)',1,3)
,'Working : History 0 : <Site Details.Number of Complaints>WAS<>IS<3>' AS col
<\K.*?(?=>)
<\K = check for '<', but don't add it to the result (similar to a positive lookbehind, which will not work in this case)
.*? = any characters, i.e. the expected result
(?=>) = check for '>' without adding it to the result, i.e. positive lookahead