Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
标签键&;使用Teradata正则表达式的值_Teradata_Regexp Substr - Fatal编程技术网

标签键&;使用Teradata正则表达式的值

标签键&;使用Teradata正则表达式的值,teradata,regexp-substr,Teradata,Regexp Substr,我有一个类似于以下内容的TERADATA数据集: '项目:大力神发行类型:改进组件:核心影响版本:2.4.1优先级:次要时间:2020年6月15日25时23分' 我想根据键从上面提取标记值 例: 是否有一种不必更改每个标记的位置参数的查询方法。 另外,我发现最后一个字段与日期和时间字段有点棘手 感谢您的帮助 谢谢。有NVP函数来访问名称/值对数据,但要分割成多行,您需要strtok_split_to_table或regexp_split_to_table。在您的案例中,棘手的部分是分隔符,如果它

我有一个类似于以下内容的TERADATA数据集:

'项目:大力神发行类型:改进组件:核心影响版本:2.4.1优先级:次要时间:2020年6月15日25时23分'

我想根据键从上面提取标记值

例:

是否有一种不必更改每个标记的位置参数的查询方法。 另外,我发现最后一个字段与日期和时间字段有点棘手

感谢您的帮助


谢谢。

NVP
函数来访问名称/值对数据,但要分割成多行,您需要
strtok_split_to_table
regexp_split_to_table
。在您的案例中,棘手的部分是分隔符,如果它们是唯一的,而不是
'
':'
:

WITH comm AS 
 (
   SELECT 1 as keycol, -- should be a key column in your table, either numeric or varchar
      'Project: Hercules IssueType: Improvement Components: core AffectsVersions: 2.4.1 Priority: Minor Time: 15:25:23 04/06/2020' AS text
 )
SELECT id, tokennum, token, 
   -- get the key
   StrTok(token,':', 1) AS "Key",
   -- get the value (can't use StrTok because of ':' delimiter)
   Substring(token From Position(': ' IN token)+2) AS "Value"
FROM TABLE
 ( RegExp_Split_To_Table(comm.keycol
                         ,comm.text
                         ,'( )(?=[^ ]+: )' -- assuming names don't contain spaces: split at the last space before ': '
                         , 'c') 
RETURNS (id INT , tokennum INTEGER, token VARCHAR(1000) CHARACTER SET Latin)) AS dt

返回的确切结果是什么?谢谢你的提问。如果上面的内容可以像下面那样用正则表达式分解成键和值,而不必提供位置参数,那么它会有所帮助关键值===========================================项目大力士发布类型改进组件核心影响版本2.4.1优先级次要时间15:25:23 04/06/2020```
WITH comm AS 
 (
   SELECT 1 as keycol, -- should be a key column in your table, either numeric or varchar
      'Project: Hercules IssueType: Improvement Components: core AffectsVersions: 2.4.1 Priority: Minor Time: 15:25:23 04/06/2020' AS text
 )
SELECT id, tokennum, token, 
   -- get the key
   StrTok(token,':', 1) AS "Key",
   -- get the value (can't use StrTok because of ':' delimiter)
   Substring(token From Position(': ' IN token)+2) AS "Value"
FROM TABLE
 ( RegExp_Split_To_Table(comm.keycol
                         ,comm.text
                         ,'( )(?=[^ ]+: )' -- assuming names don't contain spaces: split at the last space before ': '
                         , 'c') 
RETURNS (id INT , tokennum INTEGER, token VARCHAR(1000) CHARACTER SET Latin)) AS dt