1: 函数的创建
create or replace function test_function_name
return varchar2 as
begin
return ‘ hell0 wuxu_nanjing’ ;
end test_function_name ;
对于函数的创建语句格式很简单,必须指定一个名字,必须有返回值,相比存储过程,函数是必须有返回值的,但是存储过程则不需要
对于函数名称,在使用函数的时候,会进程定义变成, 要保障函数名称和变量名称不能相同
2: 带参数的函数
create or replace function test_function_name (salary number)
return numer as
begin
declare test_salary number ;
begin
test_salary := salary - 500 ;
return test_salary ;
end ;
end ;test_function_name
3 函数的确定性 deterministic (用于指定新建函数为确定函数) ,确定性会很大程度提高数据库性能, oracle在调用函数时,会查找以前是否使用过相同参数,如果查到
那就直接返回之前查询的结果
create or replace function test_function_name (salary number)
return numer
deterministic
as
begin
declare test_salary number ;
begin
test_salary := salary - 500 ;
return test_salary ;
end ;
end ;test_function_name