我想达到这效果,执行update语句时,需要的才更新,一段一段‘SET  。。’加上去。。不知道我的思路是否正确
但是这样执行了没有反映。create or replace
procedure p_updatetinitems1(i_iid TINITEMS.IID%type default 'IID',i_gid VARCHAR2 default 'GID',i_iprice NUMBER default 0,i_inum NUMBER default 0,
i_IIre VARCHAR2 default 'R')
as
v_sql varchar2(2000);
v_gmaxstocks tgoods.gmaxstocks%type;
v_goodstocks tgoods.gstocks%type;
v_inum tinitems.inum%type;
kkk int;
begin
v_sql:='update TINITEMS ';
select count(*) into kkk from tinitems where gid=i_gid;
if kkk=0 then
dbms_output.put_line('没有GID');
else
select gmaxstocks,gstocks into v_gmaxstocks,v_goodstocks from tGoods where gid=i_gid;
select inum into v_inum from tinitems where iid=i_iid; 
if  v_goodstocks-v_inum+i_inum<v_gmaxstocks  then
dbms_output.put_line('超出最大库存');
else
if i_iprice!=0 then
v_sql:=v_sql||'set IPRICE='||i_iprice;
elsif i_iire!='R' then
v_sql:=v_sql||', IIREMARK='||i_iire;
elsif i_inum!=0 then
v_sql:=v_sql||', INUM='||i_inum;
end if;
v_sql:=v_sql||' where iid='||i_iid;
execute Immediate v_sql;
end if;
end if;
exception 
 when others then
    dbms_output.put_line(sqlerrm);
end;

解决方案 »

  1.   

    我想或者是execute Immediate 句子的问题,需要用USING 提供参数这样的话又要用IF判断拼接了几段set语句 然后提供相应的参数么?
      

  2.   

    程序经常用这办法。。
    oracle怎么做这个事的。
      

  3.   

    别急着execute Immediate v_sql
    动态语句拼的过程中很容易出错,先将拼好的语句输出检查一下
    dbms_output.put_line(v_sql);
    比较容易找出问题所在