关于select 赋值的问题!很简单的

liulovetoo 2006-10-15 04:14:29
现在学oracle有点搞不懂
比如
declare fir_n varchar2(20);
begin
select cust_first_name into fir_n
from oe.customers where oe.customers.customer_id=1470;--没有1470这个id
dbms_output.put_line(fir_n);
end;
如果是mssql fir_n这个变量就为空呀 但是oracle会出异常,oracle中有没有不报错的写法??
...全文
711 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
maguang54 2007-01-06
  • 打赏
  • 举报
回复
加个异常就不会报错了
declare
fir_n varchar2(20);
begin
select cust_first_name into fir_n
from oe.customers where oe.customers.customer_id=1470;--没有1470这个id
dbms_output.put_line(fir_n);
exception
when NO_DATA_FOUND then
dbms_output.put_fine('出错');

end;
maguang54 2007-01-06
  • 打赏
  • 举报
回复
加个异常就不会报错了
declare
fir_n varchar2(20);
begin
select cust_first_name into fir_n
from oe.customers where oe.customers.customer_id=1470;--没有1470这个id
dbms_output.put_line(fir_n);

end;
sten 2007-01-06
  • 打赏
  • 举报
回复
加个异常,单步跟一下看看就知道了
kasoo 2007-01-06
  • 打赏
  • 举报
回复
我也是刚学oracle,这个问题是够让人烦的
用update或delete语句时,如果要操作的内容不存在不会报错,
可以在下面用sql%notfound来判断操作的内容存不存在

但就是select的时候就会出现异常.
lujianjian970531 2006-10-19
  • 打赏
  • 举报
回复
declare fir_n varchar2(20);
cursor cur_first_name is
select cust_first_name
from oe.customers where oe.customers.customer_id=1470;
begin
open cur_first_name;
fetch cur_first_name into fir_n;
if (cur_first_name%NOTFOUND) then
fir_n := null;
end if;
close cur_first_name;
end;
lujianjian970531 2006-10-19
  • 打赏
  • 举报
回复
也可以用游标来实现
wangzk0206 2006-10-18
  • 打赏
  • 举报
回复
可以在NO_DATA_FOUND中处理 或是可以先用select count() from 表
然后用if来判断这样就可以消除查不出记录了呀
ptpa 2006-10-18
  • 打赏
  • 举报
回复
declare fir_n varchar2(20);
begin
select cust_first_name into fir_n
from oe.customers where oe.customers.customer_id=1470;--没有1470这个id
dbms_output.put_line(fir_n);
exception
when no_data_found then
dbms_output.put_line("errr");
when others then
dbms_output.put_line("dddddd");

end;
Eric_1999 2006-10-15
  • 打赏
  • 举报
回复
可以自己添加异常处理。
excetion

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧