Home » SQL & PL/SQL » SQL & PL/SQL » Delimited by '\' in oracle external table
Delimited by '\' in oracle external table [message #614607] Fri, 23 May 2014 12:40 Go to next message
arvindvegad
Messages: 5
Registered: May 2014
Location: USA
Junior Member
Hi - I have data file delimited by '\'

test.txt file has

a1\b1\c1\d1\e1
a2\b2\c2\d2\e2


create table test
(col1 varchar2(10),
col2 varchar2(10),
col3 varchar2(10))
ORGANIZATION external
(TYPE oracle_loader
DEFAULT DIRECTORY DIR_NAME
ACCESS PARAMETERS
(FIELDS TERMINATED BY "\"
(col1,
col2,
col3)
location ('test.txt'))

Trying to run select * from test - does not work - Can you help me how to define text file with field terminated by '\' in external table syntax.

Re: Delimited by '\' in oracle external table [message #614609 is a reply to message #614607] Fri, 23 May 2014 12:54 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
"does not work" is not a valid Oracle error message.

SQL> l
  1  create table test
  2  (col1 varchar2(10),
  3  col2 varchar2(10),
  4  col3 varchar2(10))
  5  ORGANIZATION external
  6  (TYPE oracle_loader
  7  DEFAULT DIRECTORY DIR_NAME
  8  ACCESS PARAMETERS
  9  (FIELDS TERMINATED BY "\"
 10  (col1,
 11  col2,
 12  col3)
 13* location ('test.txt'))
SQL> /
location ('test.txt'))
                     *
ERROR at line 13:
ORA-30648: missing LOCATION keyword
Re: Delimited by '\' in oracle external table [message #614612 is a reply to message #614609] Fri, 23 May 2014 13:20 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
I am assuming you are saying the error is when you select and NOT on the creation of the table, although I ran your create table script and it is invalid syntax.

Backslash is hex character 5C. did you try that in the definition?
Re: Delimited by '\' in oracle external table [message #614613 is a reply to message #614612] Fri, 23 May 2014 14:08 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
consider to actually Read The Fine Manual

http://docs.oracle.com/cd/E16655_01/server.121/e17636/tables.htm#ADMIN01507
Re: Delimited by '\' in oracle external table [message #614614 is a reply to message #614612] Fri, 23 May 2014 14:25 Go to previous messageGo to next message
arvindvegad
Messages: 5
Registered: May 2014
Location: USA
Junior Member
Yes. the error is when i run select * from test; - how can we use \ as delimited in file. Can u suggest in the table syntax ?
CREATE TABLE test
(col1 varchar2(10),
col2 varchar2(10),
col3 varchar2(10))
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY cashdwh_data
ACCESS PARAMETERS
(
FIELDS TERMINATED BY "\"
(col1,
col2,
col3)
)
LOCATION ('test')
);
Re: Delimited by '\' in oracle external table [message #614615 is a reply to message #614614] Fri, 23 May 2014 14:29 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
ERROR? What Error?
I don't see any error.

show results from SQL below

desc test
select directory_name from all_directories;

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and please read http://www.orafaq.com/forum/t/174502/102589/


Re: Delimited by '\' in oracle external table [message #614616 is a reply to message #614614] Fri, 23 May 2014 14:34 Go to previous messageGo to next message
arvindvegad
Messages: 5
Registered: May 2014
Location: USA
Junior Member
I tried
FIELDS TERMINATED BY x'5c' and it is working fine.
Thanks for your help
Re: Delimited by '\' in oracle external table [message #614617 is a reply to message #614616] Fri, 23 May 2014 14:40 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>FIELDS TERMINATED BY x'5c' and it is working fine.
consider using a different character as the Field Separator; like "|" [CHR(142)]
Re: Delimited by '\' in oracle external table [message #614618 is a reply to message #614614] Fri, 23 May 2014 14:54 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
arvindvegad wrote on Fri, 23 May 2014 15:25
Yes. the error is when i run select * from test; - how can we use \ as delimited in file. Can u suggest in the table syntax ?


Backslash is escape character. Use its ASCII code X'5C' instead, as others suggested. Also, your table has 3 columns and file has 5 fields:

SQL> create table test(
  2                    col1 varchar2(10),
  3                    col2 varchar2(10),
  4                    col3 varchar2(10)
  5                   )
  6    ORGANIZATION external
  7      (
  8       TYPE oracle_loader
  9       DEFAULT DIRECTORY TEMP
 10       ACCESS PARAMETERS
 11         (
 12          FIELDS TERMINATED BY X'5c'
 13            (
 14             col1,
 15             col2,
 16             col3,
 17             col4,
 18             col5
 19            )
 20         )
 21       location ('test.txt')
 22      )
 23  /

Table created.

SQL> select  *
  2    from  test
  3  /

COL1       COL2       COL3
---------- ---------- ----------
a1         b1         c1
a2         b2         c2

SQL>


SY.

[Updated on: Fri, 23 May 2014 14:55]

Report message to a moderator

Re: Delimited by '\' in oracle external table [message #614620 is a reply to message #614618] Fri, 23 May 2014 15:33 Go to previous messageGo to next message
arvindvegad
Messages: 5
Registered: May 2014
Location: USA
Junior Member
one more twist - The data file may have different no. of column in a row for example

Record 1 :a1\b1\c1\d1\e1 (5 fields)
Record 2 :a1\b1\c1\d1\e1\f1\g1 ( 7 fields)
Record 3 :a1\b1\c1 (3 fields)

Do you know how to handle this in the sysntax ?

Thanks in advance
Re: Delimited by '\' in oracle external table [message #614621 is a reply to message #614620] Fri, 23 May 2014 15:57 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
arvindvegad wrote on Fri, 23 May 2014 16:33
one more twist - The data file may have different no.


So how many columns do you want? Assuming you want all and max number of fields is 7, define 7 columns:

SQL> create table test(
  2                    col1 varchar2(10),
  3                    col2 varchar2(10),
  4                    col3 varchar2(10),
  5                    col4 varchar2(10),
  6                    col5 varchar2(10),
  7                    col6 varchar2(10),
  8                    col7 varchar2(10)
  9                   )
 10    ORGANIZATION external
 11      (
 12       TYPE oracle_loader
 13       DEFAULT DIRECTORY TEMP
 14       ACCESS PARAMETERS
 15         (
 16          FIELDS TERMINATED BY X'5c'
 17         )
 18       location ('test.txt')
 19      )
 20  /

Table created.

SQL> select  *
  2    from  test
  3  /

COL1       COL2       COL3       COL4       COL5       COL6       COL7
---------- ---------- ---------- ---------- ---------- ---------- ----------
a1         b1         c1         d1         e1
a2         b2         c2         d2         e2
a3         b3         c3
a4         b4         c4         d4         e4         f4         g4

SQL>


SY.

[Updated on: Fri, 23 May 2014 15:59]

Report message to a moderator

Re: Delimited by '\' in oracle external table [message #614642 is a reply to message #614621] Sun, 25 May 2014 00:48 Go to previous messageGo to next message
arvindvegad
Messages: 5
Registered: May 2014
Location: USA
Junior Member
Thanks
I tried with above systax ( 7 column ) with test file as

a1\b1\c1\d1\e1\f1\g1
a1\b1\c1\d1\e1

row one have seven column while row 2 has 5 - It does not work. how you achieve this ?
Re: Delimited by '\' in oracle external table [message #614643 is a reply to message #614642] Sun, 25 May 2014 00:51 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Rows have a fixed number of columns.

Re: Delimited by '\' in oracle external table [message #614646 is a reply to message #614642] Sun, 25 May 2014 02:54 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
arvindvegad wrote on Sun, 25 May 2014 11:18

I tried with above systax ( 7 column ) with test file as

a1\b1\c1\d1\e1\f1\g1
a1\b1\c1\d1\e1

row one have seven column while row 2 has 5 - It does not work. how you achieve this ?


If you see SY's demo in above post, he took maximum number of fields which totals to 7 columns. And for the 4 rows inserted, it has values for 5,5,3 and 7 columns respectively. So what different are you trying to achieve? Please post it and show us.
Re: Delimited by '\' in oracle external table [message #614650 is a reply to message #614646] Sun, 25 May 2014 06:53 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Lalit Kumar B wrote on Sun, 25 May 2014 03:54
And for the 4 rows inserted, it has values for 5,5,3 and 7 columns respectively.


Absolutely not. Table can't have different number of columns in different rows. All rows in my example have 7 columns. External tables have default of MISSING FIELD VALUES ARE NULL. So in this case external table automatically assigns NULLs to missing fields when loading records with less than 7 fields. As a result columns corresponding to missing fields get NULL values.

SY.
Re: Delimited by '\' in oracle external table [message #614653 is a reply to message #614650] Sun, 25 May 2014 07:28 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
I am absolutely correct by saying there are 5,5,3 and 7 values in each row respectively. I said 5,5,3,7 are values for columns, and NULL is not a value, its nothing. So values out of 7 columns in each row are 5,5,3 and 7 respectively.
The other fields which doesn't have values are cinsidered NULL.
Re: Delimited by '\' in oracle external table [message #614655 is a reply to message #614653] Sun, 25 May 2014 07:53 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
All 7 columns in all 4 rows have values. NULL is also a value.

SY.
Re: Delimited by '\' in oracle external table [message #614656 is a reply to message #614653] Sun, 25 May 2014 08:06 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
NULL is not a value, its nothing.


Wrong! NULL means "unset" or "unknown" not "nothing".

Re: Delimited by '\' in oracle external table [message #614663 is a reply to message #614655] Sun, 25 May 2014 10:17 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Solomon Yakobson wrote on Sun, 25 May 2014 18:23
NULL is also a value.


Per documentation, NULLS,
"If a column in a row has no value, then the column is said to be null". So NULL itself can't be a value. The only exception that Oracle has is for zero length strings.

Michel, agreed. Saying "Its nothing" for NULL in english is also absurd. It's absence of a value Smile But can't be a value itself.
Re: Delimited by '\' in oracle external table [message #614670 is a reply to message #614663] Sun, 25 May 2014 12:02 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

I do not speak about English, I can't give any lesson in English to anyone given my poor level in this mattter, I speak about relational theory. NULL means we currently do not know the value or this attribute/field/column is meaningless for this item/element/row which is far from nothing.

Previous Topic: Help me to write query
Next Topic: how to send email when the status of the object gets invalid?
Goto Forum:
  


Current Time: Sat Apr 20 10:31:21 CDT 2024