sqlldr direct参数小测试


首先建一表
 CREATE TABLE XEP.TEST
  (    ID NUMBER(*,0),                                              --主键
       NAME VARCHAR2(16) NOT NULL ENABLE, --非空
       AGE NUMBER(3,0),                                               --check
        CONSTRAINT CHECK_AGE CHECK (age>0),
        PRIMARY KEY (ID)
 USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
 TABLESPACE XEP_SPACE  ENABLE
  ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
 TABLESPACE XEP_SPACE
 
 
SQL> desc xep.test
 名称                                      是否为空? 类型
 ----------------------------------------- -------- ----------------------------

 ID                                        NOT NULL NUMBER(38)
 NAME                                      NOT NULL VARCHAR2(16)
 AGE                                                NUMBER(3)
 
1.创建 控制文件 ctr.txt
Load Data
infile  data.txt
badfile badfile.txt
discardfile discardfile.txt
replace
into table test
FIELDS TERMINATED ","
(
 id,
 name,
 age
)

2.创建数据文件 data.txt
1,"test1",1
2,"test2",2
3,"test3",3
4,"test4",4
3,"test5",5
6,"test6",6
6,"test7",-1
6,"test8",0
9,"test9",9

3.执行loader命令 D:\document\xep\load>sqlldr xep/xiaoep control=ctr.txt  skip=2

SQL> select * from xep.test;

        ID NAME                    AGE
---------- ---------------- ----------
         3 "test3"                   3
         4 "test4"                   4
         6 "test6"                   6
         9 "test9"                   9


4.执行带direct参数的loader命令 D:\document\xep\load>sqlldr xep/xiaoep control=ctr.txt  skip=2 direct=y

SQL> select * from xep.test;

        ID NAME                    AGE
---------- ---------------- ----------
         3 "test3"                   3
         4 "test4"                   4
         3 "test5"                   5
         6 "test6"                   6
         6 "test7"                  -1
         6 "test8"                   0
         9 "test9"                   9

已选择7行。

普通load相当于insert 每一条都会检查约束,直接路径加载(带direct=y) 只检查主键与唯一约束  其它的不做检查 如果主键冲突 也会插入表中。
skip参数是跳过前几行。

再测一下触发器
1.创建一序列 create sequence test_seq increment by 1 start with 1 cache 15 nocycle

2.创建一新表记录用户插入数据的详细信息
create table test_audit(id number,insert_user varchar2(16),cmd varchar2(16),val varchar2(32));

3.创建触发器
create or replace trigger t_insert
  after insert or  delete or update on test  
  for each row

begin
    if inserting then
    insert into test_audit values(test_seq.nextval,user,'insert',:new.name);
   
    elsif updating then
      insert into test_audit values(test_seq.nextval,user,'update',:new.name ||'_'||:old.name);
    
    elsif deleting then
      insert into test_audit values(test_seq.nextval,user,'delete',:old.name);
    end if;
    
end;


4.执行loader命令 D:\document\xep\load>sqlldr xep/xiaoep control=ctr.txt  skip=2

SQL> select * from xep.test;

        ID NAME                    AGE
---------- ---------------- ----------
         3 "test3"                   3
         4 "test4"                   4
         6 "test6"                   6
         9 "test9"                   9
         
SQL> select * from xep.test_audit;

        ID INSERT_USER      CMD              VAL
---------- ---------------- ---------------- --------------------------------
         1 XEP              insert           "test3"
         2 XEP              insert           "test4"
         3 XEP              insert           "test6"
         4 XEP              insert           "test9"
         
SQL> truncate table xep.test;

5.执行loader命令(带direct=y)   D:\document\xep\load>sqlldr xep/xiaoep control=ctr.txt  direct=y     

SQL> select * from xep.test;

        ID NAME                    AGE
---------- ---------------- ----------
         1 "test1"                   1
         2 "test2"                   2
         3 "test3"                   3
         4 "test4"                   4
         3 "test5"                   5
         6 "test6"                   6
         6 "test7"                  -1
         6 "test8"                   0
         9 "test9"                   9

SQL> select * from xep.test_audit;

        ID INSERT_USER      CMD              VAL
---------- ---------------- ---------------- --------------------------------
         1 XEP              insert           "test3"
         2 XEP              insert           "test4"
         3 XEP              insert           "test6"
         4 XEP              insert           "test9"

          

常规路径加载                                                                       直接路径加载
 
使用 COMMIT 来使所做的更 改能永久保留                    使用数据保存
 

始终生成重做日志条目                                                       仅在特定条件下才生成重做 日志条目
 

执行所有的约束                                                                   仅执行主键约束、唯一性约束 和 NOT NULL 约束
 
触发 INSERT 触发器    不触发 INSERT 触发器              可以加载到集簇表中    无法加载到集簇表中
 

其他用户可以对表进行更改                                                其他用户不能对表进行更改


你可能感兴趣的:(sql,user,table,null,delete,insert)