存储函数:有返回值,创建完成后,通过 select function() from dual;执行
语法格式
--函数的声明(有参数的写在小括号里)
create or replace function func_name(v_param varchar2)
--返回值类型
return return_type
is
--块变量、记录类型、游标的声明
begin
--函数体(可以实现增删改查等操作,返回值需要 return)
return 'helloworld'|| v_param;
end;
函数的helloworld:返回一个"helloworld"的字符串
create or replace function hello_func
return varchar2
is
begin
return 'hello world';
end;
- 执行函数
begin
dbms_output.put_line(hello_func());
end;
或
select hello_func() from dual;
过程的helloworld
create or replace procedure hello_world
is
begin
dbms_output.put_line('hello world');
end;
- 执行函数
begin
hello_world3();
end;