为什么rownum between 2 and 10的时候,无法打印数据呢?
如果是rownum between 1 and 10就可以create or replace procedure print_t_time(a in number)
as
cursor cur is
select * from
(select * from t_time order by id)
where rownum between 2 and 10;
v_time t_time%rowtype;
begin
open cur;
loop
fetch cur into v_time;
if cur%found = true then
dbms_output.put_line('id:' || v_time.id || ',time:' || v_time.time);
end if;
exit when cur%notfound;
end loop;
close cur;
end;
还有在游标中,也无法使用这样的格式,求原理 cursor cur is
select * from
(select t.*, rownum r from t_time t)
where rownum between 2 and 10;
如果是rownum between 1 and 10就可以create or replace procedure print_t_time(a in number)
as
cursor cur is
select * from
(select * from t_time order by id)
where rownum between 2 and 10;
v_time t_time%rowtype;
begin
open cur;
loop
fetch cur into v_time;
if cur%found = true then
dbms_output.put_line('id:' || v_time.id || ',time:' || v_time.time);
end if;
exit when cur%notfound;
end loop;
close cur;
end;
还有在游标中,也无法使用这样的格式,求原理 cursor cur is
select * from
(select t.*, rownum r from t_time t)
where rownum between 2 and 10;
改下试试:
cursor cur is
select * from
(select t.*, rownum r from t_time t)
where r between 2 and 10; --改用别名r存储过程里也改下试试
rownum 用别名
没用别名是我的笔误,以下是代码create or replace procedure print_t_time(a in number)
as
cursor cur is
select * from
(select t.*, rownum r from t_time t)
where r between 1 and 10;
v_time t_time%rowtype;
begin
open cur;
loop
fetch cur into v_time;
if cur%found = true then
dbms_output.put_line('id:' || v_time.id || ',time:' || v_time.time);
end if;
exit when cur%notfound;
end loop;
close cur;
end;
--此兄回答的为正解,因此你必须用别名,另外用别名依然报错的原因为:
v_time t_time%rowtype; --v_time 为行记录类型(注意没有包含rownum)
fetch cur into v_time; --这里你直接把右边数据into 到v_timecursor cur is
select * from --注意这里的[*] 包含下面的 [r],在这里将t表字段列出即可。
(select t.*, rownum r from t_time t)
where r between 1 and 10;
[code]
v_time t_time%rowtype; --v_time 为行记录类型(注意没有包含rownum)
fetch cur into v_time; --这里你直接把右边数据into 到v_time
赋值有问题