oracle问题求教

以下有三道题目:
利用rownum方法删除指定行

删除m行到n行的记录

在无限多的数据中,删除第m行n列的数值,然后在该位置添加数值。
这些题目据说是面试题,我没做出来。哪位高手来帮一下?

先建一张表,简单插入30条记录:

此时表中有三十条记录。


假设我要删除rownum所指定的10 到20 行,使用如下语句:

delete from king where  rowid in (select rid from(select id,name,rownum no,rowid rid from king where rownum <=20)where no >=10);

commit;

查看数据:发现其中对应数据已经被删除



简单说明下,对于rownum的使用,你不可以直接指定大于1的数字来使用,你需要利用子查询获得一个包含1的区间,然后根据需要再获得你想得到区间范围。比如,你想查询rownum10到20的数据:

select * from(select id,name,rownum no from king where rownum <=20)where no >=10


对于利用rownum来进行update,delete时,使用rowid这个伪列来操作可以很方便。

追问

delete from king where rowid in (select rid from(select id,name,rownum no,rowid rid from king where rownum =10);
commit;
经验证不能运行。怎么回事?

追答

报什么错?
你检查下是否写的正确吧,程序应该没问题。我自己都跑了一遍,不会凭空捏造出来。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-07-09
1、delete from table where rownum=m;
2、delete from table where rownum>=m and rownum<=n;
3、update table set column=2222 where rownum=m;
相似回答