简体   繁体   English

如何将此 hive 查询转换为 oracle

[英]How to convert this hive query to oracle

I have this hive query:我有这个 hive 查询:

select REGEXP_EXTRACT( lower(column_name) , '.*(build[ \t]*(app)?[ \t]*:[ \t]*)(.*?)([ \t]*;[ \t]*essential[ \t]+reason[ \t]+info[ \t]+compilation.*$|$)', 3) from table

How do I convert it to oracle query?如何将其转换为 oracle 查询?

I have tried using regexp_substr() but it doesn't work like it needs to.我试过使用regexp_substr()但它无法正常工作。 Thanks!谢谢!

It would help a lot if you could edit your question to add some example data with your expected output so we could see how it "doesn't work".如果您可以编辑您的问题以使用您预期的 output 添加一些示例数据,那么我们可以看到它是如何“不起作用”的,这将有很大帮助。

regexp_substr() follows the same syntax as regexp_extract() , but Oracle (like many vendors) only supports a specific set of regular expression operators . regexp_substr()遵循与regexp_extract() () 相同的语法,但 Oracle(与许多供应商一样) 仅支持一组特定的正则表达式运算符

In your case, the main issue I see is that \t isn't interpreted as "tab character" in Oracle. You have several alternatives to match tab characters:在您的情况下,我看到的主要问题是\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, -- StackOverflow 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;

Output: Output:

SLASH_T POSIX_CC PERL_CC LITERAL_TAB CHR_TAB
------- -------- ------- ----------- -------
        build  : build : build   :   build :

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM