ORACLE SQL 如何使用自定义函数iside insert cte
ORACLE SQL How to use custom function iside insert cte
我正在尝试在插入 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 中使用函数,但出现错误 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