declare
cursor emp_cur
is select * from emp; --宣告游標
emp_var emp%rowtype; --宣告變數:變數emp_var是表emp的行型別
begin
if emp_cur%isopen then --判斷游標是否開啟
loop
fetch emp_cur into emp_var; --獲取游標資料
exit when emp_cur%notfound; --結束迴圈
dbms_output.put_line(emp_var.empno ||'-'|| emp_var.ename||'-'||emp_var.job||'-'||emp_var.mgr);
--輸出資料
end loop;
else
dbms_output.put_line('游標emp_cur沒有被開啟');
end if;
end;
declare
cursor emp_cur
is select * from emp; --宣告游標
emp_var emp%rowtype; --宣告變數:變數emp_var是表emp的行型別
begin
open emp_cur; --開啟游標
loop
fetch emp_cur into emp_var; --獲取游標資料
if emp_cur%found then
dbms_output.put_line(emp_var.empno ||'-'|| emp_var.ename||'-'||emp_var.job||'-'||emp_var.mgr);
--輸出資料
else
dbms_output.put_line('沒有資料被提取');
exit;
end if;
end loop;
close emp_cur; --關閉資料
end;
declare
cursor emp_cur
is select * from emp; --宣告游標
emp_var emp%rowtype; --宣告變數:變數emp_var是表emp的行型別
begin
open emp_cur; --開啟游標
loop
fetch emp_cur into emp_var; --獲取游標資料
if emp_cur%found then
dbms_output.put_line(emp_var.empno ||'-'|| emp_var.ename||'-'||emp_var.job||'-'||emp_var.mgr);
--輸出資料
dbms_output.put_line('讀取了第'|| emp_cur%rowcount ||'條');
else
dbms_output.put_line('沒有資料被提取');
exit;
end if;
end loop;
close emp_cur; --關閉資料
end;
結果:
7369-smith-clerk-7902
讀取了第1條
7499-allen-salesman-7698
讀取了第2條
7521-ward-salesman-7698
讀取了第3條
7566-jones-manager-7839
讀取了第4條
7654-martin-salesman-7698
讀取了第5條
7698-blake-manager-7839
讀取了第6條
7782-clark-manager-7839
讀取了第7條
7788-scott-analyst-7566
讀取了第8條
7839-king-president-
讀取了第9條
7844-turner-salesman-7698
讀取了第10條
7876-adams-clerk-7788
讀取了第11條
7900-james-clerk-7698
讀取了第12條
7902-ford-analyst-7566
讀取了第13條
7934-miller-clerk-7782
讀取了第14條
沒有資料被提取
declare
cursor emp_cur(deptno_var number)
is select * from emp where deptno=deptno_var; --宣告游標
emp_var emp%rowtype; --宣告變數:變數emp_var是表emp的行型別
begin
open emp_cur(30); --開啟游標
loop
fetch emp_cur into emp_var; --獲取游標資料
exit when emp_cur%notfound; --結束迴圈
dbms_output.put_line(emp_var.empno ||'-'|| emp_var.ename||'-'||emp_var.job||'-'||emp_var.mgr);
--輸出資料
end loop;
close emp_cur; --關閉資料
end;
結果:
7499-allen-salesman-7698
7521-ward-salesman-7698
7654-martin-salesman-7698
7698-blake-manager-7839
7844-turner-salesman-7698
7900-james-clerk-7698
oracle 含參帶游標的儲存過程
系統中有個模組的基礎資料需要導到資料庫,由於資料量比較大,而且 內容分布較凌亂。就先將資料匯入臨時表,然後根據臨時表進行有效的檢索並新增到對應的表中。今天下午寫了個含有引數,帶游標的儲存過程。算是把這個問題給解決了。本人需求大致如下 現有臨時表 sheet1 資料是直接從excel的sheet1中讀...
控制游標的屬性
cursor all scroll 十字箭頭游標 div cursor col resize 水平拖動線游標 div cursor crosshair 十字線游標 div cursor move 移動十字箭頭游標 div cursor help 帶問號的游標 div cursor no drop 禁...
oracle帶游標的儲存過程
create or replace procedure xs test add19 is bachelor edu varchar2 2000 new bachelor edu varchar2 2000 aa varchar2 2000 bb varchar2 2000 edu length in...