万事开头难,先走出第一步,并作为备忘录:
--创建第一个简单的存储过程
create or replace procedure proc_001demo
(
param001 in number,
param002 out varchar2
) as
var001 integer :=0;
var002 number(20,6) := 20.06;
begin
DBMS_OUTPUT.put_line('The param is : '||param001||', and var001 is : '||var001||', and var002 is : '||var002);
param002 := 'The param is : '||param001||', and var001 is : '||var001||', and var002 is : '||var002;
end proc_001demo;
--在PL/SQL调用存储过程
declare
a varchar2(100);
begin
proc_001demo(1, a);
DBMS_OUTPUT.put_line(a);
end;
会输出2条打印语句:
The param is : 1, and var001 is : 0, and var002 is : 20.06
The param is : 1, and var001 is : 0, and var002 is : 20.06
第一条是存储过程打印的,
第二条是参数a(out)的值。
如果声明a时,长度不够长,例如 a varchar2(5),会抛错!