有一組數據,如果我想更新其中的第n條,該怎麼寫?

sjun66 2004-01-15 10:14:27
根據一個條件查出一個表中有n條數據,
我想更新其中第三條怎麼寫?
...全文
33 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
beckhambobo 2004-01-19
  • 打赏
  • 举报
回复
update table1 set (col1, col2, col3)=( Select col1,col2,col3 from from table2 where table1.id=table2.id where rownum <2
) where rownum <= 3;
sjun66 2004-01-18
  • 打赏
  • 举报
回复
第三条只是一个例子,按顺序排列

to BlueSuperMan:
update tables set col3=.....
where rownum=3

to leecooper:
update table1 set col1= ..., col2= ..., col3=...
( Select * from (select p.*, rownum rnum
from (select * from table1) p where rownum <4
) where rnum >= 3
这句里面where 怎么写?
如update table1 set col1=...
where col1='123'
and ???;
and后面用ROWNUM是错的,用条件去查询的时候ROWNUM除了=1之外,不能等于其他

sjun66 2004-01-18
  • 打赏
  • 举报
回复
这个问题还是没有解决,不过程序开发是完成了,因为换了一种方式实现。

to leecooper:
也许是我孤陋寡闻,我知道insert into table1 ( Select * from
(select p.*, rownum rnum
from (select * from table1) p where rownum <4
) where rnum >= 3
这样是可以的,但是update没有试过。
beckhambobo 2004-01-16
  • 打赏
  • 举报
回复
怎么叫其中三条,是什概念?
随机?
顺序?
qiansl 2004-01-16
  • 打赏
  • 举报
回复
UP: BlueSuperMan(耀舞飞扬)
legumer 2004-01-16
  • 打赏
  • 举报
回复
where rownum=3?这也可以的啊。

BlueSuperMan 2004-01-16
  • 打赏
  • 举报
回复
update tables set col3=.....
where rownum=3
leecooper0918 2004-01-15
  • 打赏
  • 举报
回复

我想更新其中第三條怎麼寫
------------------------

你这里说的"第三条"具体是个什么概念? 我理解为按一定的排序
规则筛选出来的,既然你能定义这个规则,就照着这个规则去update

假如按照ronum排序:

update table1 set col1= ..., col2= ..., col3=...
( Select * from (select p.*, rownum rnum
from (select * from table1) p where rownum <4
) where rnum >= 3

17,086

社区成员

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

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