參照變數【PL/SQL】
阿新 • • 發佈:2019-01-09
參照變數是指用於存放數值指標的變數。
1. 遊標變數
-- 輸入部門號,並顯示該部門所有員工的姓名和他的工資 declare --定義遊標型別 type ch_emp_cursor is ref cursor; --定義遊標變數 test_cursor ch_emp_cursor; --定義變數 v_ename emp.ename%type; v_sal emp.sal%type; begin --把test_cursor和一個select結合 open test_cursor for select ename,sal from emp where deptno=&no_; --迴圈取出 loop fetch test_cursor into v_ename,v_sal; --判斷是否test_cursor為空 exit when test_cursor%notfound; dbms_output.put_line('員工的姓名:'||v_ename||',工資:'||v_sal); end loop; --關閉遊標 close test_cursor; end;
2. 物件型別變數