Oracle 包練習

來源:互聯網
上載者:User

標籤:sam   實現   package   函數   put   line   weight   rac   roc   

 1 /* 2 建立一個程式包,包裡面實現如下功能 3 1:構建一個過程,根據使用者傳入的最低工資計算出emp表中 4   低於最低工資的人數及這些人員資訊 5 2:構建一個函數,根據傳入的年月,計算該日期入職 6   員工的人數 7 */ 8  9 --包規範10 create or replace package emp_controller11 as12        --建立一個ref遊標13        type emplist is ref cursor return emp%rowtype;14 15        procedure check_sal_less(v_min number,v_count out number,v_emplist out emplist);16        17        function count_same_year_emp(v_year number) return number;18        19 end;20 21 --包主體22 create or replace package body emp_controller23 as24        --實現過程25        procedure check_sal_less(v_min number,v_count out number,v_emplist out emplist)26        as27        begin28            --根據傳入的最低工資,計算出表中低於最低工資的人數29            select count(*) into v_count from myemp30            where sal < v_min;31            32            --將工資低於最低工資的人存放到遊標中33            --開啟遊標34            open v_emplist for select * from myemp35            where sal < v_min;36        end;37        38        --實現函數39        function count_same_year_emp(v_year number) return number40        as41            v_number number;42        begin43            --根據傳入的年份來統計該年份入職的員工數量44            select count(*) into v_number from myemp45            where to_char(hiredate,‘yyyy‘) = v_year;46            47            return v_number;48        end;49 end;50 51 52 --包程式測試53 declare54     v_count number;55     v_emp emp_controller.emplist;56     v_e myemp%rowtype;57 begin58     --根據傳入的最低工資,計算出表中低於最低工資的人數59     emp_controller.check_sal_less(2000,v_count,v_emp);60     dbms_output.put_line(‘低於最低工資2000的人數有:‘||v_count||‘,分別是:‘);61     loop62       fetch v_emp into v_e;63       exit when v_emp%notfound;64       dbms_output.put_line(‘姓名:‘||v_e.ename||‘,薪水:‘||v_e.sal);65       dbms_output.put_line(‘---------------------------------------‘);66     end loop;67 end;68 69 --包測試70 declare71     v_number number;72 begin73     --輸出測試,直接調用函數,輸出傳回值74     dbms_output.put_line(emp_controller.count_same_year_emp(‘1981‘));75 end;

 

Oracle 包練習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.