createorreplaceprocedure raise_salary
(p_id in emp_empno%type)--相当于形参isbeginupdate emp set sal=sal+500where empno=p_id;end;--调用存储过程1begin
raise_salary(2296);--调用存储过程时给参数赋值end;--调用过程2declare
v_empno emp.empno%type:=2296;begin
raise_salary(v_empno);end;
二、out参数
createorreplaceprocedure raise_salary1
(
p_id in emp.empno%type,--入参
p_name out emp.ename%type,--出参
p_sal out emp.sal%type--出参)isbeginselect ename,sal into p_name,p_sal
from emp
where empno=p_id;--入参,和数据库中的值匹配end;--调用存储过程declare
v_name emp.ename%type;
v_sal emp.sal%type;begin
raise_salary1(2296,v_name,v_sal);
dbms_output.put_line(v_name||' '||v_sal);end;
三、in out参数:既可以作为入参也可以作为出参
createorreplaceprocedure raise_salary2
(
p_id in emp.empno%type,
p_name out emp.ename%type,
p_sal inout emp.sal%type)isbeginupdate emp set sal = sal+p_sal --p_sal作为入参使用where empno=p_id;select ename,sal into p_name,p_sal --p_sal作为出参使用from emp
where empno=p_id;end;--调用存储过程declare
v_empno emp.empno%type:=2296;
v_name emp.ename%type;
v_sal emp.sal%type:=500;begin
raise_salary2(v_empno,v_name,v_sal);
dbms_output.put_line(v_name||' '||v_sal);end;
四、处理异常
createorreplaceprocedure raise_exception
(
p_id out emp.empno%type)isbeginselect empno into p_id
from emp
where empno =99;--异常处理
exception
when no_data_found then
dbms_output.put_line('没有数据输出');end;--调用存储过程declare
v_empno emp.empno%type;begin
raise_exception(v_empno);
dbms_output.put_line(v_empno);end;