Home > Ask the Oracle Experts > (Archive) SQL and PL/SQL Questions & Answers > Changing the column values with hyphens to commas
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Changing the column values with hyphens to commas

Azim Fahmi EXPERT RESPONSE FROM: Azim Fahmi

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 19 January 2005
How can I decode while importing all the data to a table? For example, I have a .CSV file with two columns, such as:
Name     Address
selva    addr1-addr2-addr3
joy      asd1-asd2-asd3 
When I use the SQL loader to load this data to a table, I need a CTL file. How can I decode this date to change the column values with hyphens to (addr1-addr2-addr3) to comma (addr1,addr2,addr3)?

>
EXPERT RESPONSE
INSERT, APPEND, REPLACE, TRUNCATE in the control file refers to instruction to the database to:

1. Insert rows in an already empty table; this instruction will fail if the table is not empty.
2. Insert rows in a non-empty table.
3. Replace or truncate rows in a table and insert data in the data file or in the control file. Data can be part of the control file preceded by the instruction BEGINDATA.

In order for you to replace the hyphens with comma in the rows in the table, you need to create a before insert trigger on the table as follows.

Say the table is called TEST with the following description:

NAME VARCHAR2(100)
ADDRESS VARCHAR2(200)

The trigger text to achieve your objective is as follows:

CREATE OR REPLACE TRIGGER REPLACE_DASHES_WITH_COLUMN
BEFORE INSERT ON TEST
FOR EACH ROW
BEGIN
:NEW.ADDRESS := REPLACE(:NEW.ADDRESS,'-', ',');

END;
/

The control file (test.ctl) listing will be as follows:

LOAD DATA
INFILE *
INTO TABLE TEST
REPLACE
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
(NAME, ADDRESS)
BEGINDATA
Sonali Bendre, c/o Azim Fahmi-Somewhere outthere-Bollywood
Preity Zinta, "c/o Azim Fahmi-In your dreams-None of your business"
"George Bush", 1600 Pennsylvania Avenue-Whitehouse-Washington D.C.
Tony Blair, 10 Downing Street-London-UK-POSTALCODE HERE
Telaram Thakur, 10 Shabzi Mandi-Jackson Heights-New York

From command line if you type the following command:

sqlldr USERID=/{@db_name} control=test.ctl log=test.log bad=test.bad

where @db_name is optional

The dashes will be replaced with comma because of the compiled before user trigger above.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
(Archive) SQL and PL/SQL
ORA-01654 even though maxextents defined as unlimited
Read, process and write a text file to the database
Concatenating a null character affecting performance
Generating a 10 character alphanumeric sequence
Working with InterDev and DreamWeaver
Line placement in an EMESSAGE
Searching for stored reservation dates in a database
Specifying a column as NULL
Write a SQL script with optional arguments
Error message while trying to write a Pl/SQL block

Oracle PL/SQL
Oracle's free SQL Developer adds database migration tool
Confused about Oracle certification exams
ORA-01422 error when procedure returns more than one row
Calling procedure inside another procedure in anonymous block
How to import comma-delimited text file to Oracle table
Oracle updates Microsoft developer tools
PLS-00103 errors
PL/SQL do's and don't's: Five questions with Steven Feuerstein
Definition of force view
ORA-04082: NEW or OLD references not allowed in table level triggers

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
PL/SQL  (SearchOracle.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts