A csv file in sqlldr in Linux

Source: Internet
Author: User

This is a small example of sqlldr in the exercise thinking book. It is to save the excel file as csv and load it into the Oracle database through sqlldr. The purpose was to demonstrate the processing method of sqlldr In the csv file and strings in the csv file that contain commas (,) and double quotation marks ("). However, I am confused for a while, I tried it over and over again, and I suspected that the last check was exactly the same. Then I passed the test. I will summarize it below.
 
By the way, record one:

Think twice about how to create the classic schema of scott and run $ ORACLE_HOME/rdbms/admin/scott. the content of the SQL script. In fact, I did not find the script and found and ran utlsampl. SQL
 
Excel is like this:

SMITH CLEAK 3904
ALLEN SALER, M 2891
WARD SALER, "S" 3128
KING PRESIDENT 2523


 

The content after 'ldr_case2.csv 'is:

SMITH, CLEAK, 3904
ALLEN, "SALER, M", 2891
WARD, "SALER," "S" ", 3128
KING, PRESIDENT, 2523

Everything looks quite normal. Then upload the csv file to the linux server where Oracle is located and write the control file:

Load data
Infile 'ldr_case2.csv'
Truncate into table bonus
Fields terminated by ', 'optionally enclosed '"'
(Ename, job, sal)

After loading, the log is displayed as failed:

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

Column Name Position Len Term Encl Datatype
--------------------------------------------------------------------------
Ename first *, O (") CHARACTER
Job next *, O (") CHARACTER
Sal next *, O (") CHARACTER

Record 1: Rejected-Error on table BONUS, column SAL.
ORA-01722: invalid number.

Record 2: Rejected-Error on table BONUS, column SAL.
ORA-01722: invalid number.

Record 3: Rejected-Error on table BONUS, column SAL.
ORA-01722: invalid number.

Record 4: Rejected-Error on table BONUS, column SAL.
ORA-01722: invalid number.

After repeated tests, I finally found that I put the content in the file into the file created in linux and loaded OK, but it seems that the csv file with the same content cannot be changed, I doubt whether something that looks the same hides anything that I don't notice. I searched the internet with this question. Someone encountered the same problem. The hidden difference is that the carriage return character is hidden at the end of the csv file line. Check the comparison in linux:
 
[Oracle @ nathan-rhel5 ~] $ Cat-v ldr_case2.csv
SMITH, CLEAK, 3904 ^ M
ALLEN, "SALER, M", 2891 ^ M
WARD, "SALER," "S" ", 3128 ^ M
KING, PRESIDENT, 2523 ^ M
[Oracle @ nathan-rhel5 ~] $ Cat-v ldr_case2.dat0
SMITH, CLEAK, 3904
ALLEN, "SALER, M", 2891
WARD, "SALER," "S" ", 3128
KING, PRESIDENT, 2523

It turns out ^ M at the end of the file line !!!

Convert the csv file to the following format:
[Oracle @ nathan-rhel5 ~] $ Dos2unix ldr_case2.csv
Dos2unix: converting file ldr_case2.csv to UNIX format...
[Oracle @ nathan-rhel5 ~] $ Cat-v ldr_case2.csv
SMITH, CLEAK, 3904
ALLEN, "SALER, M", 2891
WARD, "SALER," "S" ", 3128
KING, PRESIDENT, 2523

Then the data is reloaded successfully:
[Oracle @ nathan-rhel5 ~] $ Vi ldr_case2.ctl

Load data
Infile 'ldr_case2.csv'
Truncate into table bonus
Fields terminated by ', 'optionally enclosed '"'
(Ename, job, sal)
[Oracle @ nathan-rhel5 ~] $ Sqlldr scott/tiger control = ldr_case2.ctl

SQL * Loader: Release 10.2.0.1.0-Production on Sat Feb 22 22:47:31 2014

Copyright (c) 1982,200 5, Oracle. All rights reserved.

Commit point reached-logical record count 4
[Oracle @ nathan-rhel5 ~] $ Vi ldr_case2.log

Control File: ldr_case2.ctl
Data File: ldr_case2.csv
Bad File: ldr_case2.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 BONUS, loaded from every logical record.
Insert option in effect for this table: TRUNCATE

Column Name Position Len Term Encl Datatype
--------------------------------------------------------------------------
Ename first *, O (") CHARACTER
Job next *, O (") CHARACTER
Sal next *, O (") CHARACTER

Table BONUS:
4 Rows successfully loaded.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.