當前位置:首頁 » 存儲配置 » oracle帶游標的存儲過程

oracle帶游標的存儲過程

發布時間: 2023-09-04 22:08:14

Ⅰ Oracle存儲過程游標for循環怎麼寫

舉例回答:

案例:

sql">--For循環游標
--(1)定義游標
--(2)定義游標變數
--(3)使用for循環來使用這個游標
declare
--類型定義
cursorc_job
is
selectempno,ename,job,sal
fromemp
wherejob='MANAGER';
--定義一個游標變數v_cinfoc_emp%ROWTYPE,該類型為游標c_emp中的一行數據類型
c_rowc_job%rowtype;
begin
forc_rowinc_jobloop
dbms_output.put_line(c_row.empno||'-'||c_row.ename||'-'||c_row.job||'-'||c_row.sal);
endloop;
end;

Ⅱ oracle存儲過程中打開游標有幾種方法用open直接打開

兩種方法
1.聲明游標時寫好SELECT語句,如
CURSOR r_cur1 IS select *** from tableName where 條件;
使用時
OPEN r_cur1;
LOOP
FETCH *** INTO variable;
EXIT WHEN r_cur1%NOTFOUND OR r_cur1%NOTFOUND IS NULL;
。。。
2.聲明游標
ccc sys_refcursor;
使用時
open ccc for select dept_code,dept_name from comm.dept_dict;
loop
fetch ccc into aa,bb;
exit when ccc%notfound;
。。。
end loop;
close ccc;

Ⅲ oracle在存儲過程中定義游標

createtableemp
(idvarchar2(10),
namevarchar2(20),
sexnumber,
tyvarchar2(20)
);

insertintoempvalues('001','Tom',1,'gcs');
insertintoempvalues('002','John',1,'dba');
insertintoempvalues('003','Jean',0,'gcs');
insertintoempvalues('004','Reid',1,'gcs');
commit;


createorreplaceprocerepro6as

cursorcris
select*
fromemp
wheresex=1
andty='gcs';
begin
forcr_resultincrloop
begin
dbms_output.put_line('ID:'||cr_result.id||'NAME:'||
cr_result.name);

end;
endloop;
endpro6;

Ⅳ oracle存儲過程游標問題,多層循環游標,插入中間表

以hr用戶下的employees、departments、locations這三張表為列,sin1得到的是雇員的全名和對應的部門id,並將該部門的id作為sin2查詢時的條件,sin2得到的是該部門id所對應的部門名和對應的位置id,並將該位置id作為sin3查詢使得條件,最後sin3得到的就是該位置id所應得城市,並且在sin3這個循環里將sin1里雇員的全名,sin2里的部門名以及sin3里的city作為一條記錄插入到sin_insert表裡.
附上代碼:
first:
create table sin_insert(full_name varchar2(50),department_name varchar2(30),city
varchar2(30));

then:
create or replace procere testloop
as
begin
for sin1 in (select first_name||last_name full_name,department_id from
employees) loop
for sin2 in (select department_name,location_id from departments where
department_id=sin1.department_id) loop
for sin3 in (select city from locations where
location_id=sin2.location_id) loop
insert into sin_insert values
(sin1.full_name,sin2.department_name,sin3.city);
end loop;
end loop;
end loop;
end;

Ⅳ oracle存儲過程游標問題

fetch mycur into yang_02;
把游標mycur 所提取的數據yang_02變數

熱點內容
新聞訪問類型 發布:2025-08-28 14:22:25 瀏覽:937
從零基礎學習編程 發布:2025-08-28 13:57:34 瀏覽:381
資料庫在國外 發布:2025-08-28 13:42:53 瀏覽:891
androiddialog創建 發布:2025-08-28 13:09:26 瀏覽:950
初級伺服器是指什麼 發布:2025-08-28 13:08:39 瀏覽:100
微軟dns伺服器地址 發布:2025-08-28 13:07:20 瀏覽:607
2013款榮放頂配有哪些配置 發布:2025-08-28 13:05:32 瀏覽:667
dedecmssql注入漏洞 發布:2025-08-28 12:54:27 瀏覽:397
dash官網搭建伺服器 發布:2025-08-28 12:45:17 瀏覽:746
html上傳圖片模板 發布:2025-08-28 12:41:30 瀏覽:999