spoolエクスポートおよびsqllderインポート.


#!/bin/bash
sqlplus -s $DB_NAME  <<EXP
set pages 50000;
set lines 200;    
set trims on;
set heading off;
set feedback off
spool "lwc_test.csv";
select test_id||','||test_name||','||test_sex from lwc_test; 
spool off;
EXP
echo export successfully!
echo -e "load data
infile lwc_test.csv
into table lwc_test
Fields terminated by ','
(TEST_ID,
TEST_NAME,
TEST_SEX)" > "lwc_test.ctl"

 
 
#!/bin/bash
echo ----begin to insert into imp table----
   sqlldr $DB_NAME control="lwc_test.ctl"   log="lwc_test.log"  bad="bad.log" 
if [ -f "bad.log" ]; then 
echo ' imp bad.lg'
exit
else
echo ' imp successfully.'
fi
echo ----import successfully----
 
select * from lwc_test
create table LWC_TEST
(
  TEST_ID   NUMBER(5),
  TEST_NAME VARCHAR2(10),
  TEST_SEX  VARCHAR2(20)
);

alter table lwc_test add (
  beizhu varchar2(100) default 'beizhu',
  constraint lt_pk primary key (test_id),
  constraint lt_unuque unique (beizhu)
);

commit;

create index lt_idx on lwc_test (test_name);

insert into lwc_test values(1001,'liwenchao','','')
insert into lwc_test values(1002,'xuetuo','','')
insert into lwc_test values(1003,'yinpinyong','','')

update lwc_test lt set lt.test_sex ='male';
drop index lt_idx;

ID列シーケンスの自己増加:
1.シーケンスの作成:
create sequence seq_lt
increment by 1
start with 1
minvalue 1 
maxvalue 900
NOCYCLE;
2.トリガーの作成
create trigger trg_lt before insert on lwc_test
for each row
begin
select seq_lt.nextval into :new.TEST_ID from dual;
end;
insert into lwc_test lt values(55455,'liwenchao','male','')
// 。 :(1. , , 。2. , insert )。
または挿入時にシーケンス・アイテムを直接関連付け、トリガを作成しないでください.
insert into lwc_test lt values(seq_lt.nextval,'xuetuo','male','')。