0

what can i do if i want to pass insert statement to this function as a parameter and executed it in function and return value

create or replace function new_record (p_name your_table.first_name%type)
    return your_table.id%type
is
    return_value your_table.id%type;
begin
    begin
        insert into your_table (id, first_name)
            values (your_seq.nextval, p_first_name)
        returning id into return_value;
    exception
        when dup_val_on_index then
             return_value := 0;
    end;
    return return_value;
end;
1
  • use dynamic SQL e.g. EXECUTE IMMEDIATE 'INSERT STATEMENT'; Commented Apr 8, 2013 at 9:37

1 Answer 1

1

use "execute immediate" statement:

This is simple example, just execute this sql and you will see how it works:

declare
  p_param   number := 123;
  l_res varchar2(10);
  l_sqltext varchar(100);
begin
  l_sqltext := 'begin select t.dummy into :1 from dual t where 123 = :2; end;';
  execute immediate l_sqltext using out l_res, in p_param;
  dbms_output.put_line(l_res);
end;
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.