日期:2014-05-16 浏览次数:20503 次
create or replace procedure update_emp_sal(Name in out type, Name in out type, ...) isbegin end update_emp_sal;
create or replace procedure update_emp(v_empno varchar2,v_ename varchar2) isbeginupdate emp set ename=v_ename where empno=v_empno; end update_emp;
SQL>exec update_emp('7935','test');2、有返回值的存储过程
create or replace procedure emp_out_sal ( v_empno in varchar2, v_sal out number ) is vsal number(7,2); begin select sal into vsal from emp where empno=v_empno; v_sal:=vsal; end;
SQL> var vsal numberSQL> exec emp_out_sal('7935',:vsal);PL/SQL procedure successfully completedvsal---------700SQL> var vsal numberSQL> call emp_out_sal('7935',:vsal);Method calledvsal---------700二、Oracle创建函数(function)
create or replace function (Name in type, Name in type, ...) return number is Result number;begin return (Result);end ;
create or replace function ret_emp_sal(v_ename varchar2)return numberisv_sal number(7,2);beginselect nvl(sal,0) into v_sal from emp where lower(ename)=lower(v_ename);return v_sal;end;
SQL> var vsla numberSQL> call ret_emp_sal('7935') into :vsal;Method calledvsal---------700
create package emp_pkg is procedure emp_update_ename(v_empno varchar2,v_ename varchar2); function emp_get_sal(v_empno varchar2) return number; end;
create or replace package body emp_pkgis procedure emp_update_ename ( v_empno varchar2, v_ename varchar2 ) is vename varchar2(32); begin update emp set ename=v_ename where empno=v_empno; commit; select ename into vename from emp where empno=v_empno; dbms_output.put_line('雇员名称:'||vename); end; function emp_get_sal ( v_empno varchar2 ) return number is vsal number(7,2); begin select sal into vsal from emp where empno=v_empno; return vsal; end;end;
SQL> var vsla numberSQL> call emp_pkg.emp_get_sal('7935') into :vsal;Method calledvsal---------700SQL> exec emp_pkg.emp_update_ename('7935','helong');雇员名称:helongSQL> call emp_pkg.emp_update_ename('7935','helong');Method calledSQL> select * from dual;DUMMY-----X雇员名称:helong