Thanks for the question, Xander.
Asked: December 06, 2016 - 2:33 pm UTC
Last updated: December 08, 2016 - 1:27 pm UTC
Version: Oracle 12c
Viewed 1000+ times
You Asked
Hello, Ask Tom team!
There is my problem.
i have a package procedure with some parameters:
procedure updt(p_col varchar2,p_value clob)
is
v_update_clob clob;
begin
v_update_clob:= 'update table set :p_col=:p_value where cond = ''some_condition'' ';
execute IMMEDIATE v_update_clob using p_col,p_value;
commit;
end updt;
in another procedure I want to send to updt procedure column name and clob variable:
updt('description',v_clob);
But get a errors such as string is too long or incomplete expression, if try rewrite procedure with hardcoding ( means||p_value||) like:
procedure updt(p_col varchar2,p_value clob)
is
begin
execute immediate
'update table set set '||p_key||'='''||p_value_clob||''' where cond = ''some_condition'' ';
commit;
end;
Can I improve this issue without changing of procedure logic?
and Chris said...
You can't bind column names! If you want to dynamically pass the column name, you have to append it into the statement. Do this and your clob should work fine:
create table t (
x clob
);
insert into t values ('blah');
commit;
select * from t;
X
blah
create or replace procedure p(col varchar2, val clob) is
stmt clob;
begin
stmt := 'update t set ' || col || ' = :val';
execute immediate stmt using val;
end p;
/
declare
l clob;
begin
dbms_lob.createtemporary(l, true);
for i in 1 .. 10 loop
dbms_lob.writeappend(l, 1000, rpad('x', 1000, 'x'));
end loop;
p('x', l);
end;
/
select length(x) from t;
LENGTH(X)
10,000
Rating
(2 ratings)
Is this answer out of date? If it is, please let us know via a Comment