「在程序單元ORDERTOTAL中定義的本地子程序」是正確的,因爲問題是「這個代碼將從幾個地方調用」。換句話說,我們有像
create function foo
return number
is
v_one number := 200;
v_two number := 10;
begin
v_one := some complex math operation;
-- some other code
v_two := the same complex math operation;
-- etc..
end;
/
所以單元保存重複的是數學運算(這是溶液你的在函數本身碼gave..a塊,根據需要重複),我們可以這樣做:
create function foo
return number
is
v_one number := 200;
v_two number := 10;
function calc_math(p_var number)
return number
is
begin
return complex math operation;
end calc_math;
begin
v_one := calc_math(v_one);
-- some other code
v_two := calc_math(v_two);
-- etc..
end;
/
因此避免代碼重複。
過程或函數可以有其自己的本地過程和函數。 – 2013-03-26 12:12:42