標籤:
--函數的建立create function func1(dno number)return NUMBER--必須帶有傳回值is v_max number;--定義傳回值 begin select max(sal) into v_max--賦值 from emp where deptno= dno; RETURN v_max;--返回 end;--函數的調用,只能是運算式的一部分,不能單獨調用 select * from emp where sal= func1(10); ------------------------------------------------------------------------------- --建立過程存在則替換,帶輸出參數 create or replace procedure proc1(dno in number,maxsal out number) is v_maxsal number; begin select max(sal) into v_maxsal from emp where deptno= dno; maxsal := v_maxsal;--給輸出參數賦值 dbms_output.put_line(v_maxsal);--列印 end; --調用過程 declare maxsal number; begin proc1(10,maxsal); dbms_output.put_line(maxsal); end;--------------------------------------------------------------------------------/* 建立返回多行的預存程序*/create or REPLACE procedure proc_testisbegin DECLARE cursor cc is SELECT * from emp;--這裡定義一個遊標集合變數cc begin for r in cc loop--對遊標cc進行遍曆 dbms_output.put_line(r.ename || ‘:‘ || r.sal); end loop;--結束遍曆 end; end; ---調用 begin proc_test(); end;
1.函數必須是和語句一起執行,不能被單獨執行,必須有傳回值。
2預存程序 可以被單獨執行,沒有傳回值。
Oracle procedure/function