存储过程

yundeweilai 2014-05-19 10:46:42
create or replace procedure whq_henkel
is
cursor cur_whq(vv_itemcode in varchar2) is select store_id from tmp_whq_henkel_godeep where itemcode=vv_itemcode and wt03>0;
begin
for i in 2..9 loop
for cur_whq_v1 in cur_whq('K00'||i) loop
update tmp_whq_henkel_godeep set 'whq'||i=1 where store_id=cur_whq_v1.store_id and itemcode='K001';
end loop;
end loop;
end ;

第一行第七列有错
...全文
144 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
CT_LXL 2014-05-19
  • 打赏
  • 举报
回复
引用 2 楼 yundeweilai 的回复:
[quote=引用 1 楼 zlloct 的回复:] [quote=引用 楼主 yundeweilai 的回复:] create or replace procedure whq_henkel is cursor cur_whq(vv_itemcode in varchar2) is select store_id from tmp_whq_henkel_godeep where itemcode=vv_itemcode and wt03>0; begin for i in 2..9 loop for cur_whq_v1 in cur_whq('K00'||i) loop update tmp_whq_henkel_godeep set 'whq'||i=1 where store_id=cur_whq_v1.store_id and itemcode='K001'; end loop; end loop; end ; 第一行第七列有错
列名在哪里? 'whq'||i=1 i是number型,最好用TO_CHAR转换一下[/quote] ‘whq’||i 就是列名,由于列名是随着i 的值变化的。是不是这样的写法不行啊[/quote] 这样肯定不行啊,除非你用动态SQL
yundeweilai 2014-05-19
  • 打赏
  • 举报
回复
引用 1 楼 zlloct 的回复:
[quote=引用 楼主 yundeweilai 的回复:] create or replace procedure whq_henkel is cursor cur_whq(vv_itemcode in varchar2) is select store_id from tmp_whq_henkel_godeep where itemcode=vv_itemcode and wt03>0; begin for i in 2..9 loop for cur_whq_v1 in cur_whq('K00'||i) loop update tmp_whq_henkel_godeep set 'whq'||i=1 where store_id=cur_whq_v1.store_id and itemcode='K001'; end loop; end loop; end ; 第一行第七列有错
列名在哪里? 'whq'||i=1 i是number型,最好用TO_CHAR转换一下[/quote] ‘whq’||i 就是列名,由于列名是随着i 的值变化的。是不是这样的写法不行啊
CT_LXL 2014-05-19
  • 打赏
  • 举报
回复
引用 楼主 yundeweilai 的回复:
create or replace procedure whq_henkel is cursor cur_whq(vv_itemcode in varchar2) is select store_id from tmp_whq_henkel_godeep where itemcode=vv_itemcode and wt03>0; begin for i in 2..9 loop for cur_whq_v1 in cur_whq('K00'||i) loop update tmp_whq_henkel_godeep set 'whq'||i=1 where store_id=cur_whq_v1.store_id and itemcode='K001'; end loop; end loop; end ; 第一行第七列有错
列名在哪里? 'whq'||i=1 i是number型,最好用TO_CHAR转换一下
CT_LXL 2014-05-19
  • 打赏
  • 举报
回复
引用 4 楼 yundeweilai 的回复:
[quote=引用 3 楼 zlloct 的回复:] [quote=引用 2 楼 yundeweilai 的回复:] [quote=引用 1 楼 zlloct 的回复:] [quote=引用 楼主 yundeweilai 的回复:] create or replace procedure whq_henkel is cursor cur_whq(vv_itemcode in varchar2) is select store_id from tmp_whq_henkel_godeep where itemcode=vv_itemcode and wt03>0; begin for i in 2..9 loop for cur_whq_v1 in cur_whq('K00'||i) loop update tmp_whq_henkel_godeep set 'whq'||i=1 where store_id=cur_whq_v1.store_id and itemcode='K001'; end loop; end loop; end ; 第一行第七列有错
列名在哪里? 'whq'||i=1 i是number型,最好用TO_CHAR转换一下[/quote] ‘whq’||i 就是列名,由于列名是随着i 的值变化的。是不是这样的写法不行啊[/quote] 这样肯定不行啊,除非你用动态SQL[/quote] 也就是列名变化不行,但是列的值变化可以的事吗?[/quote] 列名可以变化,用动态SQL,如下:

create or replace procedure whq_henkel is
  cursor cur_whq(vv_itemcode in varchar2) is
    select store_id
      from tmp_whq_henkel_godeep
     where itemcode = vv_itemcode
       and wt03 > 0;
  str      varchar2(2000);
  l_result varchar2(1000);
begin
  for i in 2 .. 9 loop
    for cur_whq_v1 in cur_whq('K00' || i) loop
      str := 'update tmp_whq_henkel_godeep set whq' || to_char(i) || '=1 ' ||
             'where store_id =' || cur_whq_v1.store_id ||
             ' and itemcode = ''K001''';
      execute immediate str;
    end loop;
  end loop;
  commit;
end;
yundeweilai 2014-05-19
  • 打赏
  • 举报
回复
引用 3 楼 zlloct 的回复:
[quote=引用 2 楼 yundeweilai 的回复:] [quote=引用 1 楼 zlloct 的回复:] [quote=引用 楼主 yundeweilai 的回复:] create or replace procedure whq_henkel is cursor cur_whq(vv_itemcode in varchar2) is select store_id from tmp_whq_henkel_godeep where itemcode=vv_itemcode and wt03>0; begin for i in 2..9 loop for cur_whq_v1 in cur_whq('K00'||i) loop update tmp_whq_henkel_godeep set 'whq'||i=1 where store_id=cur_whq_v1.store_id and itemcode='K001'; end loop; end loop; end ; 第一行第七列有错
列名在哪里? 'whq'||i=1 i是number型,最好用TO_CHAR转换一下[/quote] ‘whq’||i 就是列名,由于列名是随着i 的值变化的。是不是这样的写法不行啊[/quote] 这样肯定不行啊,除非你用动态SQL[/quote] 也就是列名变化不行,但是列的值变化可以的事吗?

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧