Connecting to Oracle DB using sqlplus


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Connecting to Oracle DB using sqlplus
# 8  
Old 05-05-2010
start off by seeing that you can 'see' everything as needed.

Code:
telnet 10.5.199.106 1521

Code:
tnsping PHYGD1

Beyond this, if the instance is down...or the schema and/or object is not present you'll want to speak to your DBA. Good luck!
# 9  
Old 05-05-2010
1) echo $ORACLE_SID returns the following:

bash: PHYGD1: command not found

where PHYGD1 is the correct SID.

2) tnsping to VOMSD1 returns OK

3) telnet to the server says 'Connected'

From the basic checks everything looks fine to me.

Could someone please confirm if the tnsnames.ora entry in Unix can exactly be same as the one in windows?

because i am able to connect to the remote database through toad from my windows machine w/o any issues.
# 10  
Old 05-05-2010
Quote:
Originally Posted by shrutihardas
1) echo $ORACLE_SID returns the following:

bash: PHYGD1: command not found
That's surely not possible!!

Is that what you really typed?

Code:
echo $ORACLE_SID

I'm surely not the only person who uses oraenv to set an Oracle environment?
# 11  
Old 05-05-2010
Quote:
Originally Posted by shrutihardas
1) echo $ORACLE_SID returns the following:

bash: PHYGD1: command not found

where PHYGD1 is the correct SID.

2) tnsping to VOMSD1 returns OK

3) telnet to the server says 'Connected'

From the basic checks everything looks fine to me.

Could someone please confirm if the tnsnames.ora entry in Unix can exactly be same as the one in windows?

because i am able to connect to the remote database through toad from my windows machine w/o any issues.
(a) Run the commands posted earlier on the Unix/Linux dollar prompt.
(b) Select the relevant area from your terminal emulator program (PuTTY/Konsole/Gnome Terminal/XTerm etc.), copy it and paste it over here.
So that we could see what exactly you typed, and its result.

tyler_durden
# 12  
Old 05-05-2010
@durden_tyler - I am able to establish a DB connection now. Using the following command from Unix prompt:

Code:
sqlplus <User_ID>/<Password>@'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.5.199.106)(PORT=1521))(CONNECT_DATA=(SID=PH YGD1)))'

I was now trying to use the sample code which you had provided below -

Code:
#!/bin/bash
#Connect to the database using sqlplus
x=`sqlplus -s /nolog <<EOF
connect test/test
set pages 0 
select x from t;
exit
EOF`

As follows:

Code:
sqlplus gidicm/gidicm@'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.5.199.106)(PORT=1521))(CONNECT_DATA=(SID=PHYGD1)))' >> outputlogfile.log
echo "Step 1 Done"
select sysdate from dual;
ENDSQL
echo "Output_variable, sysdate=$sysdate"

This code is getting stuck at the select statement.

Could you please let me know the correct way to invoke a sql from shell script? Please note that the way I am using the command sqlplus needs to be the same as above...since i am able to establish connection using this command now.

Please advise.

Thanks!
Shruti

Last edited by Scott; 05-05-2010 at 05:23 PM.. Reason: Code tags, PLEASE!
# 13  
Old 05-05-2010
preface the line starting "echo ... " with the sqlplus command host. This is needed to produce a host-side command from within the sqlplus client...

But, you're also mixing and matching syntax provided by tyler and your original approach. As stated before, one step at a time...prove you can get the select to run from the command-line...manually, and then you can try to get it into a script.
# 14  
Old 05-05-2010
I am sorry I did not explain it clearly before:

Yes, I was able to connect to the database from the Unix prompt and also I was able to run the following query successfully on the prompt. Please see the query ran and the output I got below:

Code:
bash-2.05b$ sqlplus gidicm/gidicm@'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.5.199.106)(PORT=1521))(CONNECT_DATA=(SID=PHYGD1)))'

SQL*Plus: Release 9.2.0.8.0 - Production on Wed May 5 16:31:34 2010

Copyright (c) 1982, 2002, Oracle Corporation.  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 sysdate from dual;

SYSDATE
---------
05-MAY-10

SQL>

Now I am trying to include this simple query in my shell script. For which I have written the below script:

Code:
#!/bin/bash
sqlplus gidicm/gidicm@"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.5.199.106)(PORT=1521))(CONNECT_DATA=(SID=PHYGD1)))"<< EOF
'select sysdate from dual;
EOF'
echo "Output_variable, x=$sysdate"


This script is able to establish the database connection successfully...but it fails at the step where i try to fire the select query. I know i am missing the write syntax here....but that's where i need the help from you experts.

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sqlplus not connecting the 2nd time in for loop

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)
Discussion started by: ajayakunuri
6 Replies

2. Shell Programming and Scripting

Connecting sqlplus from UNIX with multiple select statement

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)
Discussion started by: lovelysethii
1 Replies

3. Shell Programming and Scripting

Connect to Oracle using sqlplus

I have logged into oracle using SQLPLUS. When I type any kind of query, there is only 1 answer - '2'. What is wrong with it? (1 Reply)
Discussion started by: Subhasis
1 Replies

4. Red Hat

TNS Timeout Error when connecting to SQLPLUS through scripts only

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)
Discussion started by: aashish.sharma8
9 Replies

5. UNIX for Advanced & Expert Users

Connecting once using sqlplus and doing multiple queries

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)
Discussion started by: edlin_r
2 Replies

6. UNIX for Dummies Questions & Answers

Connecting to Oracle DB using sqlplus

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)
Discussion started by: shrutihardas
1 Replies

7. Shell Programming and Scripting

Formatting Oracle sqlplus output

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)
Discussion started by: Gopal_Engg
6 Replies

8. Shell Programming and Scripting

connecting through sqlplus

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)
Discussion started by: gander_ss
2 Replies

9. Shell Programming and Scripting

Showing errors when connecting to sqlplus in shell script

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)
Discussion started by: silas.john
5 Replies

10. UNIX for Dummies Questions & Answers

error connecting to sqlplus

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)
Discussion started by: papachi
2 Replies
Login or Register to Ask a Question