LOAD DATA IN ORACLE - oracle

Hi am trying to use load data in oracle. if am using
LINES TERMINATED BY '<>'
it is throwing
SQL*Loader-350: Syntax error at line 1.
Expecting "(", found "LINES".
why it is happening .whether there is no LINES teminated by clause in oracle?

I think LINES TERMINATED is not defined in ORACLE; check Stream Record Format from the ORACLE documentation:
A file is in stream record format when the records are not specified
by size; instead SQL*Loader forms records by scanning for the record
terminator. Stream record format is the most flexible format, but
there can be a negative effect on performance. The specification of a
datafile to be interpreted as being in stream record format looks
similar to the following: INFILE datafile_name ["str
terminator_string"]
Example:
load data
infile 'example.dat' "str '|\n'"
into table example
fields terminated by ',' optionally enclosed by '"'
(col1 char(5),
col2 char(7))
example.dat:
hello,world,|
james,bond,|
See http://docs.oracle.com/cd/B19306_01/server.102/b14215/ldr_concepts.htm for more.

Related

Load string data that does not have quotes to Hive

I'm trying to load some test data to a simple Hive table. The data is comma separated, but the individual elements are not enclosed in double quotes. I'm getting an error due to this. How do I tell Hive not to expect varchar fields to be enclosed in quotes. Manually adding quotes to varchar fields is not an option since the input file I'm trying to use has thousands of records. Sample query and data below.
create table mydatabase.flights(FlightDate varchar(10),Airline int,FlightNum int,Origin varchar(4),Destination varchar(4),Departure varchar(4),DepDelay double,Arrival varchar(4),ArrivalDelay double,Airtime double,Distance double) row format delimited;
insert into mydatabase.flights(FlightDate,Airline,FlightNum,Origin,Destination,Departure,DepDelay,Arrival,ArrivalDelay,Airtime,Distance)
values(2014-04-01,19805,1,JFK,LAX,0854,-6.00,1217,2.00,355.00,2475.00);
The insert query above gives me an error message. It works fine if I enclose the varchar fields in quotes.
Error while compiling statement: FAILED: ParseException line 11:11 mismatched input '-' expecting ) near '2014' in value row constructor
I'm loading data using the following query
load data inpath '/user/alpsusa/hive/flights.csv' overwrite into table mydatabase.flights;
After load, I see only the first field being loaded. Rest all are NULL.
Sample data
2014-04-01,19805,1,JFK,LAX,0854,-6.00,1217,2.00,355.00,2475.00
2014-04-01,19805,2,LAX,JFK,0944,14.00,1736,-29.00,269.00,2475.00
2014-04-01,19805,3,JFK,LAX,1224,-6.00,1614,39.00,371.00,2475.00
2014-04-01,19805,4,LAX,JFK,1240,25.00,2028,-27.00,264.00,2475.00
2014-04-01,19805,5,DFW,HNL,1300,-5.00,1650,15.00,510.00,3784.00
Below is the output of DESCRIBE FORMATTED

Multiple Line - Multiple CLOB per line SQL Loader

I'm finding myself in a predicament.
I am parsing a logfile of multiple entries of SOAP calls. Each soap call can contain payloads of 4000+ characters preventing me to use varchar2. So I must use a CLOB)
I have to load those payloads onto a oracle DB (12g).
I succesfully split the log into single fields and got the payloads and the header of the calls in two single files.
How do I create a CTL file that loads from an infile (that contains data for other fields) and reads CLOB files in pairs?
Ideally:
LOAD DATA
INFILE 'load.ldr'
BADFILE 'load.bad'
APPEND
INTO TABLE ops_payload_tracker
FIELDS TERMINATED BY 'ยง'
TRAILING NULLCOLS
( id,
direction,
http_info,
payload CLOB(),
header CLOB(),
host_name)
but then I don't know, and can't find anywhere on the internet, how to do it for more than one record and how to reference that one record with two CLOBS.
Worth mentioning that it is JBOSS logs, on bash environment.
check size of varchar type in 12c. I thought it was increased to 32K
https://oracle-base.com/articles/12c/extended-data-types-12cR1
see that sample SQL Loader, CLOB, delimited fields
"I already create two separate files for payload and headers. How
should I specify that the two files are there for the same ID?"
see example here:
https://oracle-base.com/articles/10g/load-lob-data-using-sql-loader
roughly:
sample table
1,one,01-JAN-2006,1_clob_header.txt,2_clob_details.txt
2,two,02-JAN-2006,2_clob_heder.txt,2_clob_details.txt
ctl
LOAD DATA
INFILE 'lob_test_data.txt'
INTO TABLE lob_tab
FIELDS TERMINATED BY ','
(number_content CHAR(10),
varchar2_content CHAR(100),
date_content DATE "DD-MON-YYYY" ":date_content",
clob_filename FILLER CHAR(100),
clob_content LOBFILE(clob_filename) TERMINATED BY EOF,
blob_filename FILLER CHAR(100),
blob_content LOBFILE(blob_filename) TERMINATED BY EOF)

Select statement in hive return some columns with null value

I have seen this type of questions were asked many times, but those solutions not worked for me. I created a external hive table, since i had the data is from map-only job output. Then, by load command i given the path for the specific file. It showed ok. But when i give select * from table command it returns some column with null values. Each command i have executed is in the error pic.
My delimiter in file is ||, so i mentioned the same in create table command too.
Here is my input file pic file pic. And here is the error pic
. I have also tried a normal table instead of external table. That too showed the same error. I also tried by mentioning delimiter as //|| and also \|\|. But none worked.
The problem that you are facing is related to multiple characters as FIELD delimiter.
According to documentation FIELD delimiter should be a CHAR
row_format
: DELIMITED [FIELDS TERMINATED BY char [ESCAPED BY char]] [COLLECTION ITEMS TERMINATED BY char]
[MAP KEYS TERMINATED BY char] [LINES TERMINATED BY char]
[NULL DEFINED AS char] -- (Note: Available in Hive 0.13 and later)
You need to change your data to have only single char field delimiter.
If you can not do that then the other approach is to use stage table with single field. Load your data to that table and then in your actual target table, split the column in stage table by || delimiter and then insert. You need to make sure that field counts are consistent in the data otherwise your final output will be off.
Reference:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTableCreate/Drop/TruncateTable

sqlldr : Could I use the comma delimiter field terminate and optional enclose simultaneously?

I have a CSV file that contains a list of famous singers in the world. I want to import this file to Oracle DB using SQLLDR.
Contains of singers.csv is:
number,name,follower
1,Prince,100
2,Ludacris,100
3,Bruno Mars,100
4,Madonna,100
5,Miley,Cyrus,100
6,Britney,Spears,100
control.ctl
OPTIONS (SKIP=0, errors=12000)
LOAD DATA
APPEND INTO TABLE singers_tb
FIELDS TERMINATED BY ","
optionally enclosed by '"'
TRAILING NULLCOLS
(number ":number", name "TRIM (:name)",follower ":follower")
singers_tb
create singers_tb (
number varchar2(3),
name varchar2(255),
follower number
)
error message
Record 5: Rejected - Error on table singers_tb, column FOLLOWER.
ORA-01722: invalid number
Record 6: Rejected - Error on table singers_tb, column FOLLOWER.
ORA-01722: invalid number
I know the cause of the error is the comma (,) on Britney,Spears and Miley,Cyrus.
How to solve these problems if I still want to use FIELDS TERMINATED BY "," ?
Thanks you very much for your suggestion.
Your control file already has: optionally enclosed by '"'.
Make sure the data provider indeed provides that any field containing your delimiter arrive surrounded by double quotes.

SQLLDR -- selective loading from pipe delimited txt

I am looking for a way to do selective loading using SQLLDR.
The source file is in "pipe delimited" format.
I know there is a way for this if the source is in a predefined position. It is explained here, by using WHEN & POSITION keywords.
What could I do if the source file is "pipe or tab" delimited?
I am not sure what you mean with "selective loading"?
But ify you are only asking how you can load a file where each column is delimited with a pipe, then use the option FIELDS TERMINATED BY '|' in the control file.
See the chapter "Variable Record Format" in the SQL*Loader manual for more details and examples:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_concepts.htm#sthref476
Depending on which version of the SQLLDR version you are using, you can use the keyword FILLER to skip a field from the file.
The below instruction will skip the second field in the file.
LOAD DATA
TRUNCATE INTO TABLE T1
FIELDS TERMINATED BY ','
( field1,
field2 FILLER,
field3
)
LOAD DATA
INFILE 'c:\myfile.txt'
TRUNCATE INTO TABLE T1
FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS (field1, field2 , field3, field4)

Resources