当前位置:首页 » 存储配置 » oracle存储过程循环插入

oracle存储过程循环插入

发布时间: 2022-11-26 23:22:50

⑴ oracle存储过程用fetch循环实现向一张表中插入不同数据

创建测试表

sql">createtabletest
(touch_idvarchar2(20),
party_idvarchar2(20));

执行过程

declare
v_idint;
begin
v_id:=1;
whilev_id<=10--这个10设置为插入的次数
loop
insertintotestvalues('张三'||v_id,'partyid'||v_id);
v_id:=v_id+1;
endloop;
commit;
end;

结果

⑵ 写一段创建oracle存储过程的代码,并将1至10个数循环插入表A(ID,NAME)的NAME字段

v_name integer;
begin
v_name:=1;
while v_name<=10 loop
begin
insert into table(id,name) values(seq.nextval,v_name);
v_name=v_name+1;
end;
end loop;
===========
主题程序就是这样。

⑶ oracle循环存储过程方法怎么写,每条数据不一样

方法1:用游标可以解决呀!给你个例子。
FOR c IN (SELECT DISTINCT wdd.organization_id,
wdd.ship_from_location_id,
wdd.ship_to_location_id,
wdd.customer_id,
wdd.freight_terms_code,
wdd.fob_code,
wdd.source_header_id,
wdd.source_header_type_id
FROM wsh_delivery_details wdd
WHERE wdd.released_status IN ('R', 'B')
AND wdd.inventory_item_id IN
(SELECT DISTINCT mln.inventory_item_id
FROM bs_edi_shipment_ge bes,
mtl_lot_numbers_all_v mln
WHERE mln.lot_number = bes.lot_number
AND bes.header_id = l_header_id)) LOOP
INSERT INTO Document VALUES(c.organization_id,
c.ship_from_location_id,
c.ship_to_location_id,
c.customer_id,
c.freight_terms_code,
c.fob_code,
c.source_header_id,
c.source_header_type_id);
END LOOP;
将游标里面的数据一条一条的插入到你想插入到的表。

方法2:还有一种方法,定义一个表类型的记录,将所有数据插入到这个表类型记录集中,然后再一次性插入到表中。

⑷ oracle 存储过程循环插入数据不定时出现卡死,求高手指点,循环过程如下:

感觉对日期的处理问题,你将日期类型转换为字符串类型再比较,这里不建议转,直接比较吧。

⑸ 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存储过程循环插数据

有以下几个步骤。
在表account中循环插入数据,id从1001到1005。createor
replace
procere
test
is--存储过程,名称为test。v_id
int;
--声明变量。begin。v_id
:=1001;
--ACCOUNT_ID从1001插到1005。while
v_id
<=1005--设置插入的次数。loop。

⑺ oracle存储过程循环执行SQL语句

实现方式错了,批量移动数据应该使用Cursor,而不是像分页那样每次都查询。
每次都查询可能会导致重复数据。
正确方式应该是打开一个Cursor,循环Cursor来插入,使用计数器来控制每次COMMIT的行数:
declare
TYPE R_CURSOR IS REF CURSOR;
i number;
a1_cursor R_CURSOR;
a1_row A1%ROWTYPE;
begin
open a1_cursor FOR
select ID, NAME from A1;
i := 0;
loop
fetch a1_cursor
into a1_row;
exit when a1_cursor%notfound;
INSERT INTO A2 VALUES a1_row;
i := i + 1;
if i >= 5 then
commit;
i := 0;
end if;
end loop;
close a1_cursor;
commit;
end;

⑻ oracle 用存储过程向表插入数据的问题

实际上存储过程向表中插入数据和sql执行的区别是不大的,只不过是存储过程是用loop等循环插入,之后顺序执行sql语句,不用命令行执行。

_data_4_pressure_3
is

--Result1VARCHAR2(50);
VAR_numnumber;
begin
VAR_num:=1;

while
VAR_num<1000000
LOOP
insertintorp_trans_log_day
(trans_time,
trans_province,
trans_type,
score_range,
rule_name,
trans_num)
selectto_date('2013/10/29','yyyy-mm-dd'),
round(dbms_random.value(1,300))||'省',
round(dbms_random.value(1,800))||'类型',
round(dbms_random.value(1,100))||'风险分值',
round(dbms_random.value(1,300))||'规则名称',
'1'
fromal;
commit;
VAR_num:=VAR_num+1;
<ahref="https://www..com/s?wd=end&tn=44039180_cpr&fenlei=-bIi4WUvYETgN-"target="_blank"class="-highlight">end</a>loop;

<ahref="https://www..com/s?wd=end&tn=44039180_cpr&fenlei=-bIi4WUvYETgN-"target="_blank"class="-highlight">end</a>insert_data_4_pressure_3;

⑼ oracle存储过程中循环for in是如何使用的

1、首先编写存储过程的整体结构,如下图所示定义变量。

⑽ oracle存储过程循环怎么写

Oracle中有三种循环(For、While、Loop):
1、loop循环:

createorreplaceprocerepro_test_loopis
inumber;
begin
i:=0;
loop
i:=i+1;
dbms_output.put_line(i);
ifi>5then
exit;
endif;
endloop;
endpro_test_loop;


2、while循环:

createorreplaceprocerepro_test_loopis
inumber;
begin
i:=0;
whilei<5loop
i:=i+1;
dbms_output.put_line(i);
endloop;
endpro_test_loop;


3、for循环1:

createorreplaceprocerepro_test_foris
inumber;
begin
i:=0;
foriin1..5loop
dbms_output.put_line(i);
endloop;
endpro_test_for;

4、for循环2:

createorreplaceprocerepro_test_cursoris
userRowt_user%rowtype;
cursoruserRowsis
select*fromt_user;
begin
foruserRowinuserRowsloop
dbms_output.put_line(userRow.Id||','||userRow.Name||','||userRows%rowcount);
endloop;
endpro_test_cursor;
热点内容
两台服务器如何建立双向连接 发布:2025-07-27 23:18:26 浏览:146
河间压缩机 发布:2025-07-27 23:13:39 浏览:983
客户ip服务器连接不上 发布:2025-07-27 23:05:33 浏览:352
读写分离java 发布:2025-07-27 23:05:29 浏览:89
pythonjson乱码 发布:2025-07-27 23:04:33 浏览:249
des算法代码c语言 发布:2025-07-27 22:58:08 浏览:116
android运行时 发布:2025-07-27 22:39:21 浏览:957
音频剪辑需要哪些配置 发布:2025-07-27 22:38:26 浏览:463
小盒编程下载 发布:2025-07-27 22:22:53 浏览:415
c语言统计数字字符个数 发布:2025-07-27 22:22:09 浏览:832