oracle function 的简单问题,求教

Vash 2012-12-09 10:50:20
新人请教……
create or replace function f_test1
(i_aa test3.aa%type,
i_bb test3.bb%type
)
return varchar2
is
v_result varchar2(20);
count_1 number;
begin
select t3.cc into v_result from test3 t3
where
t3.aa = i_aa
and t3.bb = i_bb
;
if v_result is null then
return '1010';
end if
;
return v_result;
end f_test1;

想达到的效果是 ,如果t3关联不到数据时,能返回 ‘1010’,
但是实际 上 并没有返回‘1010’;而是 返回了 空。
请问是怎么回事呢?
...全文
79 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Vash 2012-12-09
  • 打赏
  • 举报
回复
这么晚了……先谢过你的回复。马上去试试…… Orz
linwaterbin 2012-12-09
  • 打赏
  • 举报
回复
create or replace function f_test1
(i_aa test3.aa%type,
i_bb test3.bb%type
)
return varchar2
is
v_result varchar2(20);
count_1 number;
begin
  select t3.cc into v_result  from test3 t3
 where
     t3.aa = i_aa
 and t3.bb = i_bb
;
return v_result;
exception 
    when others then
    return '1010';
end f_test1;

u1@EMREP> select * from test3;

        AA         BB         CC
---------- ---------- ----------
                      1          2          3

u1@EMREP> call f_test1(1,1) into :a;

Call completed.

u1@EMREP> print a;

         A
----------
      1010

u1@EMREP> call f_test1(1,2) into :a;

Call completed.

u1@EMREP> print a;

         A
----------
         3

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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