I am very new to shell scripting and trying to write a simple shell script in which i am trying to achieve the following:
1. Connect to oracle database hosted on a different server
2. fire a query on the oracle db
3. store the output in a variable
4. use this variable for further logic
The code that i have written so far is as follows:
Now the error message i am getting is as follows:
Could someone please guide where am I going wrong? And what is the correct way to write such a code.
Your help is highly appreciated!
Regards,
Shruti
Last edited by Scott; 05-04-2010 at 05:25 PM..
Reason: Code tags, please...
Unfortunately you are so far adrift that it is hard to guess what you are trying to achive. There are multiple significant errors both the Unix shell syntax and the Oracle command syntax.
The sqlplus line posted looks like an extract from an Oracle listener log. It is not a valid sqlplus command line at all.
Maybe try using the search facility on this site to look for examples of Oracle sqlplus commands within unix shell. Don't forget to set the Oracle environment variables such as ${ORACLE_HOME}.
In this context if you can type the commands at a command prompt they can be turned into a unix shell script.
Tip: First try getting the command sequence to work manually before trying to script it.
Actually, it is possible to connect to the Oracle database by specifying the connect descriptor from the tnsnames.ora file. But it's not a secure way of connecting since all important pieces of information (server name, port etc.) are exposed in the process list when connecting this way.
@OP - find out the net_service_name that corresponds to this connect descriptor. It may be "PHYGD1" or something else - depends on what your Oracle DBA set it to during installation, so you may want to talk to him/her.
Once it is known, you can connect as "username/password@net_service_name". Or better, set the ORACLE_SID variable to that value and connect as "username/password".
In my case, I've set my ORACLE_SID to "ora11g", which is the net_service_name in my tnsnames.ora for my local database. So I can connect as "test/test".
Have a look at the script below; it should give you some idea -
The SQL syntax of your script looks suspicious:
If "dbdev.db_inv_dtl_hdr" is a regular (heap) table i.e. one that has been created using the "create table dbdev.db_inv_dtl_hdr (blah...);" syntax then your syntax should be -
As a matter of fact, there is a "table()" operator in Oracle that casts a nested table to a regular table. However, that type of syntax is typically used by advanced Oracle programmers and somehow I believe that's not the case here.
1. Connect to oracle database hosted on a different server
2. fire a query on the oracle db
3. store the output in a variable
4. use this variable for further logic
Try this ...
--> use the variable to add your own logic
Last edited by Scott; 05-05-2010 at 01:43 PM..
Reason: Code tags please...
As per the suggestions below i thought of taking 1 step at a time by doing the following:
1. Checked all environment variables are set in my .bash_profile file. $ORACLE_HOME and $ORACLE_SID returns correct results.
2. I tried to connect to SQLPLUS from the unix prompt directly....I enter the user name and password....but I get the following error:
I tried to research on this error message and everywhere it mentions that i should check the entries in TNSNAMES.ora......i cross checked the entries and everything looks fine to me....below is the entry from my tnsnames.ora file...
Could anyone please guide me as to what i might be missing which is preventing me from connecting to the database on a remote machine - 10.5.199.106??
Thanks,
Shruti
Last edited by Scott; 05-05-2010 at 01:44 PM..
Reason: Code tags please...
Hi,
I am trying to get the rows(First step is to get the poolid's and then second step run a loop to get the output based on each pool id and third connection is to get the member id and pool id based on a different condition) where based of certain conditions and storing it in a file. I wrote the... (6 Replies)
hi,
i have a requirement where i need to connect sqlplus from unix and i am able to do so by following command:
cust_count=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF
set pagesize 0
set feedback off
set verify off
... (1 Reply)
Hi,
I am facing a strange issue when connecting to SQLPLUS via a shell scripts.
I am using Linux 2.6.18-274.18.1 and gbash shell.
When I connect to SQLPLUS through scripts then it throws TNS Time Out error ""sometimes"" and connects successfully other times.This is only happening when... (9 Replies)
Hello everyone,
It's my first week using unix and shell scripting. I tried creating a script that has a function that execute SQL query. my script looks something like this:
----------------------------------------------------
#!/bin/sh
tableName="myTable"
secondTable="secondTable"... (2 Replies)
Hi,
I am very new to shell scripting and trying to write a simple shell script in which i am trying to achieve the following:
1. Connect to oracle database hosted on a different server
2. fire a query on the oracle db
3. store the output in a variable
4. use this variable for further logic... (1 Reply)
a job extracts orcle data into unix as flat file.
a single record breaks into two record in unix flat file. This is the case only for 6 records out of 60 lack records.
(its not single record in two line. but its single record into record. ie., \n come into picture)
can you tell me what... (6 Replies)
I am trying to connect to one of the oracle sever using uni through sqlplus
command: sqlplus -s BOXI_ALPH_AUDITOR,Q078_audit$@Q047
But its not getting connected. I tried using some different server using same syntax its working. What differene i found is the password is having no special... (2 Replies)
hi,
I am trying to automate the compilation of procedures stored in .sql files in Unix. Is there any way in which we can sho err if there errors are raised in the compilation?
I am using the following code to connect to the sqlplus
sqlplus ${SQL_USER}/${SQL_PASSWORD} (5 Replies)
Hi,
I wrote a shell script to call oracle procedure. But when i am trying to connet sqlplus with the fallowing statement It is giving me error " callproce.sh : sqlplus: not found". What could be the problem.
sqlplus -s $CONNECT_STRING >$LOGFILE <<!!
thank u all
papachi (2 Replies)