示例代码:
- CREATE OR REPLACE FUNCTION "MY_DATABASE"."F_GET_USER_COUNT_BY_DEPART"
- (
- DEPART_ID_VAL in long
- )
- return varchar2
- is
- USER_STATE varchar(16);
- USER_COUNT number;
- begin
- select count(*) into USER_COUNT from TB_USER_INFO where DEPART_ID=DEPART_ID_VAL;
- if USER_COUNT > 0 then
- USER_STATE:='该部门下有用户';
- else
- USER_STATE:='该部门下无用户';
- end if;
- return (USER_STATE);
- end;
解释:
- CREATE OR REPLACE FUNCTION "数据库名称"."函数名"
- (
- 参数一 [in,out] 类型,
- 参数二 [in,out] 类型,
- ...
- )
- return 返回值类型
- is
- 变量一 类型;
- 变量二 类型;
- ... ;
- begin
- /*给变量赋值的过程*/
- return (变量一或变量二或...);
- end;
例子:
CREATE OR REPLACE FUNCTION getbusinessname(pJBusinessType varchar)
return varchar
is pBusinessTypeName varchar(80);
begin
select TypeName into pBusinessTypeName
from BUSINESS_TYPE
where TypeNo=pJBusinessType;
return pBusinessTypeName;
end;
- 参数有两种类型,in或者out;可以创建不带参数的函数;
- 多个参数之间用“,”隔开;多个变量之间用“;”隔开;