MySQL, Oracle及数据库讨论区
Oracle函数问题,报(ORA-01422: 实际返回的行数超出请求的行数
create or replace function get_doctor_groups(cnum in staff_vs_group.EMP_NO%type)
return staff_vs_group.group_class%type as cclass staff_vs_group.group_class%type;
begin
select distinct group_class
into cclass
from staff_vs_group , staff_dict
where staff_vs_group.emp_no = staff_dict.emp_no and rownum=1;
---加上rownum=1就可以了,不加则报出01422的错误,为什么?
return (cclass);
end;
这说明:
1.where staff_vs_group.emp_no = staff_dict.emp_no and rownum=1;
这个符合这个条件的记录不止一行,而且很多行
2.而distinct只能把同一字段相同内容的删掉,不同内容的不会删掉。
3.select into是隐式游标,只能传一个内容进去
4.当加上rownum=1,就是选取了第一行,也就是说只是一行,肯定不会有其他相异的内容。
为了方便大家阅读,我对文章中错误号来解释一下吧!
Error Id
: ORA-01422
Title
: exact fetch returns more than requested number of rows
Description
:
exact fetch returns more than requested number of rows
Action
:
Rewrite the query or change number of rows requested
Cause
:
The number specified in exact fetch is less than the rows returned.
也许你已明白,但对一个人有用也是我存在的理由!^_^ By:持之以恒的大白
-- 来自: