当前位置: 代码迷 >> Oracle开发 >> 动态存储过程,不知道哪里错了
  详细解决方案

动态存储过程,不知道哪里错了

热度:26   发布时间:2016-04-24 06:36:48.0
动态存储过程,不知道哪儿错了
create or replace procedure merge_rio
is
v_itm varchar2(100);
v_sql varchar2(500);
v_sql1 varchar2(500);
i number;
begin
        for i in 1..9 loop
             v_itm:='C000'||i
             v_sql:='merge into tmp_whq_rio_data_test a using (select * from tmp_whq_rio where itemcode='''||v_itm||''') b on (a.storecode=b.storecode) when matched then update set a.'||v_itm||'1=b.有无铺货,a.'||v_itm||'2=b.单价 ';
                         execute immediate v_sql;
       end loop;
             i:=10;
             for i in 10..25 loop
                     v_itm:='C00'||i
                   v_sql1:='merge into tmp_whq_rio_data_test a using (select * from tmp_whq_rio where itemcode='''||v_itm||''') b on (a.storecode=b.storecode) when matched then update set a.'||v_itm||'1=b.有无铺货, a.'||v_itm||'2=b.单价 ';
             execute immediate v_sql1;
       end loop;
       exception
   when no_data_found then  --直接抛出异常
     dbms_output.put_line('不存在该工资值的雇员');
   when too_many_rows then
     dbms_output.put_line('存在多个雇员具有该工资');
   when others then
     rollback;
     dbms_output.put_line('异常回滚退出');
end merge_rio;
------解决思路----------------------
貌似就丢了2个分号 两个给 v_itm赋值的语句的最后
procedure merge_rio
is
v_itm varchar2(100);
v_sql varchar2(500);
v_sql1 varchar2(500);
i number;
begin
        for i in 1..9 loop
             v_itm:='C000'
------解决思路----------------------
i;
             v_sql:='merge into tmp_whq_rio_data_test a using (select * from tmp_whq_rio where itemcode='''
------解决思路----------------------
v_itm
------解决思路----------------------
''') b on (a.storecode=b.storecode) when matched then update set a.'
------解决思路----------------------
v_itm
------解决思路----------------------
'1=b.有无铺货,a.'
------解决思路----------------------
v_itm
------解决思路----------------------
'2=b.单价 ';
                         execute immediate v_sql;
       end loop;
             i:=10;
             for i in 10..25 loop
                     v_itm:='C00'
------解决思路----------------------
i;
                   v_sql1:='merge into tmp_whq_rio_data_test a using (select * from tmp_whq_rio where itemcode='''
------解决思路----------------------
v_itm
------解决思路----------------------
''') b on (a.storecode=b.storecode) when matched then update set a.'
------解决思路----------------------
v_itm
------解决思路----------------------
'1=b.有无铺货, a.'
------解决思路----------------------
v_itm
------解决思路----------------------
'2=b.单价 ';
             execute immediate v_sql1;
       end loop;
       exception
   when no_data_found then  --直接抛出异常
     dbms_output.put_line('不存在该工资值的雇员');
   when too_many_rows then
     dbms_output.put_line('存在多个雇员具有该工资');
   when others then
     rollback;
     dbms_output.put_line('异常回滚退出');
  相关解决方案