在plsql中,存储过程中的out模式的参数可以用来返回数据,相当于函数的返回值。下面是一个小例子。
沿用上一篇的emp表结构和数据。
存储过程如下:
create or replace procedure out_test(v_user in emp.user_name%type,
v_salary out emp.salary%type,
v_deptno out emp.emp_deptno%type) as
begin
select salary, emp_deptno
into v_salary, v_deptno
from emp
where user_name = v_user;
exception
when NO_DATA_FOUND then
dbms_output.put_line('No data found');
when TOO_MANY_ROWS then
dbms_output.put_line('Too many rows found');
end out_test;
在命令行中调用该存储过程,利用绑定变量
SQL> var v_user varchar2(20); SQL> var v_salary number; SQL> var v_deptno number; SQL> exec :v_user := 'Lisi'; PL/SQL procedure successfully completed v_user --------- Lisi SQL> exec out_test(:v_user, :v_salary, :v_deptno); PL/SQL procedure successfully completed v_user --------- Lisi v_salary --------- 11500 v_deptno --------- 20
这是在plsql developer下运行的结果,这个工具是一个很好的oracle的可视化编程工具。
转载自:https://www.cnblogs.com/bejour/p/3375104.html

posted on
浙公网安备 33010602011771号