[Oracle@cat admin]$ sqlplus cat/cat
SQL*Plus: Release 11.2.0.1.0 Production on Sat Jan 14 08:31:16 2012
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Release 11.2.0.1.0 - Production
create table test_users(
userid varchar2(16) primary key,
username varchar2(32) not null,
passwd varchar2(16),
phone varchar2(32),
email varchar2(64))
tablespace cat_data;
5,创建测试存储过程
$ vi test_proceduce.sql
set serveroutput on
create or replace procedure init_test_users
as
currentId number(16) := 0;
maxNum number(16) := 5000000;
l_userid varchar2(16);
l_username varchar2(32);
sqltext varchar2(256);
begin
dbms_output.put_line('begin ...' || to_char(current_timestamp, 'HH24:MI:SSxFF'));
--sqltext := 'insert into test_users(userid, username, passwd, phone, email) values(:userid, :username,' || '''111111'',' || '''13800000000'',' || '''xx''' || ')';
sqltext := 'insert into test_users(userid, username, passwd, phone, email) values(:userid, :username,' || '111111,' || '13800000000,' || '''xx''' || ')';
--这里需注意xx前后由'''包起来,而前面的111111和13800000000可以前后只用'包起来,因为他们像数字,Oracle可以自动进行转义,而xx就不行,被这个问题曾经折腾了好多天 :(
loop
currentId:=currentId + 1;
l_userid:=to_char(currentId);
l_username:=sys_guid();
execute immediate sqltext using l_userid, l_username;
exit when currentId >= maxNum;
end loop;
dbms_output.put_line('before commit ...' || to_char(current_timestamp, 'HH24:MI:SSxFF'));
commit;
dbms_output.put_line('end commit ...' || to_char(current_timestamp, 'HH24:MI:SSxFF'));
end init_test_users;
/
$ chmod +x test_proceduce.sql
$ sqlplus cat/cat
SQL> @test_proceduce.sql
Procedure created.
