Procedure with an unknown name or amounts of bind variables.
CodesMar 5 2013 — edited Mar 6 2013Hey Gurus,
Hopefully somebody out there can point me in the right direction.
I'm writing a PL/SQL function that receives an unknown number of bind variables from the client.
I'm using Apex Listener 1.1 to configure a RESTful resource template for a POST x-www-form-urlencoded body.
If the client POSTs the following body: *"title=Mr.&fname=John&lname=Smith"*
My PL/SQL procedure automatically receives the bind variables passed to it with the following:
:title := 'Mr.';
:fname := 'John';
:lname := 'Smith';
Now my limitation is that the required design uses metadata to define the end user data's structure.
So in reality the POST Bodies I receive look more like this: *"120=Mr.&121=John&122=Smith"*
Therefore my PL/SQL procedure receives:
:120 := 'Mr.';
:121 := 'John';
:122 := 'Smith';
I can query the metadata tables to anticipate which bind variables may be present at runtime,
but this can change based on the resource ID passed along with the POST body at the time of request.
My first attempt was to loop the anticipated items and run an EXECUTE IMMEDIATE kind of like:
for c_record_items in
(select field_id from tfields where record_id = :id) loop
EXECUTE IMMEDIATE 'begin update_item('||:field_id||', :'||field_id||'); end;';
end loop;
But unfortunately the EXECUTE IMMEDIATE fails because the bind variable isn't declared; it requires the USING clause.
Which I cannot think I can code the amount or the value into...
I started to dabble in the DBMS_SQL package but I have yet to think of a way I can overcome this problem.
Are there any experts out there who can point me in right direction?
Much appreciated.
Edited by: Codes on Mar 5, 2013 5:11 PM
Edited by: Codes on Mar 5, 2013 5:13 PM