create or replace procedure p1
--or replace代表创建该存储过程时,若存储名存在,则替换原存储过程,重新创建
--无参数列表时,不需要写()
as
begin
dbms_output.put_line('hello world');
end;
begin
p1();
end;
create or replace procedure p2
(name in varchar2,age int,msg out varchar2)
--参数列表中,声明变量类型时切记不能写大小,只写类型名即可,例如参数列表中的name变量的声明
--参数列表中,输入参数用in表示,输出参数用out表示,不写时默认为输入参数。
------------输入参数不能携带值出去,输出参数不能携带值进来,当既想携带值进来,又想携带值出去,可以用in out
as
begin
msg:='姓名'||name||',年龄'||age;
--赋值时除了可以使用:=,还可以用into来实现
--上面子句等价于select '姓名'||name||',年龄'||age into msg from dual;
end;
--执行存储过程
declare
msg varchar2(100); --有返回参数时,需要通过declare声明变量进行接收。
begin
p2('张三',23,msg);
dbms_output.put_line(msg);
end;