【问题标题】:Multiple inline functions in OracleOracle 中的多个内联函数
【发布时间】:2019-08-01 11:23:14
【问题描述】:

我需要将我的第二个内联函数调用到我的第一个函数中。我无法实现这一目标并且只会出错。

with 
  function add_string(p_string in varchar2) return varchar2
  is
    --Function to add a string
    l_buffer varchar2(32767);
  begin
    l_buffer := p_string || ' works!';
    --
    return l_buffer;
    --
  end ; 
  --      
  function doesnt_it(p_string in varchar2) return varchar2
  is 
    l_buffer varchar2(32767);
    pp_string varchar2(32767);
  begin
    select add_string(p_string) into pp_string from dual;
    l_buffer := pp_string || ' Doesnt it?';
    --
    return l_buffer;
    --
  end ; 
--
select doesnt_it('Yes, it') as outVal
from dual
;

【问题讨论】:

  • 请添加您收到的错误消息。还包括 Oracle 版本,因为内联函数在 Oracle 12c 之前不可用。

标签: sql oracle inline-functions


【解决方案1】:

是的,您可以将SELECT func() INTO variable 替换为直接函数调用:

ORA-06553:PLS-231:函数 'ADD_STRING' 不能在 SQL 中使用

with 
  function add_string(p_string in varchar2) return varchar2
  is
    --Function to add a string
    l_buffer varchar2(32767);
  begin
    l_buffer := p_string || ' works!';
    --
    return l_buffer;
    --
  end ;

  function doesnt_it(p_string in varchar2) return varchar2
  is 
    l_buffer varchar2(32767);
    -- pp_string varchar2(32767);
  begin
    -- select add_string(p_string) into pp_string from dual;
    l_buffer := add_string(p_string) || ' Doesnt it?';  -- here is function call
    --
    return l_buffer;
    --
  end ; 

select  doesnt_it('Yes, it') as outVal
from dual;

db<>fiddle demo

输出:

OUTVAL
Yes, it works! Doesnt it?

替代解决方案:

pp_string :=  add_string(p_string);
l_buffer := pp_string || ' Doesnt it?';

db<>fiddle demo2


您还可以在块 Procedures in the WITH Clause 内嵌内联函数/过程

【讨论】:

    猜你喜欢
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多