简体   繁体   中英

How to Convert Oracle Sql to Postgresql

My SQL query has "connect by regexp_substr". How do I convert it to PostgreSQL 10 query ?

I have tried this in Ubuntu and 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?

string_to_array() is typically faster if no regular expression is needed.

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() :

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

In Postgres, it is possible that you would really phrase the overall query using arrays. If you have a question about a larger query, ask in a new question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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