如果有序列号的话:
insert into tbname2 select col1,col2... from tbname1 where id>0 and id<1001;
insert into tbname2 select col1,col2... from tbname1 where id>0 and id<1001;
解决方案 »
- 如何将ORACLE定期导入到EXCEl中
- 求助:ORA 10g 透明网关连接SQL 2005连不上
- oracle存储过程的解密
- 4400W量的语句优化!求高手
- 关于sql优化——索引的使用
- 现有的服务器操作系统是windows 2000 server,已经安装了sql server2000,现在想再安装Oracle 9i,这样做可行吗?
- 如何把一个数据库的表和结构复制到另一个数据库,我用的是9i
- ORA-12541如何处理
- 不创建新表从oracle中导出数据
- 两个字节的byte型数据在oracle中应该存成什么类型?
- 用Oracle如何存储,读取AVI(视频)文件,应用程序用Delphi!(谢谢!)
- 在oracle里如何倒入foxpro的数据呢?
第1到1000条当然可以这样用,但是第1001到2000呢?我是想要找一种最快的并且不锁表可以让其他用户正常使用的,而我后台可以不停循环的处理最后直到50多万条记录全部导完为止。但是显然不能用rownum>1001 and rownum<2000的啊?
直接用sql不行,因为数据之间有很多差异,需要先单独把数据从大表拿出来然后经过处理过后再写到另外两个小表里。所以就放在procedure里用cursor来做了
也许你认为不可以实际却可以呢?再说了,处理50万条记录,也不是什么大事,很快就可以完成
当然,如果你这种操作是要写一个程序来频繁的调用,那是值得考虑的
否则,你尽管去做好了
create or replace procedure trans_user_info
IS
cursor c1 is select * from table1;
emp_record c1%rowtype;
TEMP_USERNAME VARCHAR2(30);
TEMP_NICKNAME VARCHAR2(30);
TEMP_PASSWD VARCHAR2(30);
TEMP_RAWPASSWD VARCHAR2(30);
TEMP_REALNAME VARCHAR2(30);
TEMP_EMAIL VARCHAR2(50);
TEMP_SEX NUMBER(2);
TEMP_BIRTH date;
... TEMP_STRING VARCHAR2(1000);
TEMP_NUMBER number(12);
BEGIN
for emp_record in c1 loop
TEMP_USERNAME := emp_record.USERNAME;
TEMP_NICKNAME := emp_record.NICKNAME;
... if (TEMP_STRING = '女') then
TEMP_SEX := 1;
else
TEMP_SEX := 0;
end if;
TEMP_BIRTH :=nvl(emp_record.BIRTH,sysdate);
TEMP_BLOODTYPE := emp_record.BLOODTYPE;
TEMP_STRING := emp_record.HIGHT;
TEMP_HEIGHT := 0;
if (length(TEMP_STRING)<=3) then
begin
TEMP_HEIGHT := to_number(TEMP_STRING);
exception
when others then
null;
end;
end if;
TEMP_STRING := emp_record.WEIGHT;
TEMP_WEIGHT := 0;
if (length(TEMP_STRING)<=3) then
begin
TEMP_WEIGHT := to_number(TEMP_STRING);
exception
when others then
null;
end;
end if;
TEMP_BODY := emp_record.BODY;
TEMP_MARRIAGE := emp_record.MARRIAGE;
TEMP_REGISTER_DATE := emp_record.JOINDATE;
TEMP_USERTYPE := emp_record.USERTYPE;
TEMP_CONSTELLATION := emp_record.CONSTELLATION;
TEMP_STRING := emp_record.EDUCATION;
TEMP_EDUCATION := 8;
if (TEMP_STRING='初中') then
TEMP_EDUCATION := 0;
elsif (TEMP_STRING='高中') then
TEMP_EDUCATION := 1;
elsif (TEMP_STRING='中专') then
TEMP_EDUCATION := 2;
elsif (TEMP_STRING='大专') then
TEMP_EDUCATION := 3;
elsif (TEMP_STRING='大学') then
TEMP_EDUCATION := 4;
elsif (TEMP_STRING='双学位') then
TEMP_EDUCATION := 5;
elsif (TEMP_STRING='硕士') then
TEMP_EDUCATION := 6;
elsif (TEMP_STRING='博士') then
TEMP_EDUCATION := 7;
else
TEMP_EDUCATION := 8;
end if;
TEMP_HOUSING := emp_record.HOUSING;
TEMP_STRING := emp_record.INCOME;
TEMP_INCOME := 0;
if (TEMP_STRING='RMB1000以下') then
TEMP_INCOME := 1;
elsif (TEMP_STRING='RMB1000-2000') then
TEMP_INCOME := 2;
elsif (TEMP_STRING='RMB2000-3500') then
TEMP_INCOME := 3;
elsif (TEMP_STRING='RMB3500-5000') then
TEMP_INCOME := 4;
elsif (TEMP_STRING='RMB5000-7500') then
TEMP_INCOME := 5;
elsif (TEMP_STRING='RMB7500-10000') then
TEMP_INCOME := 6;
elsif (TEMP_STRING='RMB10000以上') then
TEMP_INCOME := 7;
else
TEMP_INCOME := 0;
end if;
... if (TEMP_NUMBER=1) then
TEMP_PICTURE := 1;
end if;
TEMP_UPLOADDATE := emp_record.UPLOADDATE;
TEMP_COMMON_BAK1 := '';
TEMP_COMMON_BAK2 := '';
TEMP_STRING := emp_record.PENNAME;
TEMP_NICKNAME_CHANGED := 0;
if (TEMP_STRING='**ALREADY CHANGED**') then
TEMP_NICKNAME_CHANGED := 1;
end if;
TEMP_LAST_VALID_LOGIN := emp_record.LOGIN;
if (length(TEMP_STRING)<=3) then
begin
TEMP_CIRCUMFERENCE := to_number(TEMP_STRING);
exception
when others then
null;
end;
end if;
TEMP_STRING := emp_record.WAISTLINE;
TEMP_WAISTLINE := 0;
if (length(TEMP_STRING)<=3) then
begin
TEMP_WAISTLINE := to_number(TEMP_STRING);
exception
when others then
null;
end;
end if;
TEMP_STRING := emp_record.TUNWEI;
TEMP_TUNWEI := 0;
if (length(TEMP_STRING)<=3) then
begin
TEMP_TUNWEI := to_number(TEMP_STRING);
exception
when others then
null;
end;
end if;
TEMP_PARENT_APPRAISE := emp_record.PARENT_APPRAISE;
...
insert into table2 (USERNAME,NICKNAME,PASSWD,RAWPASSWD,
REALNAME,EMAIL,SEX,...) values (
TEMP_USERNAME,TEMP_NICKNAME,...);
insert into table3(USERNAME,NICKNAME_CHANGED,...)
values (TEMP_USERNAME,TEMP_NICKNAME_CHANGED,TEMP_LAST_VALID_LOGIN,
...);
commit;
end loop;
END;
主要目的就是把table1中的数据导到table2和table3中,中间省略了很多变量的声明及普通的赋值操作。(省略地方用...来表示)如果这么做的话,一个多小时可以做完,但是如果网络连接中断的话,因为数据都是放在一个大记录集中所以很危险。但如果用rownum和minus结合来每次小批量做速度好象更慢的。不知各位高手有何意见。
insert into table2 (USERNAME,NICKNAME,PASSWD,RAWPASSWD,REALNAME,EMAIL,SEX,...)
select USERNAME,NICKNAME,....,
decode(sex,'女',1,0),...,
decode(education,'初中',0,'高中',1,'中专',2,...,8),...
from table1;
insert into table2 select col1,col2,... from table1 where rownum >1000 and rownum <= 2000
这样的句子能否取出结果集
insert into table2
(select col1,col2,... from table1 where rownum <= 2000
minus
select col1,col2,... from table1 where rownum <1001)
insert into table2
(select col1,col2,... from table1 where rownum <= 2000
minus
select col1,col2,... from table1 where rownum <1001)