Home >Database >Mysql Tutorial >Oracle中插入大量测试数据

Oracle中插入大量测试数据

WBOY
WBOYOriginal
2016-06-07 16:47:121339browse

Oracle工作中有时需要用到大量的测试数据,一条一条的很慢很费劲,如果用存储过程来做就快多了。

Oracle工作中有时需要用到大量的测试数据,一条一条的很慢很费劲,,如果用存储过程来做就快多了。

举个例子,假设有A表和它的关联表B表,b_id等于a_id,表字段如下,

表A:

a_id

a_name

表B:

b_id

b_name

b_value

1、创建获取序列的函数

create or replace function get_seq return number
 as
      seq_num number;
 begin
        select hibernate_sequence.nextval into seq_num from dual;
        return  (seq_num);
 end get_seq;

2、创建存储过程,插入10万条数据

DECLARE
i INT;
testid number(19);
BEGIN
i := 0;
WHILE(i LOOP
    i := i + 1;
    testid := get_seq;
    INSERT INTO A(A_ID, A_NAME) VALUES(testid, 'n001');
    INSERT INTO B(B_ID, B_NAME, B_VALUE) VALUES(testid, 'n1', 'str_n1');
    INSERT INTO B(B_ID, B_NAME, B_VALUE) VALUES(testid, 't1', '00123');
END LOOP;
COMMIT;
END;

这样就可以把数据很快的插入到表中了

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn