【问题标题】:ORACLE SQL How to use custom function iside insert cteORACLE SQL如何使用自定义函数iside insert cte
【发布时间】:2020-06-01 10:20:20
【问题描述】:

我试图在插入 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)

【问题讨论】:

  • 您的数据库是什么版本的 Oracle?
  • 您需要/*+ WITH_PLSQL */ 提示。 dbfiddle.
  • @PonderStibbons,请发表您的评论作为答案,因为这是正确的解决方案。

标签: sql oracle sql-function


【解决方案1】:

如果包含 PL/SQL 声明部分的查询不是顶部 级别查询,顶级查询必须包含 WITH_PLSQL 提示。 没有这个提示,语句将无法编译

上面写着documentation。因此,在这种情况下,您可能需要:

insert /*+ WITH_PLSQL*/ into table1 (Field1, Field2, ...

dbfiddle 有类似的表格

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    • 1970-01-01
    • 1970-01-01
    • 2011-12-27
    • 2015-01-16
    相关资源
    最近更新 更多