Skip to Main Content
  • Questions
  • single field having multiple line value. issue in extracted file.

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Partheeban.

Asked: July 26, 2016 - 8:23 am UTC

Last updated: August 08, 2016 - 4:47 pm UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi

Every time I am facing some issues, please help on this. Test cases are given below

CREATE TABLE AA
(
ID NUMBER NOT NULL,
NAME VARCHAR2(80 BYTE) NOT NULL,
BANK_ADDRESS VARCHAR2(1000 BYTE)
);

INSERT INTO AA VALUES
(1,’MGR’, ‘ICICI BANK
MOUNT ROAD
CHENNAI’);

INSERT INTO AA VALUES
(2,’SIVAJI’, ‘SBI
ANNA ROAD
CHENNAI’);

INSERT INTO AA VALUES
(3,’KABALI’, ‘RBS OLYMBIA GUINDY CHENNAI’);

--data stored in the database same as like as it is.

SELECT * FROM AA;
OUTPUT displayed in UNIX server USING SQLPLUS / login
===================================
ID NAME BANK_ADDRESS
----------------------------------
1 MGR SBI
ANNA ROAD
CHENNAI
2 SIVAJI ICICI BANK
MOUNT ROAD
CHENNAI
3 KABALI RBS OLYMBIA GUINDY CHENNAI

I have created the spool file query

aa.sql
SET TRIMSPOOL ON
SET TRIMOUT ON
SET HEADING OFF
SET FEEDBACK OFF
SET LINESIZE 10000
SET PAGESIZE 0
SET TERM OFF
SET ECHO OFF
SET LONG 10000

SPOOL local_path/bank_aa.txt
SELECT 'HDR.AA.' || to_char(sysdate,'YYYYMMDDHH24MISS') from dual;
SELECT distinct
ID ||'|'||
NAME ||'|'||
BANK_ADDRESS
FROM AA
UNION ALL
select 'TRL.AA.' || count(*) from AA;
SPOOL OFF;
exit;

I had received the bank_aa.txt file like this.

HDR.AA.20160726130606
1 | MGR | SBI
ANNA ROAD
CHENNAI
2 | SIVAJI | ICICI BANK
MOUNT ROAD
CHENNAI
3 | KABALI | RBS OLYMBIA GUINDY CHENNAI
TRL.AA.3

Total data is 3 but extract files is having 7 data line. With this extract file I cant load the data into target database.

I need the output file like below
HDR.AA.20160726130606
1 | MGR | SBI ANNA ROAD CHENNAI
2 | SIVAJI | ICICI BANK MOUNT ROAD CHENNAI
3 | KABALI | RBS OLYMBIA GUINDY CHENNAI
TRL.AA.3

Can you pls help on this

Thanks
Partheeban.J





and Chris said...

You've got a choice:

- Change the output so the linebreaks are gone
- Preserve the linebreaks, but change the SQL*Loader script to handle these correctly.

To do the first, just replace the CR/LF characters appropriately:
drop table t purge;
create table aa (
    id number not null, name varchar2 ( 80 byte ) not null, 
    bank_address varchar2 ( 1000 byte )
  ) ;
insert into aa values
  ( 1,'MGR', 'ICICI BANK
MOUNT ROAD
CHENNAI'
  ) ;
insert into aa values
  ( 2,'SIVAJI', 'SBI
ANNA ROAD
CHENNAI'
  ) ;
insert into aa values
  ( 3,'KABALI', 'RBS OLYMBIA GUINDY CHENNAI'
  ) ;

SELECT 'HDR.AA.' || to_char(sysdate,'YYYYMMDDHH24MISS') from dual;

SELECT distinct ID ||'|'||NAME ||'|'||replace(replace(BANK_ADDRESS, chr(10), ' '), chr(13)) 
FROM AA;

ID||'|'||NAME||'|'||REPLACE(REPLACE(BANK_ADDRESS,CHR(10),''),CHR(13))  
1|MGR|ICICI BANK MOUNT ROAD CHENNAI                                    
3|KABALI|RBS OLYMBIA GUINDY CHENNAI                                    
2|SIVAJI|SBI ANNA ROAD CHENNAI


To do the second, use the STR option to define a custom "end-of-record" delimiter:

http://gerardnico.com/wiki/sql_loader/carriage_return_in_text_field
https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:9529759800346052607

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Thanks You

Partheeban J, July 27, 2016 - 12:20 pm UTC

Thank You So much Chris Saxon. It helps lot
Connor McDonald
July 27, 2016 - 1:22 pm UTC

glad we could help

single field having multiple line value. issue in extracted file.

Partheeban J, July 28, 2016 - 9:31 am UTC

Thanks, I understood to process of load this file's data via SQLLOADER. can you pls guide me, that can we create Oracle external table with this below data and load in to target tables?

bank_aa.txt - Which my file is having the data.

1 | MGR | SBI
ANNA ROAD
CHENNAI
2 | SIVAJI | ICICI BANK
MOUNT ROAD
CHENNAI
3 | KABALI | RBS OLYMBIA GUINDY CHENNAI

My Situation is,

I need to store, 10 extract files into 10 target tables.

In that, 9 extract files can directory load from sqlloader
But another 1 extract file need to create as oracle external table and this table will be compare with another new table. columns need to remap and need to load. Examples

Oracle External table
aa_et - columns
=====
id
name
BANK_ADDRESS

new table
bb - columns
===
id
target_name
bank_address

insert into targettable
select
aa.id
bb.name
aa.bank_address
from aa_et, bb
where aa_et.id=bb.id;


So how we can create the oracle external table with bank_aa.txt file format for load

can you please help on This solution it will help who has extracted the data with this type of wrong format and which they cannot able to re-extract.

Thanks
Partheeban.J



Chris Saxon
August 08, 2016 - 4:47 pm UTC

You could use a pre-processor script:

https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:9482573400346602730

Or have a special "end of record" character at the end of each record in the file:

https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:2818047000346046084

single field having multiple line value. issue in extracted file.

Partheeban J, August 03, 2016 - 2:07 pm UTC

Hi

Any update on my latest query

Thanks
Partheeban.J