gpt4 book ai didi

sql - ORACLE SQL 如何在插入 cte 中使用自定义函数

转载 作者:行者123 更新时间:2023-12-04 10:34:17 27 4
gpt4 key购买 nike

我试图在插入 SQL 中使用函数,但出现错误 ORA-32034。看起来我无法在 cte 中访问此功能。
也许有人可以帮忙?

    insert into table1 (     

Field1,
Field2,
Field3
)

with


function STR_country(in_str VARCHAR2) return char is out_str char(2);
begin
out_str :='';
if SUBSTR(in_str,1,1)= 'A' then out_str :='AT';
elsif SUBSTR(in_str,1,1)= 'D' then out_str :='DE';
elsif SUBSTR(in_str,1,2)= 'CH' then out_str :='CH';
elsif SUBSTR(in_str,1,2)= 'CZ' then out_str :='CZ';
elsif SUBSTR(in_str,1,1)= 'H' then out_str :='HU';
else out_str := ' ';
end if;
return out_str ;
end;



help_select_transactions1 as
(select distinct

master.reference,
f.start_date,
f.end_date,
f.Branch_NO,
f.seq,
master.SOURCEAPPLICATIONCODE,
f.PAYRECIND,
f.NOSTRODDAINDICATOR,
f.PAYMENTVALUEDATE,
f.PAYMENTCURRENCY,
f.PAYMENTAMOUNT,
STR_country(customer1.address3) as customer_country,
STR_country(customer2.address3) as customer_country2)

最佳答案

If the query containing the PL/SQL declaration section is not the top level query, the top-level query must include the WITH_PLSQL hint. Without this hint, the statement will fail to compile



这说 documentation .因此,在这种情况下,您可能需要:
insert /*+ WITH_PLSQL*/ into table1 (Field1, Field2, ...

dbfiddle 同 table

关于sql - ORACLE SQL 如何在插入 cte 中使用自定义函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60263218/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com