建表 插入数据
create table test(
id number primary key,
name varchar2(10));insert into test test values(1,'1');
insert into test test values(2,'2');
insert into test test values(3,'3');
insert into test test values(4,'4');
insert into test test values(5,'5');编程:
declare
type t_emp is table of test%rowtype index by binary_integer;
v_cnt binary_integer := 1;
v_emp t_emp;
begin
loop
select *
into v_emp(v_cnt)
from test
where id = v_cnt;
dbms_output.put_line(v_emp(v_cnt).name);
v_cnt := v_cnt + 1;
exit when v_cnt >=3 ;
end loop;
while v_cnt <> 0 loop
dbms_output.put_line(v_cnt);
dbms_output.put_line(v_emp(v_cnt).name);--在sql窗口显示这里有错
v_cnt := v_cnt -1; --命令窗口显示这里有错
end loop;
end;错误信息
sql窗口报的错
ORA-01403: 未找到数据
ORA-06512: 在 line 17
命令窗口报的错
ORA-01403: 未找到数据
ORA-06512: 在 line 18
create table test(
id number primary key,
name varchar2(10));insert into test test values(1,'1');
insert into test test values(2,'2');
insert into test test values(3,'3');
insert into test test values(4,'4');
insert into test test values(5,'5');编程:
declare
type t_emp is table of test%rowtype index by binary_integer;
v_cnt binary_integer := 1;
v_emp t_emp;
begin
loop
select *
into v_emp(v_cnt)
from test
where id = v_cnt;
dbms_output.put_line(v_emp(v_cnt).name);
v_cnt := v_cnt + 1;
exit when v_cnt >=3 ;
end loop;
while v_cnt <> 0 loop
dbms_output.put_line(v_cnt);
dbms_output.put_line(v_emp(v_cnt).name);--在sql窗口显示这里有错
v_cnt := v_cnt -1; --命令窗口显示这里有错
end loop;
end;错误信息
sql窗口报的错
ORA-01403: 未找到数据
ORA-06512: 在 line 17
命令窗口报的错
ORA-01403: 未找到数据
ORA-06512: 在 line 18
解决方案 »
- Oracle查询问题
- (ora-06502 pl sql 数字或值错误 字符串缓冲区太小)(ORA-03127 no new operations allowed until ..)
- oracle 7.3 连接时 提示ora-00604 ora-00376 ora-01110(问题紧急,高手请联系,酬谢!)
- 求一条sql语句,不用存储过程
- oracle备份表问题?(多谢!oracle新手)
- 一个新手的问题?
- oracle中如何创建自己的方案
- 紧急:ORACLE817不能安装于XEON的问题。在线等待。
- 怎么会是这种结果?
- 各位大虾,请问怎么在proc 调用存储过程
- 如何得到SQL语句执行时间
- perl连接oracle中文乱码
into v_emp(v_cnt)
from test
where id = v_cnt; 这里加begin...exception...end试一下
exit when v_cnt >=3 ;
end loop;
while v_cnt <> 0 loop
dbms_output.put_line(v_cnt);
dbms_output.put_line(v_emp(v_cnt).name);--在sql窗口显示这里有错你这里的v_cnt+1了,所以dbms_output.put_line(v_emp(v_cnt).name)这里是找不到数据的。
如果修改为:
declare
type t_emp is table of test%rowtype index by binary_integer;
v_cnt binary_integer := 1;
v_emp t_emp;
begin
loop
select *
into v_emp(v_cnt)
from test
where id = v_cnt;
dbms_output.put_line(v_emp(v_cnt).name);
v_cnt := v_cnt + 1;
exit when v_cnt >=3 ;
end loop;
v_cnt:=v_cnt-1;
while v_cnt <> 0 loop
dbms_output.put_line(v_cnt);
dbms_output.put_line(v_emp(v_cnt).name);--在sql窗口显示这里有错
v_cnt := v_cnt -1; --命令窗口显示这里有错
end loop;
end; 这样就可以执行通过了