2

I have the requirement to call my 2nd inline function into my 1st function. I am not able to achieve this one and getting error only.

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
;
1
  • 3
    Please add the error message you get. Also include the Oracle version as inline functions weren't available before Oracle 12c. Commented Aug 1, 2019 at 12:52

1 Answer 1

4

Yes it is possible you should replace SELECT func() INTO variable with direct function call:

ORA-06553: PLS-231: function 'ADD_STRING' may not be used in 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

Output:

OUTVAL
Yes, it works! Doesnt it?

Alternative solution:

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

db<>fiddle demo2


You could also have inline function/procedure in inline with block Procedures in the WITH Clause

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.