oracle存储过程记录

oracle存储过程,记一下
建立游标查询A表,循环查询的数据处理后保存b表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
CREATE OR REPLACE PROCEDURE CREATE_VIEW(acton in varchar2,acton2 in varchar2,acton3 in varchar2)
as
--建立游标
CURSOR cur_netnode(Aacton in varchar2,Aacton3 in varchar2)
IS
SELECT * FROM tmp_fetch_data where no1 =Aacton and no2 in (select regexp_substr(Aacton3, '[^,]+', 1, level) as split_result from dual connect by level <= length(Aacton3) -length(replace(Aacton3, ',')) + 1;)WHERE code IS NOT NULL; --游标sql
v_user cur_netnode%rowtype; --定义的行变量,用于接收游标中的数据
BEGIN
OPEN cur_netnode(acton,acton3);--打开游标
loop --循环开始
fetch cur_netnode into v_user; --从游标中提取数据
exit when cur_netnode%notfound;--判断是游标中是否存在数据,不存在退出循环
---id=时间戳+查询id部分
insert into tmp_data2('id','name','age')
values((sysdate -to_date('1970-01-01 08:00:00', 'yyyy-mm-dd hh24:mi:ss')) * 86400000 + substr(v_user.id,10),v_user.name,v_user.age);
END loop; ---结束循环
close cur_netnode; --关闭游标
END;