17,075
社区成员
发帖
与我相关
我的任务
分享
修剪下,增加明白性
create or replace function getAddress(v_ID IN VARCHAR2) return varchar2
as
v_address varchar2(100);
begin
select address into v_address from a where a.id=v_ID;
if v_v_address is nulll then
select address into v_address from b where b.id=v_ID;
end if;
return v_address;
end;
1:
create or replace function getAddress(ID IN VARCHAR2) return varchar2
as
v_address varchar2(100);
begin
select address into v_address from a where a.id=id;
if v_v_address is nulll then
select address into v_address from b where b.id=id;
end if;
return v_address;
end;
2:
第二个问题是function和procedure结束时我看有时写 end; 有时候写 end [function name or procedure name];
没区别吧?
没什么区别 单独的过程或者函数都一样 ,没什么区别
不过在包体中最好还是
end [function name or procedure name],这样可以增加 易读性,明白了事。
Create Or Replace Function Getaddress(In_Id In Int) Return Varchar2 Is
Result integer;
Begin
Begin
Select Address Into Result From a Where Id = Id;
Exception
When No_Data_Found Then
Begin
Select Address Into Result From b Where Id = Id;
Exception
When No_Data_Found Then
Result := -1;
When Others Then
Raise;
End;
When Others Then
Raise;
End;
Return(Result);
End Getaddress;
function getAddress(ID IN VARCHAR2)
return varchar2 is
v_result varchar2(50);
as
select address
into v_result
from a
where id=ID;
if v_result is null then
select address
into v_result
from b
where id=ID;
end if;
return v_result;
exception
when NO_DATA_FOUND then
v_result := -1;
when others then
DBMS_OUTPUT.PUT_LINE('在FN_GET_TAX_GB过程中出错!'||v_result);
end;