查看: 11298|回复: 10

[PL/SQL] where current of 的一个问题

[复制链接]
论坛徽章:
1
2008新春纪念徽章
日期:2008-02-13 12:43:03
跳转到指定楼层
1#
发表于 2008-2-4 16:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
create or replace procedure COEX is
  v_curbal number(19,2);
  v_lentdt varchar2(8);
  flag1 varchar2(1);
  flag2 varchar2(1);

cursor sou_inst is
  select sou.flag,list.flag,sou.depbal_d,sou.lentdt from coex_trd_term_list list,coex_sou_nacs_d sou
    where list.flag!='S'
      and list.orgid=sou.orgid
      and list.cust_code=sou.cust_code
      and list.apcode=sou.apcode
      and list.curcde=sou.curcde
      and list.pro_pk=sou.pro_pk
      and list.papcde=sou.papcde
        for update;

begin

  open sou_inst;
    loop
    fetch sou_inst into flag1,flag2,v_curbal,v_lentdt;
    exit when sou_inst %notfound;
      update coex_sou_nacs_d
        set flag='1'
          where current of sou_inst;

    end loop;
  close sou_inst;
  commit;

end COEX;

红字部分没用效果,请问是那里有问题?
论坛徽章:
1
2008新春纪念徽章
日期:2008-02-13 12:43:03
2#
 楼主| 发表于 2008-2-4 17:51 | 只看该作者
问题出在这一行
        for update;
我原来的写法是
        for update of list.flag,sou.flag;
我发现如果 for update of 后面是两张表的话(就象上面用了 list 和 sou),后面的
      update coex_sou_nacs_d
        set flag='1'
          where current of sou_inst;
就无效。

如果 for update of 后面是一张表,如: for update of list.flag,list.abc ,就有效。

请那位出来帮帮忙,是什么原因,或者如何来改写?

使用道具 举报

回复
论坛徽章:
176
迷宫蛋
日期:2013-07-25 13:20:24奥迪
日期:2013-12-12 13:35:05林肯
日期:2013-12-25 17:20:27本田
日期:2013-12-30 13:00:37马自达
日期:2014-02-11 16:03:42林肯
日期:2014-02-12 13:22:43三菱
日期:2014-02-14 15:58:312014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:02日产
日期:2014-02-19 10:52:50
3#
发表于 2008-2-5 10:02 | 只看该作者
...

[ 本帖最后由 flaming_tower 于 2008-2-5 12:16 编辑 ]

使用道具 举报

回复
论坛徽章:
176
迷宫蛋
日期:2013-07-25 13:20:24奥迪
日期:2013-12-12 13:35:05林肯
日期:2013-12-25 17:20:27本田
日期:2013-12-30 13:00:37马自达
日期:2014-02-11 16:03:42林肯
日期:2014-02-12 13:22:43三菱
日期:2014-02-14 15:58:312014年新春福章
日期:2014-02-18 16:42:02马上有房
日期:2014-02-18 16:42:02日产
日期:2014-02-19 10:52:50
4#
发表于 2008-2-5 10:09 | 只看该作者
...

使用道具 举报

回复
论坛徽章:
10
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44祖国60周年纪念徽章
日期:2009-10-09 08:28:002009新春纪念徽章
日期:2009-01-04 14:52:28奥运会纪念徽章:沙滩排球
日期:2008-10-24 13:14:46奥运会纪念徽章:举重
日期:2008-08-09 07:34:41奥运会纪念徽章:沙滩排球
日期:2008-07-27 20:48:01奥运会纪念徽章:皮划艇激流回旋
日期:2008-07-22 19:31:45奥运会纪念徽章:拳击
日期:2008-07-19 16:09:472008新春纪念徽章
日期:2008-02-13 12:43:032010年世界杯参赛球队:斯洛伐克
日期:2010-06-13 00:10:04
5#
发表于 2008-2-5 12:20 | 只看该作者
???

使用道具 举报

回复
论坛徽章:
1
2008新春纪念徽章
日期:2008-02-13 12:43:03
6#
 楼主| 发表于 2008-2-7 20:28 | 只看该作者
楼上的版主发的什么?

where current of sou_inst;

是的,我实验过了,where current of 后面可以指定一张表(仅限于一张表)的字段。

where current of sou.XXX,sou.XXX  可以
where current of sou.XXX,list.XXX  不可以(sou,list是两张表)

--------------------------------------------------

后来找到另一个方法 update多张表 来代替(仅满足我的要求)

可是有谁告诉一下我,上面 where current of 只能指定一张表是怎么回是?我用的 oracle 9,是否版本问题?

[ 本帖最后由 米弗 于 2008-2-13 08:38 编辑 ]

使用道具 举报

回复
论坛徽章:
3
生肖徽章2007版:鸡
日期:2008-01-02 17:35:53生肖徽章2007版:鼠
日期:2008-01-02 17:35:53ITPUB十周年纪念徽章
日期:2011-11-01 16:20:28
7#
发表于 2009-3-18 11:28 | 只看该作者
我的版本是10.2.0.1.0,情况也和楼主描述的一致.

在<<Pro*C/C++ Programmer's Guide>>文档中有提到:
FOR UPDATE OF的约束:If you use the FOR UPDATE OF clause, you cannot reference multiple tables.

CURRENT OF的约束:Furthermore, you cannot reference multiple tables in an associated FOR UPDATE OF clause, which means that you cannot do joins with the CURRENT OF clause.

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
8#
发表于 2011-2-16 11:37 | 只看该作者
WHERE CURRENT OF 只能用在UPDATE,DELETE中,不能用于SELECT,INSERT中;

cursor cur_name is
     select * from table_name for update;

update table_name set ... where current of cursor;
  delete from table_name    where current of cursor;

这里table_name只能是游标所对应的基表或视图

使用道具 举报

回复
论坛徽章:
1
2012新春纪念徽章
日期:2012-01-04 11:51:22
9#
发表于 2011-11-14 09:24 | 只看该作者
请教一下:

cursor cur_name is
     select * from table_name for update;

update table_name set ... where current of cursor;
  delete from table_name    where current of cursor;
请问红色的FOR UPDATE不写可以吗?

使用道具 举报

回复
论坛徽章:
519
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
10#
发表于 2011-11-15 05:08 | 只看该作者
whlwolf110 发表于 2011-11-14 09:24
请教一下:

cursor cur_name is

一定要写。

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表