create or replace function f_test1(h in varchar2) return varchar2
as
begin
--- h:=2;
dbms_output.enable(buffer_size=>null);
dbms_output.put_line(h);
return h;
end;
select f_test1(4) from dual;
2)、out参数类型:表示参数在函数中被赋值,可以传给函数调用程序,该参数只能用于赋值,不能用于传值。
eg:
create or replace function f_test3 (h varchar2,b out varchar2) return varchar2
as
begin
b:=h+10;
--- dbms_output.put_line(b);
return h;
end;
.....调用......
declare
v_1 varchar2(10);
v_2 varchar2(10);
begin
v_1:=f_test3(10,v_2);
dbms_output.put_line(v_1);
dbms_output.put_line(v_2);
end;
3)、in out参数类型:表示参数既可以传值,也可以被赋值。
create or replace function f_test2(h in out varchar2) return varchar2
as
begin
h:=2;
dbms_output.enable(buffer_size=>null);
dbms_output.put_line(h);
return h;
end;
declare
v_1 varchar2(10):=‘4‘;
begin
v_1:=f_test2(v_1);
end;
(说明:带out参数的字定义函数不能用于 SQL语句,只能在PL/SQL程序里)
示例部分:
1.function 调用function
create or replace function f_test4 (h varchar2) return varchar2
as
g varchar2(10);
f varchar2(10);
j varchar2(10);
begin
g:=f_test3(h,f);
j:=h+f;
return j;
end;
select f_test4(10) from dual;
2.取权利人姓名:
create or replace function f_get_qlr (v_slbh varchar2) return varchar2
as
v_qlr varchar2(50);
begin
for i in (select q.* from dj_qlrgl gl inner join dj_qlr q on gl.qlrid=q.qlrid where gl.qlrlx=‘权利人‘ and gl.slbh=v_slbh) loop
v_qlr:=v_qlr||i.qlrmc||‘、‘;
end loop;
return substr(v_qlr,0,instr(v_qlr,‘、‘,-1)-1);
---return v_qlr;
end;
by wolihaito 2018.02.20
原文地址:http://blog.51cto.com/wolihaito/2089209