当前位置:首页 » 存储配置 » 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-07-04 20:42:34 浏览:473
苹果11的摄像头是什么配置 发布:2025-07-04 20:32:20 浏览:59
plc编程入门视频 发布:2025-07-04 20:26:02 浏览:927
小米电视设置界面密码是多少 发布:2025-07-04 20:26:01 浏览:989
linux软件测试 发布:2025-07-04 20:12:40 浏览:274
小数加减法计算法则 发布:2025-07-04 20:11:49 浏览:691
文件如何定时上传至服务器 发布:2025-07-04 20:06:17 浏览:860
菜鸟商城源码 发布:2025-07-04 20:01:31 浏览:446
英雄联盟头像文件夹 发布:2025-07-04 19:49:59 浏览:580
取消电脑连接wifi密码怎么设置密码 发布:2025-07-04 19:31:32 浏览:508