跪求:oracle如何在数据分组后更新(update)?求大神指导啊~~~万分感谢

luoyg1004 2014-07-23 09:06:33
如题:org_info 表内容如下:
ID NAME TEL ADDR OP_TYPE OCCUR_DATE
1001 aaa 888888 ppppppp 2014-07-23
1001 aaa 999999 ppppppp 2011-03-19
1002 bbb 666666 yyyyyyy 2014-09-15
1002 ipow 221 fghfghfh 2009-07-08
1002 ipow 221 iyyiwqwe 2006-02-24
1002 bbb 666666 yyyyyyy 2001-05-12

update (select row_number() over(partition by id order by occur_date ASC) RN,
oi.* from org_info oi) aa
set aa.op_type = 1 where aa.RN = 1
数据库报错:
ORA-01732: 此视图的数据操纵操作非法

请问这为什么错?如果不能这样写,那么用什么方式还能实现此功能呢?谢谢~~~~
(希望实现按照ID分组,取出日期最小的那条记录,将他字段OP_TYPE更新为1,求指导啊~~~)
...全文
444 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
luoyg1004 2014-07-26
  • 打赏
  • 举报
回复
引用 3 楼 z_shousi 的回复:
楼上的方法可行。先找到满足要求的数据的rowid,再用in批量update。 update org_info set op_type = 1 where rowid in ( select rid from (select rowid rid, row_number() over(partition by id order by occur_date ASC) RN from org_info oi) where rn = 1 )
都是高手,果然可以啊,解了我的燃眉之急 谢谢
luoyg1004 2014-07-26
  • 打赏
  • 举报
回复
引用 1 楼 bw555 的回复:
update org_info set op_type = 1
where rowid in (select recordid from (select rowid recordid,row_number() over(partition by id order by occur_date ASC) RN
                                                       from org_info) 
                            where  RN = 1 )
果然是大神,谢谢,不错
  • 打赏
  • 举报
回复
楼上的方法可行。先找到满足要求的数据的rowid,再用in批量update。 update org_info set op_type = 1 where rowid in ( select rid from (select rowid rid, row_number() over(partition by id order by occur_date ASC) RN from org_info oi) where rn = 1 )
bw555 2014-07-23
  • 打赏
  • 举报
回复
你需要更新的是表中的数据,而不是你select语句查询出来的视图
bw555 2014-07-23
  • 打赏
  • 举报
回复
update org_info set op_type = 1
where rowid in (select recordid from (select rowid recordid,row_number() over(partition by id order by occur_date ASC) RN
                                                       from org_info) 
                            where  RN = 1 )

17,082

社区成员

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

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