Create or replace function 函数名
(
v_参数名 in 参数类型,--------输入参数
v_参数名 out 参数类型 -------输出参数
) ----定义形式参数 不需要给参数尺寸
return 返回数据类型 ------ 不需要定义参数尺寸
is ------定义变量
v_参数名 数据类型以及尺寸;
Begin ---- 逻辑处理
Select ..... into 定义的参数 (只能给出参赋值 或者变量)
From.....
Where ..... ;
Return 定义的参数 ;
End;
注意:没有参数时 在创建函数存储时 不要写括号
Create or replace function 函数名 return is begin end;
调用存储函数
Declare
定义被调用的函数中需要的输入/输出参数/接受结果 需要定义尺寸
Begin
v_res:=函数名(入参,....,出参1,....,出参n);
Dbms_output.put_line(输出结果) ---- 只能输出一个字段 有多个时需要连接符
End;