将 Oracle 查询转换为雪花
Convert Oracle query to snowflake
我在将查询从 Oracle 转换为雪花时遇到问题。能不能帮帮忙。
示例 Oracle 查询:
替换(REGEXP_SUBSTR( col_name,'(.*?)([[:space:]]>>[[:space:]]|$)', 1,1 ) , ' >> ','') 作为测试
似乎 Snowflake 在处理正则表达式的 (.*?) 部分时表现不同。作为解决方法,您可以使用 [^>]* 或 \w+ 而不是 (.*?):
SELECT
replace(REGEXP_SUBSTR( 'test1 >> test2 >> test3','([^>]*)([[:space:]]>>[[:space:]]|$)', 1,1 ) , ' >> ','') as test;
SELECT
replace(REGEXP_SUBSTR( 'test1 >> test2 >> test3','\w+([[:space:]]>>[[:space:]]|$)', 1,1) , ' >> ','') as test;
这些应该给出与 Oracle 的 REGEXP_SUBSTR.
相同的结果 ("test1")
我在将查询从 Oracle 转换为雪花时遇到问题。能不能帮帮忙。
示例 Oracle 查询: 替换(REGEXP_SUBSTR( col_name,'(.*?)([[:space:]]>>[[:space:]]|$)', 1,1 ) , ' >> ','') 作为测试
似乎 Snowflake 在处理正则表达式的 (.*?) 部分时表现不同。作为解决方法,您可以使用 [^>]* 或 \w+ 而不是 (.*?):
SELECT
replace(REGEXP_SUBSTR( 'test1 >> test2 >> test3','([^>]*)([[:space:]]>>[[:space:]]|$)', 1,1 ) , ' >> ','') as test;
SELECT
replace(REGEXP_SUBSTR( 'test1 >> test2 >> test3','\w+([[:space:]]>>[[:space:]]|$)', 1,1) , ' >> ','') as test;
这些应该给出与 Oracle 的 REGEXP_SUBSTR.
相同的结果 ("test1")