下面的代码就是一个功能,在数据库查询按年龄查询,如果查询到多条数据的话,就引发一个异常,这个没问题,但是如果返回结果不大于1的话,我的else的这个语句总是提示我有错误,错误提示如下:
***************************************************
ERROR 位于第 10 行:
ORA-06550: 第 10 行, 第 1 列:
PLS-00428: 在此 SELECT 语句中缺少 INTO 子句***************************************************
declare
return_res number(4);
in_age number(10);
begin
in_age := &in_age;
select count(*) into return_res from stu where sage=in_age;
if return_res > 1 then
raise too_many_rows;
else
open for select * from stu where sage=in_age;
end if;
exception
when too_many_rows then
dbms_output.put_line('返回多行');
end;
/
***************************************************
ERROR 位于第 10 行:
ORA-06550: 第 10 行, 第 1 列:
PLS-00428: 在此 SELECT 语句中缺少 INTO 子句***************************************************
declare
return_res number(4);
in_age number(10);
begin
in_age := &in_age;
select count(*) into return_res from stu where sage=in_age;
if return_res > 1 then
raise too_many_rows;
else
open for select * from stu where sage=in_age;
end if;
exception
when too_many_rows then
dbms_output.put_line('返回多行');
end;
/
解决方案 »
- dbms_scheduler报错ORA-01438:?求助,求助。。。
- 求SQL语句
- 游标取值精度问题求教
- 高分求
- 在Oracle9i中PRO*C的预编译命令是什么,需要写Makefile文件。(在线等待)
- 请问如何远程连接Oracle??
- 各位老大帮帮忙啊,求最简单的把图片插入oracle的方法!!!!!
- 如何在PL-SQL中使用“TRUNCATE TABLE”语句?
- 请问把information表字段data_sql中的字符%替换成字符串'%'的SQL语句怎么写?
- 最后一位数向前添加0如何处理
- 关于能作replication的方法还有哪些?
- 我在Imp数据的时候,当跑到准备启用约束条件的时候,就挂死了,清高手指点!
declare
return_res number(4);
in_age number(10);TYPE type_cv IS REF CURSOR;
cv_c type_cv;
begin
in_age := &in_age;
select count(*) into return_res from stu where sage=in_age;
if return_res > 1 then
raise too_many_rows;
else
open cv_c for select * from stu where sage=in_age;
end if;
exception
when too_many_rows then
dbms_output.put_line('返回多行');
end;
====>open 后面没cursor