gpt4 book ai didi

snowflake-cloud-data-platform - 使用正则表达式提取 Snowflake 中的特定文本

转载 作者:行者123 更新时间:2023-12-01 23:46:29 24 4
gpt4 key购买 nike

data input/table

想要获取键 [Work Order Description:] 的值并打印它。

使用的脚本:

CREATE TABLE demo3 (id INT, log VARCHAR);
INSERT INTO demo3 (id, log) VALUES
(1, 'Work order submitted on 12-03-2020
Work Order Description:Lights are not working
Work order status:Completed'),
(2, 'Work order submitted on 5-04-2020
Work order Priority:P3
Work Order Description:Electrical equipment issue
Work order status:Completed');

实现的解决方案:从 demo3 中选择 id, substr(log, regexp_instr(log, 'Work Order Description:') + 23, 300) 作为日志;

实现的解决方案输出:

id log
1 Lights are not working Work order status:Completed
2 Electrical equipment issue Work order status:Completed

问题:最后一行也附加到输出。相反,我希望在行尾修剪输出。

所需的期望输出:

1, Lights are not working
2, Electrical equipment issue

任何帮助将不胜感激。提前致谢。

最佳答案

您可以像这样使用 REGEXP_SUBSTR():

WITH data AS (
SELECT 2 AS id, 'Work order submitted on 5-04-2020
Work order Priority:P3
Work Order Description:Electrical equipment issue
Work order status:Completed' AS log
)

SELECT id, REGEXP_SUBSTR(log, 'Work Order Description:(.*)', 1, 1, 'e')
FROM data

关于snowflake-cloud-data-platform - 使用正则表达式提取 Snowflake 中的特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64055840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com