參照變量 用于存放數(shù)值指針的變量,通過使用參照變量可以使應(yīng)用程序共享相同對象,從而降低占用的空間可以使用游標變量(ref cursor)和對象類型變量(ref obj_type)兩種參照變量 使用游標時,當定義游標不需要指定相應(yīng)的select語句,但是當使用游標時(open時)需要指定select語句 實例如下:
1.編寫pl/sql塊 可以輸入部門號,并顯示部門所有的員工姓名和工資
declare--定義游標類型sp_emp_cursortype sp_emp_cursor is ref cursor;--定義游標變量emp_cursor sp_emp_cursor;--定義變量v_name emp.name%type;v_sal emp.sal%type;begin--執(zhí)行部分--把emp_cursor和一個select語句結(jié)合open emp_cursor for select name,sal from emp where deptno=&no;--循環(huán)取數(shù)據(jù)loopfetch emp_cursor into v_name,v_sal;--判斷emp_cursor 為空則退出exit when emp_cursor%notfound;dbms_output.put_line('姓名是:'||v_name||'工資是:'||v_sal);end loop;--關(guān)閉游標close emp_cursor;end;/新聞熱點
疑難解答