Create [or replace ] function 函数名
[(参数[{in | out | in out}] 数据类型 ,...... )]
Return 返回类型
[authid {current_user | designer}]
{is | as}
Begin
函数体
End 函数名;
Or replace:如果要创建的函数存在,则先删除此函数,再重建此函数,也就是将撤销和重建这两个步骤合为一步操作。
In | out | in out:参数的模式。
authid curren_user :在调用时, oracle 使用调用该过程的用户权限域执行该过程,此时调用者必须有权限访问存储过程中所涉及到的所有数据库对象的权限。
authid designer :为默认选线, oracle 将使用过程所有者的权限来执行.
-
create function leap_or_common_year
-
(year in integer)
-
return varchar2 is
-
retval varchar2(30);
-
begin
-
if (year mod 400)-0 or ((year mod 100)!=0 and (year mod 4)= 0) then
-
retval:=year ||' is a leap year;';
-
else
-
retval:=year ||'is a common year;';
-
end if
-
return retval;
-
end leap_or_common_year;
-
SQL> set serveroutput on;
-
SQL> declare
-
2 output varchar2(30);
-
3 begin
-
4 output:=leap_or_common_year(2010);
-
5 dbms_output.put_line(output);
-
6 end;
-
7 /
-
2010is a common year;
-
-
PL/SQL 过程已成功完成。
-
SQL> select leap_or_common_year(2012) from dual;
-
-
LEAP_OR_COMMON_YEAR(2012)
-
-------------------------------------------------------------
-
-
2012 is a leap year;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26435490/viewspace-1077860/
,如需转载,请注明出处,否则将追究法律责任。