Create sql loader data file dynamically
Hi,
I want a sample program/approach which is used to create a sql loader data file.
The program will read table name as i/p and will use
select stmt will column list derived from user_tab_columns from data dictionary
assuming multiple clob columns in the column list.
Thanks
Manoj
I 'm writing clob and other columns to a sql loader dat file.
Below sample code for writing clob column is giving file write error.
How can I write multiple clobs to dat file so that control file will handle it correctly
offset NUMBER := 1;
chunk VARCHAR2(32000);
chunk_size NUMBER := 32000;
WHILE( offset < dbms_lob.getlength(l_rec_type.narrative) )
LOOP
chunk := dbms_lob.substr(l_rec_type.narrative, chunk_size, offset );
utl_file.put( l_file_handle, chunk );
utl_file.fflush(l_file_handle);
offset := offset + chunk_size;
END LOOP;
utl_file.new_line(l_file_handle);
Similar Messages
-
Skipping fields in SQL*LOADER data file
I have a data file that has more fields than the target table does. How can I write a SQL*LOADER control file to skip some fields in the middle of the text line?
nullIf you don't want to define input fields by position, the simplest way I think is to use FILLER fields.
Quoted from SQL*Loader doc:
"Specifying Filler Fields
Filler fields have names but they are not loaded into the table. However, filler fields can be used as arguments to init_specs (for example, NULLIF and DEFAULTIF) as well as to directives (for example, SID, OID, REF, BFILE). Also, filler fields can occur anyplace in the data file. They can be inside of the field list for an object or inside the definition of a VARRAY.
See SQL*Loader DDL Behavior and Restrictions for more information on filler fields and their use.
A sample filler field specification looks as follows:
field_1_count FILLER char,
Ex:
Regards,
Zoltan -
Help in creating sql loader control file
I am having a csv file representing in this format. I have several lines like this
"XXX", "YYY","ZZZ","01/01/2005", "AAA"
So when I created the control file having, I am having problem with inserting the date.
I tried to you use the date column name
load data
infile x.cvt
into table table name
fields terminated by ","
colA
colB
colC
colD "TO_DATE(colD 'dd/mm/yyy')
does not seem to work. Please let me know what I am missing.
thanksIf you don't want to load the 5th field, you need to specify it as filler field in the control file
Load Data
Infile x.cvt
Into Table table name
Fields Terminated by ","
Optionally enclosed by '"'
(colA,
colB,
colC,
colD DATE "dd/mm/yyyy",
colE FILLER
)http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch06.htm#1006670
If you want to use the function to_date, don't forget the colon before the column name
Load Data
Infile x.cvt
Into Table table name
Fields Terminated by ","
Optionally enclosed by '"'
(colA,
colB,
colC,
colD char "TO_DATE(:colD 'dd/mm/yyyy')",
colE FILLER
)http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch06.htm#1008153
Message was edited by:
Jens Petersen -
SQL*Loader .dat file
Hello I am trying to migrate large quantities of data from our Access database to Oracle. I managed to generate my SQL*Loader scripts in the OMWB directory but when I try to run the .bat file a text doc is generated with the following message:
SQL*Loader-128: unable to begin a session
ORA-01017: Invalid username/password: logon denied
I have tried to match the username/password in both my OEM an OMWB with no success. Please does anybody know where I am going and how it can be rectified. Or should I recreate the user again via OMWB?
Thank you
[email protected]Pilton,
I assume the problem with the username and password which you are using to run.
And one more thing that check the session previleges on the user side.
Hope it will help you.
Ramesh
Hello I am trying to migrate large quantities of data from our Access database to Oracle. I managed to generate my SQL*Loader scripts in the OMWB directory but when I try to run the .bat file a text doc is generated with the following message:
SQL*Loader-128: unable to begin a session
ORA-01017: Invalid username/password: logon denied
I have tried to match the username/password in both my OEM an OMWB with no success. Please does anybody know where I am going and how it can be rectified. Or should I recreate the user again via OMWB?
Thank you
[email protected] -
Pre parse terrible SQL Loader data file
Long story, but I'm on Oracle EBS 11.5.10.2 which means i'm stuck with an SQL Loader from the dark ages (8.06 - yes, I know and yes, it's still supported under EBS).
Anyhow. I have a vendor sending very annoying data. For example:
\|"Fan-Hou" dessert|
\|"Donald is cool | yes”|
\|"Fred “is” cool | yes”|
Due to the limitations of such an old SQL Loader, I need to end up with:
\|"Fan-Hou dessert"|
\|"Donald is cool | yes”|
\|"Fred “is” cool | yes”|
So you can see that really it's only the first row which is causing the issue, I need to shift the quote out to the end of the string (just before the |). The other two lines are just for reference, to show that I get data like that too, and I need to be able to keep that as is.
I have a rather un-elegant solution solution using perl but I'm sure someone out there knows a clever way to achieve the same result. Before you ask - no, the vendor won't change the data.
Edited by: user13007502 on 07-May-2013 01:35There are probably various ways you can do that. I would try the SED command.
The idea is the following:
1. Replace all double quotes of words that start and end with a space with a special character.
2. Remove all all double quotes.
3. Add double quotes to the beginning and end.
4. Reconstruct double quotes of words according to 1.
For instance:
$ cat testfile
|"Fan-Hou" dessert|
|"Donald is cool | yes"|
|"Fred "is" cool | yes"|
Replace double quotes with {} for words that start and end with a space:
sed -i 's: "\(.*\)" : {\1} :g' testfile
$ cat testfile
|"Fan-Hou" dessert|
|"Donald is cool | yes"|
|"Fred {is} cool | yes"|
Remove all double quotes
$ sed -i 's:"::g' testfile
$ cat testfile
|Fan-Hou dessert|
|Donald is cool | yes|
|Fred {is} cool | yes|
Replace all lines that begin and end with | with |" and "|.
$ sed -i 's:^|:|":g' testfile
$ sed -i 's:\(.*\)|:\1"|:g' testfile
$ cat testfile
|"Fan-Hou dessert"|
|"Donald is cool | yes"|
|"Fred {is} cool | yes"|
Finally replace { and } with double qoutes:
sed -i 's:{:":g' testfile
sed -i 's:}:":g' testfile
Here is the result:
# cat testfile
|"Fan-Hou dessert"|
|"Donald is cool | yes"|
|"Fred "is" cool | yes"|
{code} -
Parameters / Variables in SQL Loader Control File
Here's my problem, I have created SQL Loader control file (ctl) to load a file of employees. This loader program is registered in Oracle Applications. What I want is to pass a parameter derived from the profile like the user name of the one who executed the loader program and pass it to the loader program so that the user name info is included in the loading
example
input data
123456,John,Smith
654321,Jane,Doe
loaded data
123456,John,Smith,03-JUL-2009,USER13
654321,Jane,Doe,03-JUL-2009,USER13
the sysdate is easy because it can be defined in the column but what I really want to achieve is a parameter passed to the ctl file.
Thanks in advance.Dear user!
Please have a look at this thread.
{thread:id=915277}
In the last three posts I explain how to use a shellscript with AWK and SED to pass parameters to a controlfile.
Please feel free to post again if you have some questions regarding my explanatory notes.
Yours sincerely
Florian W. -
READ XML file + XSD file to create an load data in a table
Hi gurus,
What way you will use to create and load data in a SQL TABLE by reading xml+xsd files.
Can you provide my a running example?
Is it better to stage the XML structure + XML data in the database before creating/loading the real SQL table. (the size of the XML file could me 1GB)See the FAQ..
For very large files make sure
1. Use FTP to load...
2. Ensure schema is registered with storeVarrayAsTable="true" and maintainDOM="false'
3. Install latest 10.2.0.3.0...
or
Look for SaxLoader example in the FAQ
-M -
Passing file name dynamically to sql loader ctl file
Hi,
I am new to scripting and I have a complex requirement involving writing a script.
Requierment:
I need to upload a CSV file from a FTP server into oracle table using SQL Loader. The file name resembles like APF0912312359.csv represents 31-DEC-2009 23:59 and there will be multiple files in same day indicated by differnt timestamp as its filename. Once I load a file using SQL loader, I need to move the file to another directory for archival.
Since the sql loader ctl file has a fixed file name, I would like to know how I can pass the file name dynamically to ctl file to load a new file every time it runs.
Any help is greatly appreciated..
Bye
Sudheer
Edited by: user2138419 on Oct 28, 2009 4:08 PMI agree with Pradeep in regards to declaring the file names on the command line. However, I do have a concern regarding presenting the password on the command line as any user that can issue a ps (assuming Unix ~= Linux here) would be able to read it while the sqlldr command is running.
Unfortunately, you may not always have the option of declaring the files on the command line. I was recently challenged with this in a Windows 2003 Server environment running SQL*Loader: Release 10.2.0.1.0. In this environment I found that I am able to set a variable file name in a calling batch file and use that value in the control file successfully. Just to demonstrate the approach:
Batch file:
set IN_FILE=’c:\inbound\load_me.txt’
sqlldr user/pswd@db PARFILE=’c:\parameters.txt’
Parameter file:
errors=500000
rows=50000
control=%CTL_FILE%
bad=%BAD_FILE%
discard=%DSC_FILE%
log=%LOG_FILE%
Control file:
LOAD DATA
INFILE ‘%IN_FILE%’
INSERT
INTO TABLE table_to_be_loaded
I’m really interested to see if this would work on Unix.
-Luke -
Way to generate sql*loader ctl file from a table?
I'm an oracle newbie. (Oracle 8i, HP Unix)Is there any way to take an existing table
description and generate a sql*loader control file from it? If anyone has already written a procedure or knows where one can be found I'd really appreciate it. We're doing a mass conversion to oracle and would like an easy way to re-write all our loads.
Thanks! Eileen from Polaroid.Hi,
I have shell program, which will get column names from system table and create temp. control file and call sqlloader exe. and load the data automatically.
You can customise this file, according to your needs.
Shell Program
if [ $# -ne 2 ]
then
echo " Usage : $0 table_name flat file name"
exit
fi
#assigning envir. variable to unix variables
table_name=$1
flat_file=$2
#creating the control file
echo "LOAD DATA" > $table_name.ctl
echo "INFILE '$flat_file'" >> $table_name.ctl
echo "into table $table_name " >> $table_name.ctl
echo "fields terminated by '\t'" >> $table_name.ctl
#calling functions for making column name part
#describing the table and spooling into file
sqlplus -s $CUST_ORA_USER << sql_block
spool $table_name.lst
desc $table_name
spool off
sql_block
# creating suitable file and add the feilds into control file
# cutting the first line (headings)
tail +3 $table_name.lst > temp
rm -f $table_name.lst
k=`wc -l < temp`
k1=`expr $k - 1`
#cutting the last line
head -$k1 temp > tempx
record_count=`wc -l < tempx`
counter=1
echo "(" > wxyz.ctl
# reading file line by line
cat tempx | while in_line=`line`
do
#cutting the first field
field_name=`echo $in_line | cut -f1 -d' '`
#calculating the no of characters
word_cnt=`echo $in_line | wc -w`
#calculating count in a line
if [ $word_cnt = 2 ]
then
data_type=`echo $in_line | cut -f2 -d' ' | cut -f1 -d'('`
if [ "$data_type" = "DATE" ]
then
data_fmt="DECODE(LENGTH(LTRIM(RTRIM(:$field_name))),'11',to_date(ltrim(rtrim(:$field_name)),'dd-mon-yyyy'),'9',to_date(ltrim(rtrim(:$field_name)),'dd-mm-yy'),'10',to_date(ltrim(rtr im(:$field_name)),'dd-mon-yy'),'yyyy/mm/dd hh24:mi:ss')"
elif [ "$data_type" = "CHAR" ]
then
data_fmt="NVL(RTRIM(LTRIM(:$field_name)),' ')"
elif [ "$data_type" = "VARCHAR2" ]
then
data_fmt="NVL(RTRIM(LTRIM(:$field_name)),' ')"
else
data_fmt="NVL(:$field_name,0) "
fi
else
data_type=`echo $in_line | cut -f4 -d' ' | cut -f1 -d'('`
if [ "$data_type" = "DATE" ]
then
data_fmt="DECODE(LENGHTH(LTRIM(RTRIM(:$field_name))),'11',to_date(ltrim(rtrim(:$field_name)),'dd-mon-yyyy'),'9',to_date(ltrim(rtrim(:$field_name)),'dd-mm-yy'),'10',to_date(ltrim(rt rim(:$field_name)),'dd-mon-yy'),'yyyy/mm/dd hh24:mi:ss')"
elif [ "$data_type" = "CHAR" ]
then
data_fmt="NVL(RTRIM(LTRIM(:$field_name)),' ')"
elif [ "$data_type" = "VARCHAR2" ]
then
data_fmt="NVL(RTRIM(LTRIM(:$field_name)),' ')"
else
data_fmt="NVL(:$field_name,0) "
fi
fi
#if last line put );
#else ,
if test $record_count -eq $counter
then
echo $field_name \"$data_fmt\"");" >> wxyz.ctl
else
echo $field_name \"$data_fmt\""," >> wxyz.ctl
fi
#counter increamenting for each record
counter=`expr $counter + 1`
done
#removing the file
rm -f temp tempx
cat wxyz.ctl >> $table_name.ctl
rm -f x.ctl
#calling the SQLLOADER
SQLLDR $CUST_ORA_USER CONTROL=$table_name.ctl ERROR=99999999
#removing the control file
rm -f $table_name.ctl -
Problem specifying SQL Loader Log file destination using EM
Good evening,
I am following the example given in the 2 Day DBA document chapter 8 section 16.
In step 5 of 7, EM does not allow me to specify the destination of the SQL Loader log file to be on a mapped network drive.
The question: Does SQL Loader have a limitation that I am not aware of, that prevents placing the log file on a network share or am I getting this error because of something else I am inadvertently doing wrong ?
Note: I have placed the DDL, load file data and steps I follow in EM at the bottom of this post to facilitate reproducing the problem *(drive Z is a mapped drive)*.
Thank you for your help,
John.
DDL (generated using SQL developer, you may want to change the space allocated to be less)
CREATE TABLE "NICK"."PURCHASE_ORDERS"
"PO_NUMBER" NUMBER NOT NULL ENABLE,
"PO_DESCRIPTION" VARCHAR2(200 BYTE),
"PO_DATE" DATE NOT NULL ENABLE,
"PO_VENDOR" NUMBER NOT NULL ENABLE,
"PO_DATE_RECEIVED" DATE,
PRIMARY KEY ("PO_NUMBER") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS NOCOMPRESS LOGGING TABLESPACE "USERS" ENABLE
SEGMENT CREATION DEFERRED PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
INITIAL 67108864
TABLESPACE "USERS" ;
Load.dat file contents
1, Office Equipment, 25-MAY-2006, 1201, 13-JUN-2006
2, Computer System, 18-JUN-2006, 1201, 27-JUN-2006
3, Travel Expense, 26-JUN-2006, 1340, 11-JUL-2006
Steps I am carrying out in EM
log in, select data movement -> Load Data from User Files
Automatically generate control file
(enter host credentials that work on your machine)
continue
Step 1 of 7 ->
Data file is located on your browser machine
"Z:\Documentation\Oracle\2DayDBA\Scripts\Load.dat"
click next
step 2 of 7 ->
Table Name
nick.purchase_orders
click next
step 3 of 7 ->
click next
step 4 of 7 ->
click next
step 5 of 7 ->
Generate log file where logging information is to be stored
Z:\Documentation\Oracle\2DayDBA\Scripts\Load.LOG
Validation Error
Examine and correct the following errors, then retry the operation:
LogFile - The directory does not exist.Hi John,
But, i did'nt found any error when i am going the same what you did.
My Oracle Version is 10.2.0.1 and using Windows xp. See what i did and i got worked
1.I created one table in scott schema :
SCOTT@orcl> CREATE TABLE "PURCHASE_ORDERS"
2 (
3 "PO_NUMBER" NUMBER NOT NULL ENABLE,
4 "PO_DESCRIPTION" VARCHAR2(200 BYTE),
5 "PO_DATE" DATE NOT NULL ENABLE,
6 "PO_VENDOR" NUMBER NOT NULL ENABLE,
7 "PO_DATE_RECEIVED" DATE,
8 PRIMARY KEY ("PO_NUMBER") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS NOCOMPRESS LOGGING TABLESPACE "USERS" ENABLE
9 )
10 TABLESPACE "USERS";
Table created.I logged into em Maintenance-->Data Movement-->Load Data from User Files-->My Host Credentials
Here i total 3 text boxes :
1.Server Data File : C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS01.DBF
2.Data File is Located on Your Browser Machine : z:\load.dat <--- Here z:\ means other machine's shared doc folder; and i selected this option (as option button click) and i created the same load.dat as you mentioned.
3.Temporary File Location : C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\ <--- I did'nt mentioned anything.
Step 2 of 7 Table Name : scott.PURCHASE_ORDERS
Step 3 of 7 I just clicked Next
Step 4 of 7 I just clicked Next
Step 5 of 7 I just clicked Next
Step 6 of 7 I just clicked Next
Step 7 of 7 Here it is Control File Contents:
LOAD DATA
APPEND
INTO TABLE scott.PURCHASE_ORDERS
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
PO_NUMBER INTEGER EXTERNAL,
PO_DESCRIPTION CHAR,
PO_DATE DATE,
PO_VENDOR INTEGER EXTERNAL,
PO_DATE_RECEIVED DATE
And i just clicked on submit job.
Now i got all 3 rows in purchase_orders :
SCOTT@orcl> select count(*) from purchase_orders;
COUNT(*)
3So, there is no bug, it worked and please retry if you get any error/issue.
HTH
Girish Sharma -
How to call sql loader ctrl file with in the pl/sql procedure
Hi Friends,
I am doing a project related with the transferring data using queues. In the queue , I will get a tab delimited data in the form of CLOB variable/message. I do want to store that dat in the oracle table.
When updating data into the table ,
1. Don't want to write that data into a file.( Want to access directly after dequeueing from the specfic queue).
2. As the data is in tab delimited form, I want to use sql loader concept.
How do I call the sql loader ctrl file with in my pl/sql procedure. When I searched , most of the forums recommending external procedure or Java program.
Please Guide me on this issue. my preferrence is pl sql, But don't know about external procedure . If no other way , I will try Java.
I am using oracle 9.2.0.8.0.
Thanks in advance,
Vimal..Neither SQL*Loader nor external tables are designed to read data from a CLOB stored in the database. They both work on files stored on the file system. If you don't want the data to be written to a file, you're going to have to roll your own parsing code. This is certainly possible. But it is going to be far less efficient than either SQL*Loader or external tables. And it's likely to involve quite a bit more code.
The simplest possible thing that could work would be to use something like Tom Kyte's string tokenization package to read a line from the CLOB, break it into the component pieces, and then store the different tokens in a meaningful collection (i.e. an object type or a record type that corresponds to the table definition). Of course, you'll need to handle things like converting strings to numbers or dates, rejecting rows, writing log files, etc.
Justin -
Define variable in SQL Loader Control File
Hi,
I have an input file where the first line is the header record, followed by the detail records. For the processing, I do not need to store the fields of the header record but I need a date field from this header record and store in as part of the detail record in an oracle record row.
Is it possible to define a variable within the sql loader control file to store the value that I need in memory then use it when I do the sql insert by the sql loader?
Thanks for any advice.Not sure that you can. But if your on unix/linux/mac its easy enough to write a shell script to populates the variables in a template file that you can then use as the ctl file. The perl template toolkit could be an option for that as well
-
Add "Trailing Nullcolls" to sql loader control files generated by OWB
Hi gurus,
I've got a problem loading data with SQL Loader. I need to add the parameter "trailing nullcols" into the SQL Loader control file generated by OWB. I don't want to do this by saving the skript on my hard disk and run it manually, so any ideas where I can put this parameter? I am using OWB 10.1 on a windows 2000 machine.
Thanks
StephanHi,
I found the solution to problem.
1; Select the mapping where you map your source flat file to a table.
2; Right click on the mapping and select "configure"
3; Go Sources and Targets -> YOUR_TABLE_NAME -> SQL*Loader Parameters
4; Set Trailing Nullcols = true :-)
Thank you to anyone looking at this problem.
Greetings
Stephan -
System Center 2012 R2 install: SQL server Data file and log file
This might be a dumb question, but I can't find the answer anywhere.
I'm installing a new instance of System Center 2012 R2 on a new server, I'm stuck on the SQL Server data file section. Everytime I put in a path, it says that tne path does not exist. I'm I supposed to be creating some sort of SQL Server
data file and log file before this installation, I didn't get this prompt when installing System Center 2012 SP1 or hen I upgraded from System Center 2012 SP1 to System Center 2012 R2
My SQL is on a different server
Thank you in advancedHave you reviewed the setup.log?
On a side note, why would you put the database file on the same drive as the OS? That defeats the whole purpose of having a remote SQL Server. Why use a remote SQL Server in the first place.
Jason | http://blog.configmgrftw.com -
Creating SQL-Loader script for more than one table at a time
Hi,
I am using OMWB 2.0.2.0.0 with Oracle 8.1.7 and Sybase 11.9.
It looks like I can create SQL-Loader scripts for all the tables
or for one table at a time. If I want to create SQL-Loader
scripts for 5-6 tables, I have to either create script for all
the tables and then delete the unwanted tables or create the
scripts for one table at a time and then merge them.
Is there a simple way to create migration scripts for more than
one but not all tables at a time?
Thanks,
Prashant RaneNo there is no multi-select for creating SQL-Loader scripts.
You can either create them separately or create them all and
then discard the one you do not need.
Maybe you are looking for
-
Control user access in SOA Suite 11.1.1.2 Console
Hi All, We recently migrated our application from SOA Suite 11.1.1.1 to 11.1.1.2 . In 1.1 we had an end user account assigned to the Monitor group which could access the middleware console and view composite flows but could not deploy/undeploy or ret
-
Music cd not showing up in iMovie
I am used to earlier versions of iMovie importing music from CDs by simply popping the cd in and it auto pops up in the audio window. This is not happening on my intel mac. I can put in a cd but nothing happens. I have found that I can import the tra
-
Hi we are trying to install the gateway service. It installs correct but when starting it returns this error: Portal Server Gateway cannot get started. Configuration for specified profile does not exist! But the profile for this gateway does exsist o
-
Deleted sales Document - Unique issue
Hi Experts, We have created a contract (VA41)in the system, but failed to save or deleted by somebody. How can I see the document whether it is deleted? I treid with tables Tables CDHDR, CDPOS Use Change doc. Obje = VERKBELEG (sales documents) But no
-
Image to mpeg / create mpeg
Hello. Recently I wrote a small vi to take a 3d array of binary images and convert it to avi format. I have been asked to research and find out if it is possible to convert an array of images to mpeg as well. I am aware of freeware that is availab