plsql中,select coloumn into var ,如果没有select出来,程序还让他继续往下执行,

[复制链接]
查看11 | 回复3 | 2008-1-2 17:35:53 | 显示全部楼层 |阅读模式
我用一个select语句去出一列的值,只有一个值,我把他into 到一个变量里,就是这样:select name into test_name from table_name where id = 1;这里id是主键,我想判断一下是否取出值了,如果有的话,继续执行,没有的话,把test_name :='no value' ,但是我看只有
在异常处理的时候用no_data_found来处理,那是只能在程序的最后,我想问,如果在程序中判断该怎么判断?

---------------很菜的问题,谢谢回答!
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
中间同样也是使用exception。
即:
begin
...
begin
select name into test_name from table_name where id = 1;
exception
when others then
test_name := 'no value' ;
end;
...
end;
/
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
你是不是在要判断的地方有嵌入了begin 和end?
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
OK!测试成功!谢谢JAUNT
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行