jeudi 9 août 2007

Melhorando SQL*Loader exemplo

Vi que o exemplo anterior de sql*loader esta com alguns problemas então decidi fazer um melhor, já q nada se cria e tudo se copia (e melhora). Acho q vale a pena fazer o exemplo abaixo, eh muito fácil.

Boa carga...


No sqlplus:
1) VERIFIQUE SE O USUARIO SCOTT ESTA HABILITADO E A SENHA ESTA CORRETA "TIGER" NO SQLPLUS

2) CRIE UMA TABELA PARA Seu TESTE, PARA NAO MODIFICAR A DE EXEMPLO. DIGITE:"CREATE TABLE EMP2 AS SELECT * FROM EMP;"

3) O ORACLE RECLAMARÁ QUE A TABELA CONTEM DADOS, ENTAO DIGITE: "TRUNCATE TABLE EMP2;"

No Windows:
4) ABRA O NOTEPAD, COLOQUE O CONTEUDO ABAIXO E SALVE COM NOME c:\LOADER.CTL

CONTEUDO DO MEU ARQUIVO LOADER.CTL
-----------------------------------INICIO DO ARQUIVO---------------------------------------------
load data
infile 'c:\mydata.csv'
into table emp2
fields terminated by "," optionally enclosed by '"'
( empno, ename, sal, deptno )
-----------------------------------FIM DO ARQUIVO---------------------------------------------

ABRA O NOTEPAD NOVAMENTE, COLOQUE O CONTEUDO ABAIXO E SALVE COM NOME c:\mydata.csv

1001,"Scott Tiger", 1000, 40
1002,"Frank Naude", 500, 20


5) Digite esse comando no DOS (command prompt) colocando o prompt no c:\

sqlldr scott/tiger control=loader.ctl

Isso gerará um log (c:\LOADER.LOG) onde será descrito o evento de carga.

6) vERIFIQUE O c:\LOADER.LOG abrindo o arquivo, vc verá o que causou problema e se as linhas foram inseridas.

CONTEUDO DO MEU ARQUIVO LOADER.LOG:

-----------------------------------INICIO DO ARQUIVO---------------------------------------------

SQL*Loader: Release 9.0.1.1.1 - Production on Thu Aug 9 13:30:13 2007

(c) Copyright 2001 Oracle Corporation. All rights reserved.

Control File: loader.ctl
Data File: c:\mydata.csv
Bad File: mydata.bad
Discard File: none specified

(Allow all discards)

Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional

Table EMP2, loaded from every logical record.
Insert option in effect for this table: INSERT

Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
EMPNO FIRST * , O(") CHARACTER
ENAME NEXT * , O(") CHARACTER
SAL NEXT * , O(") CHARACTER
DEPTNO NEXT * , O(") CHARACTER


Table EMP2:
2 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.


Space allocated for bind array: 66048 bytes(64 rows)
Read buffer bytes: 1048576

Total logical records skipped: 0
Total logical records read: 2
Total logical records rejected: 0
Total logical records discarded: 0

Run began on Thu Aug 09 13:30:13 2007
Run ended on Thu Aug 09 13:30:13 2007

Elapsed time was: 00:00:00.10
CPU time was: 00:00:00.03

----------------------------------FIM DO ARQUIVO----------------------------------------------

7) No sqlplus Verifique os dados na tabela emp2 com o usuario scott/tiger
>select * from emp2

Voilà


#ATENÇAO#
SE ESSA MENSAGEM TE AJUDOU, DEIXE UMA MENSAGEM ANONIMA ME XINGANDO
#########

Aucun commentaire:

Enregistrer un commentaire