如何将此配置单元查询转换为 oracle
How to convert this hive query to oracle
我有这个配置单元查询:
select REGEXP_EXTRACT( lower(column_name) , '.*(build[ \t]*(app)?[ \t]*:[ \t]*)(.*?)([ \t]*;[ \t]*essential[ \t]+reason[ \t]+info[ \t]+compilation.*$|$)', 3) from table
如何将其转换为 oracle 查询?
我试过使用 regexp_substr()
,但效果不佳。谢谢!
如果您可以编辑您的问题以添加一些具有预期输出的示例数据,这样我们就可以看到如何它“不起作用”。
regexp_substr()
遵循与 regexp_extract()
相同的语法,但 Oracle(与许多供应商一样)only supports a specific set of regular expression operators.
对于您的情况,我看到的主要问题是 \t
在 Oracle 中未被解释为“制表符”。您有多种选择来匹配制表符:
with test_data as (select 'build'||chr(9)||':' as s from dual) -- 'build' with a tab character then a ':'
select
regexp_substr(s, 'build[ \t]*:') as slash_t, -- doesn't work
regexp_substr(s, 'build[[:space:]]*:') as posix_cc, -- matches any whitespace characters
regexp_substr(s, 'build\s*:') as perl_cc, -- same as posix, but perl dialect
regexp_substr(s, 'build[ ]*:') as literal_tab, -- Whosebug formatting ruins this, but there was a tab there
regexp_substr(s, 'build[ '||chr(9)||']*:') as chr_tab -- chr(9) is tab
from test_data;
输出:
SLASH_T POSIX_CC PERL_CC LITERAL_TAB CHR_TAB
------- -------- ------- ----------- -------
build : build : build : build :
我有这个配置单元查询:
select REGEXP_EXTRACT( lower(column_name) , '.*(build[ \t]*(app)?[ \t]*:[ \t]*)(.*?)([ \t]*;[ \t]*essential[ \t]+reason[ \t]+info[ \t]+compilation.*$|$)', 3) from table
如何将其转换为 oracle 查询?
我试过使用 regexp_substr()
,但效果不佳。谢谢!
如果您可以编辑您的问题以添加一些具有预期输出的示例数据,这样我们就可以看到如何它“不起作用”。
regexp_substr()
遵循与 regexp_extract()
相同的语法,但 Oracle(与许多供应商一样)only supports a specific set of regular expression operators.
对于您的情况,我看到的主要问题是 \t
在 Oracle 中未被解释为“制表符”。您有多种选择来匹配制表符:
with test_data as (select 'build'||chr(9)||':' as s from dual) -- 'build' with a tab character then a ':'
select
regexp_substr(s, 'build[ \t]*:') as slash_t, -- doesn't work
regexp_substr(s, 'build[[:space:]]*:') as posix_cc, -- matches any whitespace characters
regexp_substr(s, 'build\s*:') as perl_cc, -- same as posix, but perl dialect
regexp_substr(s, 'build[ ]*:') as literal_tab, -- Whosebug formatting ruins this, but there was a tab there
regexp_substr(s, 'build[ '||chr(9)||']*:') as chr_tab -- chr(9) is tab
from test_data;
输出:
SLASH_T POSIX_CC PERL_CC LITERAL_TAB CHR_TAB
------- -------- ------- ----------- -------
build : build : build : build :