我的表(tbl_cus)字段是id,cusname,phone,state。谁能帮我写个insert的存储过程?每500条提交一次。谢谢大家了!
解决方案 »
- 执行完毕, 但带有警告
- OracleDBConsoleorcl服务不能启动
- 查询某张表前25%的数据
- oracle 10g下的账户老是自动转为lock(timed)状态
- 访问另一个用的表的问题
- 请教:Delphi7.0,Oracle10, ADO连接,问题如下:主从表关系,当删除主表记录时,对应的从表记录没有删除,是什么原因?记得以前MSSQL时没
- oracle8连接时出现问题,不知道你们预见过吗
- 在SQL*PLUS而不是SQL*PLUS SHEET中要怎样执行本地脚本?
- 那里有关于ORACLE8I的SQL语法的教材!!
- Oracle连接异常,哪位大神帮忙看看,谢谢~
- 诚恳的请各位大神们进来看看!!!,oracle的语句,不胜感激!
- 一个筛选和排序的小问题
CREATE OR REPLACE TYPE tbl_cus_record_type IS OBJECT(
ID VARCHAR2(20),
cusname VARCHAR2(100),
phone VARCHAR2(20),
state VARCHAR2(2)
);
/CREATE OR REPLACE TYPE tbl_cus_table_type IS TABLE OF tbl_cus_record_type;
/PROCEDURE insert_tbl_cus_proc(info_list IN tbl_cus_table_type
out_message OUT VARCHAR2) IS
BEGIN
FOR i IN info_list.count LOOP
INSERT INTO tbl_cus(ID,cusname,phone,state)
VALUES (info_list(i).id,info_list(i).cusname,info_list(i).phone,info_list(i).state);
IF MOD(i,500) = 0 THEN
COMMIT;
END IF;
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
out_message := 'ERROR!';
ROLLBACK;
END;
/
试一下这样行不行,没测试过哦。
create or replace procedure bulk_insert(in_bulk_count In integer)
is
cursor cur is select * from tbl_cus;
type tbl_b is table of tbl_cus%rowtype index by pls_integer;
v_tbl_b tbl_b;
begin
open cur;
loop
<<bulk_insert>>
exit when cur%notfound;
fetch cur bulk collect into v_tbl_b limit in_bulk_count;
forall i in indices of v_tbl_b save exceptions
insert /*+nologging*/ into a values v_tbl_b(i);
commit;
exception
when others then
null;
end loop bulk_insert;
close cur;
end;执行的时候exec bulk_insert(500);
where rn between i*500+1 and (i+1)*500
如果有数据源批量的,可以这么做吧
out_message OUT VARCHAR2) IS
BEGIN
FOR i IN 1.. info_list.count LOOP
INSERT INTO tbl_cus(ID,cusname,phone,state)
VALUES (info_list(i).id,info_list(i).cusname,info_list(i).phone,info_list(i).state); IF MOD(i,500) = 0 THEN
COMMIT;
END IF;
END LOOP; COMMIT;EXCEPTION
WHEN OTHERS THEN
out_message := 'ERROR!';
ROLLBACK;
END;平时存储过程都是写在包里,忘了加create or replace了;
CREATE OR REPLACE TYPE test_record_type IS OBJECT(
testid VARCHAR2(40),
testname VARCHAR2(10),
testphone VARCHAR2(11),
);CREATE OR REPLACE TYPE test_table_type IS TABLE OF test_record_type;CREATE OR REPLACE PROCEDURE insert_test_proc(info_list IN test_table_type,
out_message OUT VARCHAR2) IS
BEGIN
FOR i IN 1.. info_list.count LOOP
INSERT INTO test(testID,testname,testphone)
VALUES (info_list(i).testid,info_list(i).testname,info_list(i).testphone);
IF MOD(i,500) = 0 THEN
COMMIT;
END IF;
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
out_message := 'ERROR!';
ROLLBACK;
END;
Line: 1
Text: CREATE OR REPLACE PROCEDURE insert_test_proc(info_list IN test_table_type,Error: PL/SQL: Compilation unit analysis terminated
Line: 0
Text: CREATE OR REPLACE PROCEDURE insert_test_proc(info_list IN test_table_type,就是这样USR_CC是数据库的登录名
testid VARCHAR2(40),
testname VARCHAR2(10),
testphone VARCHAR2(11), ----- 这里多了个逗号
);
testid VARCHAR2(40),
testname VARCHAR2(10),
testphone VARCHAR2(11)
);CREATE OR REPLACE TYPE test_table_type IS TABLE OF test_record_type;CREATE OR REPLACE PROCEDURE insert_test_proc(info_list IN test_table_type,
out_message OUT VARCHAR2) IS
BEGIN
FOR i IN 1.. info_list.count LOOP
INSERT INTO test(testID,testname,testphone)
VALUES (info_list(i).testid,info_list(i).testname,info_list(i).testphone);
IF MOD(i,500) = 0 THEN
COMMIT;
END IF;
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
out_message := 'ERROR!';
ROLLBACK;
END;