SQL Loader Username in control file
Hi,
Im using SQL Loader to load data. Im going to execute this from a UNIX shell script.
Here, I have to pass UNIX user name and Oracle user name in the control file.
How and I do it?.
Thanks,
Kannan
Prashant Tejwani wrote:
Yup.
Now i get it.
You want to load the username of the person who is executing sql loader to load the data in table.
Right?
Well, for Oracle Username you can use:
EMP_ID CHAR(10),
EMP_NAME CHAR(40),
UPD_DATE "SYSDATE",
ORACLE_USER_NAME "user",
UNIX_USER_NAME "????????"
I am not sure if we can pass UNIX username because once we execute SQL loader, control file will be executed in Database environment and i dont think any unix syntaxes will hold good there.To achieve the unix username would require the unix script to generate the control file on-the-fly providing the unix username as a fixed value in the control file before it calls sql*loader with that generated control file.
Similar Messages
-
SQL Loader tool for control file creation
We are planning to use SQL*Loader to move a lot of data from mainframe to Oracle 10g database. We will write the data in flat files and use SQL*Loader to load these files into tha database. There are more than 100 tables with lot of columns in each. So, I was just wondering if there is any tool available (visual mappings etc.) that can help create the control files for the SQL*Loader, so that I don't have to manually type all the lengthy control files
Thanks for any help,
Samsql*loader is capable to generate the controlfile for external tables which are pretty much the same
Something like
sqlldr scott/tiger ulcase1 EXTERNAL_TABLE=GENERATE_ONLYhttp://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch08.htm#1006964 -
I use SQL Loader to read a file into a table. In my tests a lot of rows are rejected and written to the bad file. But there are no error messages.
Is there a way to find out why the row was rejected.The Bad File
The bad file contains records that were rejected, either by SQL*Loader or by the Oracle database server. Some of the possible reasons for rejection are discussed in the next sections.
SQL*Loader Rejects
Datafile records are rejected by SQL*Loader when the input format is invalid. For example, if the second enclosure delimiter is missing, or if a delimited field exceeds its maximum length, SQL*Loader rejects the record. Rejected records are placed in the bad file.
Oracle Rejects
After a datafile record is accepted for processing by SQL*Loader, it is sent to the Oracle database server for insertion into a table as a row. If the Oracle database server determines that the row is valid, then the row is inserted into the table. If the row is determined to be invalid, then the record is rejected and SQL*Loader puts it in the bad file. The row may be invalid, for example, because a key is not unique, because a required field is null, or because the field contains invalid data for the Oracle datatype.
YOU WILL get more information
sqlldr help=y
also send your control file syntax
kuljeet pal singh -
Load data through control file
Hi ,
I am the first time loading data ,
My table definition:
<pre>
SQL> desc t;
Name Null? Type
ID NUMBER
NAME VARCHAR2(35)
And my csv file data:
id name
1 5.0315
2 3.2645
3 1.4975
4 -0.2695
5 -2.0365
And my control file:
load data
infile "c:\lddata.csv"
into table t truncate
fields terminated by ','
(id,
name
When I run in sql*plus I am getting this error:
SQL> @c:\lddata.ctl
SP2-0042: unknown command "load data" - rest of line ignored.
SP2-0734: unknown command beginning "infile "c:..." - rest of line ignored.
SP2-0734: unknown command beginning "into table..." - rest of line ignored.
SP2-0734: unknown command beginning "fields ter..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
4
</pre> --how to use this pre tag pls
How should over come this error.
pls,
Thanks,SQL*Loader has to run from OS command prompt as
<br>
<br>
sqlldr username/password control=<control_file>...
<br>
<br>
Read more here
<br>
<br>
[pre] and [/pre] tags -
SQL Loader and weird source file structure
I am familiar with using SQL Loader to process comma or tab delimited text files into proper table data. But how do you process "positionally delimited" files?!
I mean, I have a text file which looks like this:
Item A
---attribute1
---attribute2
---attribute3
---attribute4
Item B
---attribute1
---attribute2
---attribute3
---attribute4
Item C
---attribute1
---attribute2
---attribute3
---attribute4
And so on. How do I tell SQL Loader, 'rows 1, 6 and 11 are the first column in the table; rows 2, 7 and 12 and the second column; rows 3, 8, 13 are the third and so on? I want to end up with data in the form
Item A Attribute1 Attribute2 Attribute3 Attribute 4
Item B Attribute1 Attribute2 Attribute3 Attribute 4
Item C Attribute1 Attribute2 Attribute3 Attribute 4
Is such a thing even possible with SQL Loader?If your data is exactly in that format like in sample provided by Enrique, you can try to play with that certain data pattern. Again, based on previous example:
~ >cat data.dat
map1
615050: ( 95, 83, 68) #5F5344 rgb(95,83,68)
605728: ( 36, 27, 22) #241B16 rgb(36,27,22)
225834: (154,107, 84) #9A6B54 rgb(154,107,84)
176305: (218,187,155) #DABB9B rgb(218,187,155)
141083: (188,142,111) #BC8E6F rgb(188,142,111)
map2
615050: ( 95, 83, 68) #5F5344 rgb(95,83,68)
605728: ( 36, 27, 22) #241B16 rgb(36,27,22)
225834: (154,107, 84) #9A6B54 rgb(154,107,84)
176305: (218,187,155) #DABB9B rgb(218,187,155)
141083: (188,142,111) #BC8E6F rgb(188,142,111)
map3
615050: ( 95, 83, 68) #5F5344 rgb(95,83,68)
605728: ( 36, 27, 22) #241B16 rgb(36,27,22)
225834: (154,107, 84) #9A6B54 rgb(154,107,84)
176305: (218,187,155) #DABB9B rgb(218,187,155)
141083: (188,142,111) #BC8E6F rgb(188,142,111)
~ >cat data.ctl
LOAD DATA
INFILE "data.dat" "str '\nm'"
DISCARDFILE "data.dsc"
DISCARDMAX 999
REPLACE
-- CONCATENATE 6
INTO TABLE data
fields terminated by X'0a' trailing nullcols
( item char "replace('m'||:item,'mm','m')",
attrib1 char,
attrib2 char,
attrib3 char,
attrib4 char,
attrib5 char
~ >sqlplus scott/tiger
SQL*Plus: Release 10.2.0.4.0 - Production on Wed Oct 15 16:27:25 2008
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select count(*) from data;
COUNT(*)
0
SQL> !sqlldr userid=scott/tiger control=data.ctl
SQL*Loader: Release 10.2.0.4.0 - Production on Wed Oct 15 16:28:29 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Commit point reached - logical record count 2
Commit point reached - logical record count 3
SQL> col item for a4
SQL> col attrib1 for a50
SQL> col attrib2 for a50
SQL> select item,attrib1,attrib2 from data;
ITEM ATTRIB1 ATTRIB2
map1 615050: ( 95, 83, 68) #5F5344 rgb(95,83,68) 605728: ( 36, 27, 22) #241B16 rgb(36,27,22)
map2 615050: ( 95, 83, 68) #5F5344 rgb(95,83,68) 605728: ( 36, 27, 22) #241B16 rgb(36,27,22)
map3 615050: ( 95, 83, 68) #5F5344 rgb(95,83,68) 605728: ( 36, 27, 22) #241B16 rgb(36,27,22)
SQL>As you see, i loaded on linux, on windows you may slightly adjust controlfile to reflect end of lines...
Best regards
Maxim -
SQL Loader - Field in data file exceeds maximum length
Dear All,
I have a file which has more than 4000 characters in a field and I wish to load the data in a table with field length = 4000. but I receive error as
Field in data file exceeds maximum lengthThe below given are the scripts and ctl file
Table creation script:
CREATE TABLE "TEST_TAB"
"STR" VARCHAR2(4000 BYTE),
"STR2" VARCHAR2(4000 BYTE),
"STR3" VARCHAR2(4000 BYTE)
);Control file:
LOAD DATA
INFILE 'C:\table_export.txt'
APPEND INTO TABLE TEST_TAB
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS
( STR CHAR(4000) "SUBSTR(:STR,1,4000)" ,
STR2 CHAR(4000) "SUBSTR(:STR2,1,4000)" ,
STR3 CHAR(4000) "SUBSTR(:STR3,1,4000)"
)Log:
SQL*Loader: Release 10.2.0.1.0 - Production on Mon Jul 26 16:06:25 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Control File: C:\TEST_TAB.CTL
Data File: C:\table_export.txt
Bad File: C:\TEST_TAB.BAD
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 0
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional
Table TEST_TAB, loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
STR FIRST 4000 | CHARACTER
SQL string for column : "SUBSTR(:STR,1,4000)"
STR2 NEXT 4000 | CHARACTER
SQL string for column : "SUBSTR(:STR2,1,4000)"
STR3 NEXT 4000 | CHARACTER
SQL string for column : "SUBSTR(:STR3,1,4000)"
value used for ROWS parameter changed from 64 to 21
Record 1: Rejected - Error on table TEST_TAB, column STR.
Field in data file exceeds maximum length
MAXIMUM ERROR COUNT EXCEEDED - Above statistics reflect partial run.
Table TEST_TAB:
0 Rows successfully loaded.
1 Row not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Space allocated for bind array: 252126 bytes(21 rows)
Read buffer bytes: 1048576
Total logical records skipped: 0
Total logical records read: 1
Total logical records rejected: 1
Total logical records discarded: 0
Run began on Mon Jul 26 16:06:25 2010
Run ended on Mon Jul 26 16:06:25 2010
Elapsed time was: 00:00:00.22
CPU time was: 00:00:00.15Please suggest a way to get it done.
Thanks for reading the post!
*009*Hi Toni,
Thanks for the reply.
Do you mean this?
CREATE TABLE "TEST"."TEST_TAB"
"STR" VARCHAR2(4001),
"STR2" VARCHAR2(4001),
"STR3" VARCHAR2(4001)
);However this does not work as the error would be:
Error at Command Line:8 Column:20
Error report:
SQL Error: ORA-00910: specified length too long for its datatype
00910. 00000 - "specified length too long for its datatype"
*Cause: for datatypes CHAR and RAW, the length specified was > 2000;
otherwise, the length specified was > 4000.
*Action: use a shorter length or switch to a datatype permitting a
longer length such as a VARCHAR2, LONG CHAR, or LONG RAW*009*
Edited by: 009 on Jul 28, 2010 6:15 AM -
SQL loader Field in data file exceeds maximum length for CLOB column
Hi all
I'm loading data from text file separated by TAB and i got the error below for some lines.
Event the column is CLOB data type is there a limitation of the size of a CLOB data type.
The error is:
Record 74: Rejected - Error on table _TEMP, column DEST.
Field in data file exceeds maximum length
I'm using SQL Loader and the database is oracle 11g r2 on linux Red hat 5
Here are the line causing the error fronm my data file and my table description for test:
create table TEMP
CODE VARCHAR2(100),
DESC VARCHAR2(500),
RATE FLOAT,
INCREASE VARCHAR2(20),
COUNTRY VARCHAR2(500),
DEST CLOB,
WEEK VARCHAR2(10),
IS_SAT VARCHAR2(50),
IS_SUN VARCHAR2(50)
CONTROL FILE:
LOAD DATA
INTO TABLE TEMP
APPEND
FIELDS TERMINATED BY X'9' TRAILING NULLCOLS
CODE,
DESC,
RATE,
INCREASE,
COUNTRY),
DEST,
WEEK,
IS_SAT,
IS_SUN
Data file:
BHS Mobile Bahamas - Mobile 0.1430 1 "242357, 242359, 242375, 242376, 242395, 242421, 242422, 242423, 242424, 242425, 242426, 242427, 242428, 242429, 242431, 242432, 242433, 242434, 242435, 242436, 242437, 242438, 242439, 242441, 242442, 242443, 242445, 242446, 242447, 242448, 242449, 242451, 242452, 242453, 242454, 242455, 242456, 242457, 242458, 242462, 242463, 242464, 242465, 242466, 242467, 242468, 24247, 242524, 242525, 242533, 242535, 242544, 242551, 242552, 242553, 242554, 242556, 242557, 242558, 242559, 242565, 242577, 242636, 242646, 242727"
BOL Mobile ENTEL Bolivia - Mobile Entel 0.0865 Increase 591 "67, 68, 71, 72, 73, 740, 7410, 7411, 7412, 7413, 7414, 7415, 7420, 7421, 7422, 7423, 7424, 7425, 7430, 7431, 7432, 7433, 7434, 7435, 7436, 7437, 7440, 7441, 7442, 7443, 7444, 7445, 7450, 7451, 7452, 7453, 7454, 7455, 746, 7470, 7471, 7472, 7475, 7476, 7477, 7480, 7481, 7482, 7483, 7484, 7485, 7486, 7490, 7491, 7492, 7493, 7494, 7495, 7496" Thank you.Hi
Thank you for youe help, I found the solution and here what i do in my Control file i added
char(40000) OPTIONALLY ENCLOSED BY '"' .
LOAD DATA
INTO TABLE TEMP
APPEND
FIELDS TERMINATED BY X'9' TRAILING NULLCOLS
CODE,
DESC,
RATE,
INCREASE,
COUNTRY,
DEST
char(40000) OPTIONALLY ENCLOSED BY '"',
WEEK,
IS_SAT,
IS_SUN
Thank you for your help. -
SQL*Loader to insert data file name during load
I'd like to use a single control file to load data from different files (at different times) to the same table. I'd like this table to have a column to hold the name of the file the data came from. Is there a way for SQL*Loader to automatically do this? (I.e., as opposed to running an update query separately.) I can edit the control file before each load to set a CONSTANT to hold the new data file name, but I'd like it to pick this up automatically.
Thanks for any help.
-- HarveyHello Harvey.
I've previously attempted to store a value into a global/local OS variable and use this within a SQL*Loader control file (Unix OS and Oracle versions between 7.3.4 and 10g). I was unsuccessful in each attempt and approach I could imagine. It was very easy to use a sed script to make a copy of the control file, changing a string within it to do this however.
Do you really want to store a file name on each and every record? Perhaps an alternative would be to use a relational model. Create a file upload log table that would store the file name and an upload # and then have the SQL*Loader control file call a function that would read that table for the most recent upload #. You'll save some disk space too.
Hope this helps,
Luke -
How to load data using Control File in BW 7
Hi All,
I have a requirement to load data in BW using control file. The development is done in in BW 7.0. In BW 3.5 in infopackage, there is an option of FILE IS ( Control File or Data File ). Please suggest how to simulate the same in BW 7.0
Regards,
VikramAny suggestions?
-
Sql loader how import a file with save the actual row number in a db field
Hey,
how can i save the row number for each row in a file into a database field i the same table with the sql loader (sqlldr)?
test data:
john doe
joe meier
table:
name surname line_number_in_file
john doe 1
joe meier 2
and so on ... an if an line is discarded because it is empty for example it should be as this:
test data:
john doe
joe meier
table:
name surname line_number_in_file
john doe 1
joe meier 3
thanks for helpinmg and excuse my very bad english :-)
Message was edited by:
user527827but if one of the when clause faild or some rows are
rejectet the sequence is not right.Did you read the link?
"If a record is rejected (that is, it has a format error or causes an Oracle error), the generated sequence numbers are not reshuffled to mask this. If four rows are assigned sequence numbers 10, 12, 14, and 16 in a particular column, and the row with 12 is rejected, the three rows inserted are numbered 10, 14, and 16, not 10, 12, and 14. This allows the sequence of inserts to be preserved despite data errors. When you correct the rejected data and reinsert it, you can manually set the columns to agree with the sequence."
also if you read multiple lines and they inserted in
the wrong order the number from the sequence is not
the line number...what do you mean with "reading multiple lines and wrong order?" -
Can we schedule Loader Jobs (SQL Loader) using Grid Control ?
Can we schedule SQL Loaders jobs/process using Grid Control for 11g database ?
Or
Is it good to schedule it as external jobs using DBMS_SCHEDULER ?
OS is LINUX. Database is 11g R1 Grid Control will be the latest, I believe 10gR3.
Any other suggestions... (I know it can be done using OS utilities like cron and others but that is not an option for now.)
Thanks in advance.Try this
-> Create a shell script to execute sqlldr
-> On Grid, create an "OS COMMAND" job and pass this script as parameters. You'll have options to schedule this job.
Let us know how it works. -
Sql loader ?. CSV file need 2 load to multi tbls
I have a CSV file i.e.
3 columns on file (qy_type_cd,cd_description,tablename)
example data:
PAST,Past Program Quantity,MASTER_QY
FUT_PEACE,Future Peace Program Quantity,MASTER_QY
TM_PHAS_USE,Time Phased Users Quantity,ADDITIVE_QY
MISTR_RPR,MISTR Repair Quantity,USAGE_QY
I need to load to 3 tables. Tables have two columns (qy_type,description).
How can i read the tablename from csv file and load the qy_type_cd and cd_description INTO a table
something like this. but I dont know the syntax
into table api_mstr_qy
fields terminated by ","
when tablename ='MASTER_QY'
(qy_type,description,tablename)First you need to create a directory that corresponds to where the csv file is located
create directory mydir as 'c:\loaddata\'
Then you need to define the metadata for the
external table:
CREATE TABLE myExternal (
qy_type_cd varchar2,
cd_description varchar2,
tablename varchar2
ORGANIZATION EXTERNAL
(DEFAULT DIRECTORY mydir
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE
BADFILE 'bad_external'
LOGDILE 'log_external'
FIELDS TERMINATED BY ','
qy_type_cd char,
cd_description char,
tablename char
LOCATION (mycsv.csv))
PARALLEL 1 --PUT 2 or the amount of clustered servers you want to use for the process
REJECT LIMIT 1;
Now you are able to run selects on this table
ie: select * from myExternal will produce:
PAST,Past Program Quantity,MASTER_QY
FUT_PEACE,Future Peace Program Quantity,MASTER_QY
TM_PHAS_USE,Time Phased Users Quantity,ADDITIVE_QY
MISTR_RPR,MISTR Repair Quantity,USAGE_QY
So here is where you use the conditional INSERT:
INSERT
WHEN tablename ='MASTER_QY' THEN
INTO api_mstr_qy (qy_type,description,tablename)
VALUES (qy_type,description,tablename)
WHEN tablename = 'OTHER' THEN
FROM myExternal -
SQL*Loader importing problem, with file with eastern european files
Hello,
on Oracle 11g with UTF-8 encoding, I tried to import a csv file into a table via sqlload, the separator is the semicolon ";" all work fine except for some lines witch are not well integrated (the concerned files come from Eastern European countries like Bulgary, Hungary and Czech Republic).
For example:
For:
text_1; text_2; text_with_char_at_end_like_š; new_text
during the integration instead of have:
| text_1 | text_2 | text_with_char_at_end_like_š| new_text |
I got:
| text_1 | text_2 | text_with_char_at_end_like_š; new_text | null |
does anyone has this problem, I tried to change the delimiter by code X'59', specified in sqlldr ENCODING UTF8 ... but it does not work
do you have an idea about this problem
Thank you in advanceThanks,
the problem was solved since, the file was not in UTF8 format (for example GREEK FORMAT) and the NLS_LANG was AMERICAN_AMERICA ASCII
then i translate all files to UTF 8 and changed the NLS_LANG to UtF8.
Regards -
SQL-Loader Control file for Tab-delimited fields
i want to import a text-file with TAB-DELIMITED fields and a line-break + return at the end of each record.
a want to do this by sql-loader and a control file.
please, can someone give me the statement:
e.g.
load data
infile 'exaple.txt' .......
(...field1, field2,....)
thank you very muchCase Study 3: Loading a Delimited, Free-Format File
http://otn.oracle.com/pls/db92/db92.to_URL?urlname=http:%2F%2Fdownload-west.oracle.com%2Fdocs%2Fcd%2FB10501_01%2Fserver.920%2Fa96652%2Fch10.htm%231006907
Modify the example and use 'terminated by whitespace' instead
For more information on TERMINATED Fields see
http://otn.oracle.com/pls/db92/db92.to_URL?remark=drilldown&urlname=http:%2F%2Fdownload-west.oracle.com%2Fdocs%2Fcd%2FB10501_01%2Fserver.920%2Fa96652%2Fch06.htm%231013838 -
SQL Loader: refer datafile name in the control file
Hi All:
Database: 10GR2
I have a table as following:
test (
filename varchar2(100),
mydata varchar2(1000)
I am using sql loader to populate data for this table. I also need store the datafile name to column test.filename as part of dataload. How to refer datafile name in the control file?
Again, I am processing multiple files in a batch mode. I need store datafile name in filename column so that I can know which "mydata" come from which datafile.
Thanks in advance!
KevinAs Bravid says, you can't do that from within SQL*Loader, unless the control files are dynamically generated by a script and the filename included as the default value for that particular column as a hardcoded literal.
It's easier if you use external tables as the table definition contains the "location" which is the list of filenames it is accessing, and the value can be queried as well as being dynamically changed (though if you're dynamically changing it, then you'll programatically know the filename anyway. hint hint!)
;)
Maybe you are looking for
-
Dell 24 inch back to a 17 inch display problem
I installed a 24" Dell LCD display. I changed back to the Apple 17 inch display and i cannot get the resolution back to 1920 x 1200. I only get half the length of a safari page and it extends past the edges. How do I reset it for the Apple display?
-
Apple software not updating - Error message
iMac locked up (white screen of death) so restarted. When it restarted it will no longer update apple applications through the App Store. Downloads and then starts to instal and comes up with an error message. (iTunes, iMovie so far) Non Apple pr
-
How to make it move correctly?
I made a simple Flex application. There is a helicopter which will move to points that user clicks in the canvas. For example, it is at A point. When I click at B point, the helicopter will move to B. Then it will move to C when I click at C. However
-
HT2729 I need a new version of quicktime and i cant download it on my phone
I need the new version and it wont let me upload it and it was working five minutes ago
-
Brother Duplex Printing Problems
I have a Brother HL-5150D printer that is connected to a Windows WinXP machine. I connect my MacBook to the WinXP machine through a wireless connection. I have confirmed that the printer is correctly shared (i.e. I can print to it); however, I do not