I have some dynamic forms in a .net application. Depending on on the form, the fields in the insert/update will be different. I'm trying to build a dynamic sql statement but the string may be longer than 4000 characters which doesn't work for a string literal, so I'm trying to use bind variables. Since the fields being saved are dynamic I don't know how to handle the USING block. Below is a dumbed down version of what I'm trying to do. You can check out an older question I asked about getting the data out dynamically if it helps explain the dynamic form. collection of records to out sys_refcursor
p.s. I know I could just insert nulls into every placeholder but that means I'd have to update the procedure when I add a field to the table which isn't the way to go.
procedure bindTest(oCur out sys_refcursor)
as
vFirst varchar2(50) := 'Joe';
vMiddle varchar2(50) := 'Vs'
vLast varchar2(50) := 'Volcano';
vVars varchar2(50) := 'vFirst, vLast';
vSql varchar2(1000) := '';
begin
-- This form does not use the middle name so there are only 2 bind vars.
-- The field exists in the table but not in the web form so it would not be passed to the procedure.
-- I've included it here to show data I want to ignore.
-- vVars includes the list of valid fields to save.
-- This would be the sql created by my script.
vSql := 'insert into tbl_users (firstName, lastName) values (:a, :b)';
-- depending on the form, vSql might look like
---- 'insert into tbl_users (firstName, middle, lastName) values (:a,:b,:c)'
---- 'insert into tbl_users (lastName) values (:a)'
---- etc
execute immediate vSql using {what goes here? or how do I handle this?};
-- I understand normally it would be `USING vFirst, vLast` but what about when it's dynamic?
open oCur for
select
ID
, firstName
, lastName
from
tbl_users
where
rownum = 1
order by
id desc;
end bindTest;
insert into tbl_userscould always have placeholders for all the columns and where there are no values, simply passNULLas bind argumentsp.s.line in the OP.CLOBinstead ofVARCHAR2? Also read this oracle-base.com/articles/10g/dbms_assert_10gR2string literal too longit's the same problem demonstrated here dba-oracle.com/t_execute_immediate_large_insert_string.htm