1

I have to write a generic plsql function which is supposed to submit any concurrent request. For example, If the concurrent program has 5 parameters my function also should take 5 parameters as input. Like wise if the concurrent program has n number of parameters my function should take n number of input parameters. Can this be achieved? Please suggest the best way.

I tried manually with If statements like IF no of program parameters = 5, API should submit for the 5 input arguments only. But I know this is not the best way as we don't know which program end user may submit and how many parameters it has.

1 Answer 1

3

You can create a function that has multiple parameters and set them to "default null". Then just check if they are null or not.

Something like

function test(p1 in varchar2 default null, p2 in varchar2 default null, p3 in varchar2 default null, p4 in varchar2 default null, p5 in varchar2 default null, p6 in varchar2 default null, p7 in varchar2 default null, p8 in varchar2 default null, p9 in varchar2 default null, p10 in varchar2 default null, etc..) return number is
begin
  if p1 is not null then
  .....
  end if;
end test;

Or you can make the function accept an array, like.

create function test(p_args in sys.dbms_sql.varchar2_table) return number is
begin
  for i in 1..p_args.count loop
    ....
  end loop;
end test;

Or for a bit more flexibility have it accept a JSON array, that way you can pass a mixed use of scalar types.

create function test(p_jarr in json_array_t) return number is
begin
  for i in 0..p_jarr.get_size-1 loop
    if p_jarr.get_type(i) = 'SCALAR' and p_jarr.get(i).is_string then
      // do something with string
    end if;
    if p_jarr.get_type(i) = 'SCALAR' and p_jarr.get(i).is_number then
      // do something with number
    end if;
  end loop;
end test;
// check for boolean, date, timestamp, 

Regards

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

1 Comment

Thanks a lot for the response. I will try these options and let you know.

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.