简体   繁体   English

如何将Oracle Sql转换为Postgresql

[英]How to Convert Oracle Sql to Postgresql

My SQL query has "connect by regexp_substr". 我的SQL查询有“connect by regexp_substr”。 How do I convert it to PostgreSQL 10 query ? 如何将其转换为PostgreSQL 10查询?

I have tried this in Ubuntu and toad... 我在Ubuntu和toad中试过这个...

  select regexp_substr('1,2,4','[^,]+', 1, level) from dual
    connect by regexp_substr('1,2,4', '[^,]+', 1, level) is not null;

How to do I get convert above query to PostgreSQL version 10? 如何将上面的查询转换为PostgreSQL版本10?

string_to_array() is typically faster if no regular expression is needed. 如果不需要正则表达式, string_to_array()通常会更快。

select *
from unnest(string_to_array('1,2,4', ',')) as t(c);

If I understand correctly, you want to split a comma-delimited string into rows. 如果我理解正确,您希望将逗号分隔的字符串拆分为行。 For that, use regexp_split_to_table() : 为此,请使用regexp_split_to_table()

select regexp_split_to_table('1,2,4', ',')

In Postgres, it is possible that you would really phrase the overall query using arrays. 在Postgres中,您可能真的使用数组来表达整个查询。 If you have a question about a larger query, ask in a new question. 如果您对较大的查询有疑问,请在问题中提问。

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

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