有人可以让我知道如何将存储过程中的以下oracle源代码转换为Postgresql
CURSOR DATA_PKG (iPKG varchar2)IS
SELECT REGEXP_SUBSTR(iPKG, '[^,]+', 1, LEVEL) Data_PKG FROM dual
connect BY REGEXP_SUBSTR(iPKG, '[^,]+', 1, LEVEL) IS NOT NULL;
CURSOR LEC_PKG (iPKG varchar2) IS
SELECT REGEXP_SUBSTR(iPKG, '[^,]+', 1, LEVEL) LEC_Pkg FROM dual
connect BY REGEXP_SUBSTR(iPKG, '[^,]+', 1, LEVEL) IS NOT NULL;
我的Postgres代码如下,
c3 CURSOR (ipkg TEXT) FOR
WITH RECURSIVE t (pkg)
AS (SELECT
aws_oracle_ext.regexp_substr(ipkg, '[^,]+', 1, 1) AS data_pkg
UNION ALL
SELECT
aws_oracle_ext.regexp_substr(ipkg, '[^,]+', 1, t.level + 1)
FROM t
WHERE aws_oracle_ext.regexp_substr(ipkg, '[^,]+', 1, level + 1) IS NOT NULL)
SELECT
data_pkg
FROM t;
c4 CURSOR (ipkg TEXT) FOR
WITH RECURSIVE t2 (pkg)
AS (SELECT
aws_oracle_ext.regexp_substr(ipkg, '[^,]+', 1, 1) AS lec_pkg
UNION ALL
SELECT
aws_oracle_ext.regexp_substr(ipkg, '[^,]+', 1, t2.level + 1)
FROM t2
WHERE aws_oracle_ext.regexp_substr(ipkg, '[^,]+', 1, level + 1) IS NOT NULL)
SELECT
lec_pkg
FROM t2;
但是当我在Postgresql
中执行此函数时,它会引发如下错误,
ERROR: column t.level does not exist LINE 6: ... aws_oracle_ext.regexp_substr(ipkg, '[^,]+', 1, t.level + ...
^ QUERY: WITH RECURSIVE t (pkg)
AS (SELECT
aws_oracle_ext.regexp_substr(ipkg, '[^,]+', 1, 1) AS data_pkg
UNION ALL
SELECT
aws_oracle_ext.regexp_substr(ipkg, '[^,]+', 1, t.level + 1)
FROM t
WHERE aws_oracle_ext.regexp_substr(ipkg, '[^,]+', 1, level + 1) IS NOT NULL)
SELECT
data_pkg
FROM t CONTEXT: PL/pgSQL function "pop_bus_bundle$populate_bundle_names"() line 60 at FOR over cursor SQL state: 42703
答案 0 :(得分:0)
aws_oracle_ext.regexp_substr
是什么?是否正在执行转换的某种包装API?
为什么不直接使用将逗号分隔的字符串拆分为行的Postgres等效项?最终,看来这就是您在源代码中执行的select语句。
select regexp_split_to_table(iPKG,',');