Is it possible for Oracle sqlldr to accept a TNS entry as an instance qualifier in Oracle 10 and 11?
Asked Answered
R

8

11

Is it possible to use a fully qualified TNS entry using sqlldr bundled with Oracle 10/11?

For example, in SQLPlus:

    sqlplus user/password@(description=(address=(host=localhost)(protocol=tcp)(port=1521))(connect_data=(sid=orcl))) @script.sql

But using sqlldr (SQL Loader) there appear to be issues with using the TNS entry directly. Specifically:

    sqlldr user/password@(description=(address=(host=localhost)(protocol=tcp)(port=1521))(connect_data=(sid=orcl))) bad='bad_file.txt' control='control.ctl' data='data.txt' log='log.txt' direct='true'

Here is the error message produced:

    LRM-00116: syntax error at 'address' following '('

    SQL*Loader: Release 11.2.0.1.0 - Production on Tue Sep 13 15:41:54 2011

    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

    SQL*Loader-100: Syntax error on command-line

Attempting to encapsulate the TNS entry in quotes produces the same error.

Had a look at the sqlldr documentation, and attempted to use the 'userid' command-line argument to no avail. Specifically:

sqlldr userid='user/password@(description=(address=(host=localhost)(protocol=tcp)(port=1521))(connect_data=(sid=orcl)))' bad='bad.txt' control='control.ctl' data='data.txt' log='log.txt' direct='true'
LRM-00116: syntax error at 'password@(' following '='

SQL*Loader: Release 11.2.0.1.0 - Production on Tue Sep 13 15:44:17 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

SQL*Loader-100: Syntax error on command-line

It makes sense that Oracle would hope to coerce the user to a local instance to mitigate I/O in pushing data to a remote host. But the deviation in supported syntax is not so intuitive. Anyone else experience similar issues?

Reconstructionist answered 13/9, 2011 at 22:54 Comment(0)
K
15

fwiw, this guy posted a solution to this problem

http://www.simplemancomplexmachine.com/2011/10/sqlldr-one-liner-to-remote-database.html

Yes there is a one-line solution and you can use a TNS connect string to do this from the command line. The key is formatting the connection string a little different as it must be quoted. Additionally the quotes and parentheses must be escaped (backslashes):

sqlldr userid=dbuser@\"\(description=\(address=\(host=remote.db.com\)\(protocol=tcp\)\(port=1521\)\)\(connect_data=\(sid=dbsid\)\)\)\"/dbpass control=controlfilename.ctl data=data.csv

Note that in the original blog post he had a space in front of '/dbpass'. This causes sqlldr to give the error:

LRM-00112: multiple values not allowed for parameter 'userid'

Kirovabad answered 11/7, 2012 at 15:48 Comment(1)
I've also escaped the '=' characters, and it worked. Didn't test without escaping '=' as in the above example...Foochow
C
4

Have you tried the ezconnect format to connect to a remote db using sqlldr ?

e.g:

sqlldr user/password@//localhost:1521/orcl bad='bad_file.txt' control='control.ctl' data='data.txt' log='log.txt' direct='true'   

see: http://www.orafaq.com/wiki/EZCONNECT

Climatology answered 14/9, 2011 at 9:46 Comment(2)
Fact, but If i were you I would put the command in a shell\batch file and prompt for the password there :)Climatology
I ended up using a shell file which would generate a parameter file and run SQL*Loader off of that. Putting the password into the command line parameters of sqlldr shows the password to anyone in the system who runs ps -ao args so I was looking for a way to avoid that as well.Borst
B
4

Looks like you need to escape characters like '(', ')' and '=' with the escape character '\' (i.e. backslash) as explained in here.

Bluefish answered 20/9, 2011 at 2:0 Comment(0)
B
1

You can also try:

sqlldr user/password@TNS:(description=(address=(host=localhost)(protocol=tcp)(port=1521))(connect_data=(sid=orcl))) bad='bad_file.txt' control='control.ctl' data='data.txt' log='log.txt' direct='true'
Brieta answered 15/9, 2011 at 15:7 Comment(0)
E
1

Kelvin is 100 % Correct. It worked for me

You can execute sql loader with below command without making a tns entry

sqlldr userid/password@//host:port/SERVICE_NAME bad='/PATH/FILENAME.bad' control='/PATH/FILENAME.ctl' data='/PATH/FILENAME.csv' log='/PATH/FILENAME.log' direct='true'

Enforcement answered 15/11, 2015 at 15:57 Comment(0)
E
0

The only thing that worked for me was using two kinds of quotes:

sqlldr user/password@'"(description=(address=(host=localhost)(protocol=tcp)(port=1521))(connect_data=(sid=orcl)))"' bad='bad_file.txt' control='control.ctl' data='data.txt' log='log.txt' direct='true'

Elwina answered 26/1, 2015 at 14:13 Comment(0)
S
0

Single quoting the whole not-so-ezconnect worked for me in a DOS batch script and on the command line:

sqlldr 'user/password@(description=(address=(host=localhost)(protocol=tcp)(port=1521))(connect_data=(sid=orcl)))' control='control.ctl' data='data.txt'
Stringhalt answered 16/1, 2017 at 9:43 Comment(0)
S
0

I was able to fix the issue by running the same command with no spaces in connection string and using ' as escape character in normal command prompt (CMD) in windows server.

The same command in powershell still throw error

Just posting for powershell/CMD users

Sicyon answered 14/2, 2023 at 11:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.