Oracle procedure/function

來源:互聯網
上載者:User

標籤:

--函數的建立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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.