请帮忙看一个遍历sql

[复制链接]
查看11 | 回复3 | 2009-1-4 14:52:28 | 显示全部楼层 |阅读模式
SUKER@primary>select * from a;
ID NAME
---------- --------------------------
1 aaa
SUKER@primary>truncate table sqlsave;
表被截断。
执行循环,把a中的内容存入表sqlsave。
declare
ss varchar2(1000);
type c1 is ref cursor;
a_cursor c1;
begin
open a_cursor for
select name from a;
loop
fetch a_cursor into ss;
insert into sqlsave values (ss);
exit when a_cursor%notfound;
end loop;
close a_cursor;
end;
/
查看导入的结果,为什么会多出一行呢?
SUKER@primary>select * from sqlsave;
SQL_TEXT
---------------------------------------
aaa
aaa
是哪里做错?请帮忙指点,多谢!
回复

使用道具 举报

千问 | 2009-1-4 14:52:28 | 显示全部楼层
begin
open a_cursor for
select name from a;
fetch a_cursor into ss;
while a_cursor%found
loop
insert into sqlsave values (ss);
fetch a_cursor into ss;
end loop;
close a_cursor;
end;
/
回复

使用道具 举报

千问 | 2009-1-4 14:52:28 | 显示全部楼层
谢谢shandyyang
回复

使用道具 举报

千问 | 2009-1-4 14:52:28 | 显示全部楼层
exit when a_cursor%notfound;
放在insert前面
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行