标签:
1.一般过程
create or replace procedure p1
as
begin
dbms_output.put_line(‘Hello World‘);
end;
--调用
call p1();
2.接收参数
create or replace procedure p2
(p_name varchar,p_age in int)
as
v_id int;
begin
select max(id) into v_id from stud;
v_id := v_id + 1;
insert into stud values(v_id,p_name,p_age);
end;
--调用:
call p2(‘Alex‘,56);
3.输出类型的参数
create or replace procedure p3
(p_name varchar,p_age in int,v_id out int,v_cnt out int)
as
begin
select max(id) into v_id from stud;
v_id := v_id + 1;
--写入数据
select count(*) into v_cnt from stud;
end;
--调用拥有返回值的必须用一个PL/SQL块
declare
vid int;
vcnt int;
begin
p3(‘Jerry‘,25,vid,vcnt);
dbms_output.put_line(‘id is:‘ || vid || ‘数量:‘ || vcnt);
end;
4.输入与输出是同一个变量
create or replace procedure p4
(p_name varchar,p_age in out int,v_cnt out int)
as
v_id int;
begin
select max(id) into v_id from stud;
v_id := v_id + 1;
--写入数据
insert into stud values(v_id,P_name,p_age);
--再设置p_age的值为id的值
p_age := v_id;
--查询表中的行数
select count(*) into v_cnt from stud;
end;
--调用
declare
vid int := 99;
vcnt int;
begin
p4(‘Sam‘,vid,vcnt);
dbms_output.put_line(‘id is:‘ || vid || ‘数量:‘ || vcnt);
end;
标签:
原文地址:http://www.cnblogs.com/trister/p/4623055.html