日期:2014-05-17  浏览次数:21760 次

oracle 拼接字符串写update语句
我想达到这效果,执行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_IIremark 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_iiremark!='R' then
v_sql:=v_sql||', IIREMARK='||i_iiremark;
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;

------解决方案--------------------
?很少这样做吧,一般都是先取出来,然后更新的时候一起更新进去,还没有见过分段这样更新的方法......
可能我少见多怪了吧