怎么向数据库中添加大量数据(oracle)
现在有一个表,id NUMBER NOT NULL,
time DATE NOT NULL,
a1 NUMBER NOT NULL,
a2 NUMBER NOT NULL,
a3 NUMBER NOT NULL,
a4 NUMBER NOT NULL,
a5 NUMBER NOT NULL,
a6 NUMBER NOT NULL,id为主键,想要添加id从1~65534的数据,其中time为2011/2/11 20:00:00不变,
a1~a4均为1,a5=id,a6=id-1.这个要怎么添加这么多数据?
------解决方案--------------------
参考---
CREATE TABLE stt(id NUMBER NOT NULL, time DATE NOT NULL,a1 NUMBER NOT NULL,
a2 NUMBER NOT NULL,
a3 NUMBER NOT NULL,
a4 NUMBER NOT NULL,
a5 NUMBER NOT NULL,
a6 NUMBER NOT NULL);
BEGIN
FOR i IN 1 .. 65534 LOOP
INSERT INTO Stt
SELECT i,
To_Date('2011/2/11 20:00:00', 'yyyy/mm/dd hh24:mi:ss'),
1,
1,
1,
1,
i,
i - 1
FROM Dual;
END LOOP;
END;
------解决方案--------------------写一个For循环啊。。
循环的时候你把这些值放进去就可以了。。
然后a6就等于循环的i -1不就可以了吗?
------解决方案--------------------SQL code
CREATE TABLE stt(id NUMBER NOT NULL, time DATE NOT NULL,a1 NUMBER NOT NULL,
a2 NUMBER NOT NULL,
a3 NUMBER NOT NULL,
a4 NUMBER NOT NULL,
a5 NUMBER NOT NULL,
a6 NUMBER NOT NULL);
BEGIN
FOR i IN 1 .. 65534 LOOP
INSERT INTO Stt
SELECT i,
To_Date('2011/2/11 20:00:00', 'yyyy/mm/dd hh24:mi:ss'),
1,
1,
1,
1,
i,
i - 1
FROM Dual;
END LOOP;
END;