Connecting to ORACLE through SHELL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Connecting to ORACLE through SHELL
# 8  
Old 04-14-2010
have you actually debugged so far as to try running the following on the command-line on your own machine?

Code:
$ORACLE_HOME/bin/sqlplus schema/'pwd'@db

I think you'd find that pwd would be a literal string and not what you'd expect it to be...

Generally, you'd want to do something like the following:

Code:
sqlplus -s ${sql_connstr}${my_data} <<-SQL_SCRIPT|egrep -v "^$|rows selected" >|${out_file} 
  ..
SQL_SCRIPT

Now, if you're concerned about your flurry of set commands effecting what's being output to your file, you could play around and manage these to squelch any echoes, etc, or you could also just extend the egrep -v command above to suppress most of the noise.
# 9  
Old 04-14-2010
General comment. No time to post specifics.

By using a unix shell "here" document Oracle is in interactive mode and will give you SQL> prompts etc. which obfuscate your output.

If you invoke sqlplus and ask it to run a SQL program from a file it will all become less complicated. Within the program use "set" statements to turn off (not on) feedback etc. and then use Oracle "spool" commands to output your enquiry to file. There are many examples on this site.


Code:
sqlplus /NOLOG program_name.sql

# 10  
Old 04-14-2010
to methyl's point, I believe: yes...an external SQL file is useful in terms of providing a single point of SQL behavior. However, and possibly to the OP's use of the here doc, it's often more portable to embed the SQL into the script via the here doc.

Overall, I guess you might say, pick a paradigm and go with it, rather than cobble together approaches. Using a here doc to then call a SQL file may not simplify things.
# 11  
Old 04-15-2010
First, try to manually connect to your database first. If it works, try the code below.

If you want to store the value in a file. Please see the following code:
Code:
$ORACLE_HOME/bin/sqlplus -s schema/'pwd'@db <<  EOF > /home/count/infoc.txt
set echo on;
set feedback on;
@/home/count/qry.sql;
EOF

If you want the output the result to the $RESULT parameter:
Code:
RESULT=`$ORACLE_HOME/bin/sqlplus -s schema/'pwd'@db <<  EOF
set echo on;
set feedback on;
@/home/count/qry.sql;
EOF`
echo $RESULT

Then remove the spool line from your SQL file

Last edited by The One; 04-15-2010 at 05:40 AM.. Reason: Forgot the [CODE][/CODE]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Connecting to Oracle database

Hi guys, long time no typing :D I have problems when I try to connect to Oracle database from SQL Developer which is located on my Windows box. Server is running Solaris 11/11 and Oracle 11 enterprise. I can log in locally with sys account to database, start it up and shut it down but when I... (2 Replies)
Discussion started by: solaris_user
2 Replies

2. Shell Programming and Scripting

Connecting to oracle database

Hai i want to connect to oracle database from user input and create a view. ${ECHO} "Debut Creating View" ${ECHO} "Please Enter the User Name:" read user_name ${ECHO} "Please Enter the Connection String:" read con_string ${ECHO} "Please Enter the Password:" read pwd... (3 Replies)
Discussion started by: shenthil76
3 Replies

3. 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

4. Shell Programming and Scripting

Connecting CA::Autosys to oracle DB

Hi :), I have installed CA Autosys in my Unix system. It contains 3 ( .pm ) files namely AutoSys.pm, Job.pm, Status.pm ....... in a directory CA. Am trying to work with autosys for first time. Please guide in how do i connect autosys to oracle DB in my system. My oracle db name is XE.. Thank... (0 Replies)
Discussion started by: bhuvaneshlal
0 Replies

5. Shell Programming and Scripting

run shell script connecting to oracle from crontab

Hi, I have problems with running shell script connecting to Oracle from the crontab. Here is the script: #!/sbin/sh ORACLE_HOME=/opt/oracle/10g/ export ORACLE_HOME if then echo "Source path is not specified" exit fi /opt/oracle/10g/bin/sqlplus user/pass@testdb << EOF truncate table... (6 Replies)
Discussion started by: apenkov
6 Replies

6. Shell Programming and Scripting

Connecting to oracle database from shell script

Hi all, I am satyakiran , i am new to the forum. i never done shell scripts for connecting to the data base (oracle) and fetching the data from the database( thru sql select statements ) i want to know 1. how to connect to the data base(oracle) using shell script 2. how to retrieve data... (8 Replies)
Discussion started by: satyakiran
8 Replies

7. Shell Programming and Scripting

Connecting to Oracle Database

if; sql="select username from dba_users where username = '$FromUser';" check_FromUser=`ExecSql "$sql"` I want to connect to Oracle database & check the users in the database, store the value in check_FromUser. First how to connect to Oracle database from the shell script ? Appreciate your... (4 Replies)
Discussion started by: dreams5617
4 Replies

8. Shell Programming and Scripting

Connecting to Oracle from Shell..What Am I doing Wrong

I have the following code in my shell script. . /apps/oracli/xxxxx/xxxx/oraEnv.9.2.0 sqlplus -s $DB_USER/$DB_PWD@$DB_NAME > xx.html <<EOF I am passing DBuser and DBname from a config file and the password from user. Config File : export DB_USER=xxx; export DB_NAME=xxx; I am getting... (1 Reply)
Discussion started by: dzyr4tt
1 Replies

9. UNIX for Advanced & Expert Users

Connecting to Oracle through unix shell scripts

Hi, Can some one help me in connecting to oracle through unix shell scripts with examples. Regards Narayana Gupta (1 Reply)
Discussion started by: guptan
1 Replies

10. UNIX for Dummies Questions & Answers

Connecting to a Oracle Db using SunOS

Hi Guys, how do I connect to a Oracle Database from my machines running on Solaris 5 and 9. Do I need a Oracle client installed or is there any other way to connect to the Oracle Db without using the oracle client? Any inputs will be highly appreciated. (2 Replies)
Discussion started by: darmat0712
2 Replies
Login or Register to Ask a Question