oracle存储过程怎样批量插入新数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle存储过程怎样批量插入新数据相关的知识,希望对你有一定的参考价值。
参考技术A 需要生成的SQLinsert into TMP_UPSTATE_CASEKEY values('TMP0000001', 1, sysdate);
存储过程实现
create or replace procedure proc_casekey_upstate
as
casekey char(14);
begin
for i in 1..10000000 loop
casekey := 'TMP'||lpad(i,7,0); -- TMP0000001
insert into TMP_UPSTATE_CASEKEY values(casekey, 1, sysdate);
end loop;
commit;
end;
begin
proc_casekey_upstate();
end;
测试发现生成一千万条数据用了14分钟左右,性能还是可以了,如果先去掉TMP_NUM_STATUS_ID的外键估计更快。
或者:
insert into TMP_UPSTATE_CASEKEY select 'TMP'||LPAD(rownum,7,0),1,sysdate from dual connect by level <= 1000000; 参考技术B 这里面涉及到字符串的定义,怎么确定字符串?你是指一个单词还是一整行?如果是一整行,只要不断调用fgets函数,返回的就是一行一行的字符串,但是如果是单词的话,就复杂了,需要进行词法分析,据我估计这个题目是指一整行,代码其实很简单:#include <stdio.h>
#define MAX_LINE 1024
char *fname="a.txt";
main()
FILE * f;
char line[MAX_LINE];
int i;
f=fopen(fname,"r");
if(f==NULL)
perror("fopen");
return 1;
i=0;
while(fgets(line,MAX_LINE,f)!=NULL)
printf("%s",line);
i++;
fclose(f);
printf("filename:%s has %d Strings!",fname,i);
Oracle 定时查询数据插入新表中(job+存储过程)
create table EGMAS_COUNT_DATA
(
TIMES date not null,
COUNT NUMBER(30) not null,
SYSTEM_NAME VARCHAR2(30) not null,
Operation_index VARCHAR2(30) not null
);
-- Add comments to the columns
comment on column EGMAS_COUNT_DATA.TIMES
is ‘日期‘;
comment on column EGMAS_COUNT_DATA.COUNT
is ‘统计量‘;
comment on column EGMAS_COUNT_DATA.SYSTEM_NAME
is ‘系统编码‘;
comment on column EGMAS_COUNT_DATA.Operation_index
is ‘业务运营指标名称‘;
存储过程:
create or replace procedure orderCount is
begin
insert into EGMAS_COUNT_DATA(DAY, COUNT,SYSTEM_NAME,Operation_index)
SELECT to_date(to_char(sysdate-1,‘yyyy-MM-dd‘),‘yyyy-MM-dd‘), (select count(1) from T_ORDERS WHERE ORDER_RESOURCE = ‘13‘
AND to_char(CREATED_TM,‘yyyy-MM-dd‘) = to_char(sysdate-1,‘yyyy-MM-dd‘)), ‘EGMAS‘,‘Android手机订单量(港澳台)‘
FROM dual;
insert into EGMAS_COUNT_DATA(DAY, COUNT,SYSTEM_NAME,Operation_index)
SELECT to_date(to_char(sysdate-1,‘yyyy-MM-dd‘),‘yyyy-MM-dd‘), (select count(1) from T_ORDERS WHERE ORDER_RESOURCE = ‘14‘
AND to_char(CREATED_TM,‘yyyy-MM-dd‘) = to_char(sysdate-1,‘yyyy-MM-dd‘)), ‘EGMAS‘,‘IPHONE手机订单量(港澳台)‘
FROM dual;
insert into EGMAS_COUNT_DATA(DAY, COUNT,SYSTEM_NAME,Operation_index)
SELECT to_date(to_char(sysdate-1,‘yyyy-MM-dd‘),‘yyyy-MM-dd‘), (select count(1) from T_ORDERS WHERE
to_char(CREATED_TM,‘yyyy-MM-dd‘) = to_char(sysdate-1,‘yyyy-MM-dd‘)), ‘EGMAS‘,‘速运通订单量(港澳台)‘
FROM dual;
commit;
end orderCount;
/
设置job执行时间:
variable jobno number;
begin
dbms_job.submit(:jobno,‘orderCount;‘, sysdate, ‘TRUNC(sysdate+1)+1/24‘);
end;
/
启动job:
begin
dbms_job.run(44);
commit;
end;
/
查看job是否存在:
select job, next_date, next_sec, failures, broken from user_jobs;
以上是关于oracle存储过程怎样批量插入新数据的主要内容,如果未能解决你的问题,请参考以下文章