请教一个关于too_many_row和no_data_found问题

[复制链接]
查看11 | 回复9 | 2009-10-9 08:28:00 | 显示全部楼层 |阅读模式
我写了这样一个程序:
declare
v_sal number(9,2);
v_ename varchar2(20);
begin
select ename,sal into v_ename,v_sal from emp where sal=3000;
dbms_output.put_line('姓名:'||v_ename||',工资:'||v_sal);
when no_date_found then
dbms_output.put_line('sal=3000no date found');
when too_many_rows then
dbms_output.put_line('sal=3000 is to many rows');
end;
/
但是执行的时候报错:
SQL> @1
when no_date_found then
*
ERROR at line 14:
ORA-06550: line 14, column 1:
PLS-00103: Encountered the symbol "WHEN" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with

pipe
The symbol "case" was substituted for "WHEN" to continue
ORA-06550: line 18, column 4:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
case
我把when no_data_found和when too_many_rows注销掉就可以执行!
请教那位高手能指点一下我的问题错在哪里?
回复

使用道具 举报

千问 | 2009-10-9 08:28:00 | 显示全部楼层
哪位高手指点一下!谢谢!
回复

使用道具 举报

千问 | 2009-10-9 08:28:00 | 显示全部楼层
在when no_date_found then前加Excepiton 关键字。
begin
....
Excepiton
when .... then
end
唉!
回复

使用道具 举报

千问 | 2009-10-9 08:28:00 | 显示全部楼层
呵呵,你怎么就写了这样一个程序.
回复

使用道具 举报

千问 | 2009-10-9 08:28:00 | 显示全部楼层
我是初学者,水平低
回复

使用道具 举报

千问 | 2009-10-9 08:28:00 | 显示全部楼层
原帖由 kevintenny 于 2008-9-19 01:57 发表
我是初学者,水平低

磨刀不误砍柴工,先看看相关文档
回复

使用道具 举报

千问 | 2009-10-9 08:28:00 | 显示全部楼层
少exceptions 关键字!·
回复

使用道具 举报

千问 | 2009-10-9 08:28:00 | 显示全部楼层
呵呵,你还是把你的select into的语句好好检查一下吧
这个问题还是比较容易的:
too many 说明你的select into 取多了;
no data found 说明 没有取到
回复

使用道具 举报

千问 | 2009-10-9 08:28:00 | 显示全部楼层
原帖由 microsoft_fly 于 2008-9-19 08:53 发表
磨刀不误砍柴工,先看看相关文档

yes,砍柴前,先磨磨刀吧。
回复

使用道具 举报

千问 | 2009-10-9 08:28:00 | 显示全部楼层
no_date_found ???
应该是 no_data_found
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行