SQL script through bat file - oracle

I am trying to automatize some daily checks and now I need to use SQL query.
So I write my SQL script and then tried to run it through batch file to be able to put it to task scheduler.
So I wrote something like this
sqlplus user/pw#DBServer #PathToSQLScript.sql > "DestinationWhereToPutOutput"
It is confusing me because this works normally at any other server that I already automatized but at this one it gave me error
ORA-12154: TNS: could not resolve the connect identifier specified
And wanting me to reenter credentials.
Is there any other way how to run SQL script through batch file?
Thanks in advance for any advice.

The most frequent reason for ORA-12154 is that DBServer can't be found in TNSNAMES.ORA file. Therefore:
create DBServer's alias in TNSNAMES.ORA, or
use EZCONNECT syntax (which doesn't require TNSNAMES.ORA) that looks like host:port/service_name
For example, that would be
sqlplus user/pw#db_server:1521/orcl
For much more info about troubleshooting ORA-12154, see Ed Stevens' blog

Related

Oracle cannot get sqlldr to reach listener, get ORA-12514 error

Every time I try to run the following sqlldr command on a terminal only oracle 19c system:
sqlldr username/password#$HOSTNAME/$ORACLE_SID control=rules.ctl log=backup_error_logs.txt data=output.csv errors=1000000
I get the following error message:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Things I have tried:
Verified that the listener is operable and listener.ora file is properly formatted with lsnrctl.
Verified the connection and oracle environment variables are working as the following sqlplus command runs without problem:
sqlplus username/password#$HOSTNAME/$ORACLE_SID
Verified the tnsname.ora is running properly configured with the following tnsping command:
tnsping $ORACLE_SID
Cannot think of anything else to try or to check. Does anyone have any advice without resorting to the GUI tools?
Could be a problem of quotes in the variables, the behavior of both tools is different regarding quotes.

Running SQL file in command line using sqlplus result with an error

Using ORACLE 12.0c and SQL Developer.
I try to run a SQL file (myfile.sql) in command line using sqlplus:
sqlplus username/password#schema #myfile.sql resulted with an error.
I run only sqlplus with connection parameters sqlplus username/password#schema and still receive an error (see screenshot).
Typing the username and password didn't help as well.
Only running sqlplus and supply the database domain, port and database name I managed to connect and run the file.
The database is defined in SQL Developer, but I don't see it in TNSNames.ora.
What am I missing?
I give credit to #thatjeffsmith and the answer is... see screenshot:

Spfile and Pfile not created during installtion of Oracle 11g

I need your help concerning an issue with oracle 11g installation, i installed it while connected to a domain account (and still connected to it), after installation complete and a reboot i tried to startup Oracle using windows command line:
>sqlplus /nolog
>connect sys /as sysdba
>startup
After the startup command i get the following error:
ORA-01078: failure in processing system parameters
ORA-01565: error in identifying file ORA-27041: unable to open file
C:\oraclexe\app\oracle\product\11.2.0\server\dbs/spfileXE.ora
When i manually went to spfile and file locations, i didn't find anyone of them.
now i am looking for a method to generate of create these files without having to reinstall Oracle 11g. Any ideas please?
PS : i have windows 10.
Thanks in advance
Problem solved, while looking for pfile i was looking for something like PFile.ora, have just found that it is named init.ora, sounds stupid but yeah :D

how can I use "impdp" command importing .dmp data with port number?

I am trying to import data to an Oracle database. I have ".imp" and ".dmp" files for importing data. The database is using port 1521 and database name is "DB".
I have tried the following command, but doesn't work.
impdp root/password#xxx.xxx.xxx.xxx:1521:DB
dumpfile=transmart.dmp
logfile=transmart.imp
schemas=i2b2hive,i2b2metadata,i2b2sampledata,i2b2demodata,i2b2workdata
,biomart,biomart_user,deapp,searchapp,tm_cz,tm_lz,tm_wz
ERROR: either ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA or ORA-12545: Connect failed because target host or object does not exist
I can telnet the IP and port with no problem.
Can anyone suggest please?
Thanks!
You have a syntax error in your EZConnect string.
Try this instead (no need to fuss with tnsnames.ora this way):
impdp root/password#xxx.xxx.xxx.xxx:1521/DB
Notice the replacement of the ":" with a "/" between port and service name.
As a side note, I long ago got out of the habit of putting passwords in command lines, where they may be easily snooped while the command is running. Let the program prompt you for the password:
impdp root#xxx.xxx.xxx.xxx:1521/DB
Especially if you're going to use root for your commands ;-)
Your reference to telnet suggests you are running this from a remote client rather than locally on the database server.
You need to edit your client's TNSNAMES.ORA file with the location information for DB. Perhaps you think you've already done this, in which case you've probably introduced a typo or got the syntax wrong.
The other thing to check is that the listener is running on the database server, as that's a very common cause of ORA-12545.
to import the latest transmart database dump we used the following:
wget https://github.com/transmart/transmartApp-DB/zipball/master
unzip master
tar zxvf transmart.dmp.tar.gz
cp transmart.dump /u01/app/oracle/admin/XE/dpdump
chown oracle:dba /u01/app/oracle/admin/XE/dpdump/transmart.dmp
impdp SYSTEM dumpfile=transmart.dmp logfile=transmart3.log full=y
If you don't use the full=y you will end up missing a number of tables. Hope this is still useful to you or someone else.

Load data to remote DB using sqlldr

I wanted to load data to remote db using sqlldr.I did it using following command
>sqlldr GANUKA/GANUKA#jdbc:oracle:thin:#172.21.0.180:1521:orcl control=D:\Work\CLSTMAS.ctl
log=D:\Work\CLSTMAS.log
But it gives the following error.
SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0]
ORA-12154: TNS:could not resolve the connect identifier specified
Need a help
You're mixing up two different worlds here. One is the OCI world where sqlldr lives. It expects Oracle instance names defined in TNSNAMES.ORA (or a similar service). The other world is the JDBC world that uses connection identifiers with words like "jdbc" or "thin".
So you have two options:
If your environment has a proper TNS setup, you have to change the command line to something like sqlldr GANUKA/GANUKA#MONTY.CORP control=...
If not, you can use an Easy Connect string: sqlldr GANUKA/GANUKA#//172.21.0.180:1521/orcl control=...
I ended up having to use a thin client connection string. I couldn't get #Codo 's solution to work.
sqlldr \'username/passwd#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost.com)(PORT=1111)))(CONNECT_DATA=(SID=MYSIDE)(SERVER=DEDICATED)))\' control=loader.ctl data=data.csv

Resources