To_number conversion [message #479273] |
Fri, 15 October 2010 14:30 |
simplesql
Messages: 20 Registered: October 2010
|
Junior Member |
|
|
Hi,
I am sql loading a csv file.
My data has a salary column which comes with dollar symbol
Sal
$5,000
$10,000
$350,000
i want to eliminate $ symbol and load the amt as number in teh database table. I used the following command and getting an error:
Load data.....
fields terminated by ','.....
(Name
Salary "To_number(trim('$' FROM :Salary), '999,999.99')"
)
Can someone say what is wrong here or how to do it?
thanks in advance.
|
|
|
|
Re: To_number conversion [message #479283 is a reply to message #479279] |
Fri, 15 October 2010 15:08 |
simplesql
Messages: 20 Registered: October 2010
|
Junior Member |
|
|
I think u dint get it completely, I need to trim the $ symbol and then display it as a number.
However, I tried using To_char conversion as u suggested dint wrk. ... any other leads????
|
|
|
|
|
|
|
Re: To_number conversion [message #479590 is a reply to message #479294] |
Mon, 18 October 2010 08:11 |
simplesql
Messages: 20 Registered: October 2010
|
Junior Member |
|
|
Thanks Little foot. Your 'Char' description for the column in ctl file worked the magic...
sal char terminated by whitespace "to_number(:sal, '$999,999')"
I have a small problem with incoming file. The incoming file
has a zero vaule for the salary column but the zero is not enclosed in quotes.
1. Does this mean the salary is not a character and is a number here?
2. If so how should I modify my to_number statment???
NoTE:
sample data file ;
Sal
"$5,000 "
$0
"$10,000 "
'$350,000 "
I did a trim to remove the blank space after the sal amt.
|
|
|
Re: To_number conversion [message #479610 is a reply to message #479590] |
Mon, 18 October 2010 09:22 |
|
Barbara Boehmer
Messages: 9101 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
-- test.ctl:
load data
infile *
replace
into table test
fields terminated by whitespace
optionally enclosed by '"'
trailing nullcols
(sal char "to_number (replace (translate (:sal, '$,', ' '), ' '))")
begindata:
"$5,000 "
$0
"$10,000 "
"$350,000 "
SCOTT@orcl_11gR2> create table test
2 (sal number)
3 /
Table created.
SCOTT@orcl_11gR2> host sqlldr scott/tiger control=test.ctl log=test.log
SCOTT@orcl_11gR2> select * from test
2 /
SAL
----------
5000
0
10000
350000
4 rows selected.
SCOTT@orcl_11gR2>
|
|
|