Execute oracle query determined at runtime from a unix script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute oracle query determined at runtime from a unix script
# 1  
Old 02-01-2008
Execute oracle query determined at runtime from a unix script

Hi

I am trying to run a SQL statement from a unix script determined at runtime.
It is throwing me an error. Please advise some solution to this.

echo "Enter username for the database"
read username

echo "Enter password for the database"
read password

echo "Enter SQL stmt"
read sqlstatement

sqlplus ${username}/${password} <<EOF

spool output.lst;

execute immediate '$sqlstatement';

spool off;
EOF
# 2  
Old 02-01-2008
MySQL

try this

sqlplus -s <LOGIN>/<password>@$DBCONN <<-END > <DESTINATIONDIR>/<FLNAME>
set serveroutput on;
set head off;
set feed off;
set timing off;
set pages 0;
set line 200
<QUERY>
EXIT;
END

good luk

Regards,
Pankaj
# 3  
Old 02-01-2008
MySQL

sqlplus -s <LOGIN>/<password>@<DBCONN> <<-END > <DESTINATIONDIR>/<FLNAME>
# 4  
Old 02-01-2008
Pankaj, if the query is known to me before running the script, then there is no issue but what if the user is inputting the SQL query to be run at the Run time of the Unix Script ?
# 5  
Old 02-01-2008
if user need wants to run the query then everything shud be configurable
QUERY,PASSWRD,USENAME,DBCONN etc

i'm giving a sample of configuration file from which u'll have to extract the values and 'll have to proceed

XYZ
XYZ.db=ORACLE
XYZ.Configuration
XYZ.Dbconn=abcXYZ.Login=scott
XYZ.Pass=wljhu
XYZ.Query=SELECT RECORDSEQNUMBER||'|'||CALLIDNUMBER||'|'||RELATEDCALLIDNUMBER||'|'||DATEFORSTARTOFCHARGE||'|'||TIMEFO RSTARTOFCHARGE||'|'||ERRORTYPE||'|'||DATA||'|'||REGION||'|'||SWITCHID||'|'||FILENAME||'|'||DATEOFSUS PENSE||'|'||TIMEOFSUSPENSE||'|'||REPROSTATUS||'|'||ORIGEN_ERROR FROM E1_SUSPENSE;
XYZ.DstDir=/path od destination dir
XYZ.FileName=MM1_E1_SUS.txt

from the configuration file u have to fetch value like this way

QUERY=`grep -w <DBCODE>.Query <Full Path where the configuration file has been placed>/<Name of the configuration file>| cut -f2 -d"="`

good luk

Regards,
Pankaj
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to execute sql query.

Hi Experts, Need your support. Not able to use sql query alias in shell script. Could you please help me in finding right way to use alias with sql query in shell script. Below is the code i am using. #!/bin/bash sqlplus -s abc/abc@abc << EOF> bcd.csv set trimspool on select zone_id... (4 Replies)
Discussion started by: as7951
4 Replies

2. Shell Programming and Scripting

Want to use function and execute the below query in script.

#!/bin/bash function getDeliveredDispatches(firstDateTime, lastDateTime, limit) { var cursor = db.dispatches.find( {$and: }} ]}, {"deliveryGroupId" : 1, "batchId": 1, "statusHistory.code" : 1} ); var wrongDispatchesIds = ; print("Number of dispatches selected based on filter = " +... (2 Replies)
Discussion started by: neel2462
2 Replies

3. Shell Programming and Scripting

ksh Array name determined at runtime

I'm working on a ksh script and was wondering if anyone knows if it's possible to access an array by a variable that is determined at runtime? I have created a test example below, but essentially I will have declared and populated an array (see colorArray below). What I'd like to do is access... (9 Replies)
Discussion started by: bs103950
9 Replies

4. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

5. Shell Programming and Scripting

PROBLEM WITH ORACLE QUERY IN UNIX SCRIPT

hi Guys, i have a problem with oracle query in my unix script.. I'm getting the following error while executing.. ./logtab.sh: sqlplus -s "pmutv/pmutv1" << EOFSQL^Jset head off^Jinsert into... (2 Replies)
Discussion started by: apple2685
2 Replies

6. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

7. Shell Programming and Scripting

Execute SQL query in unix script

Hi I am new in unix. oracle and unix are installed in my sytem.i need the script which could connect to the oracle using username ,password and schema and can run the select * from tab query. Thanks vijay (8 Replies)
Discussion started by: vijays3
8 Replies

8. Shell Programming and Scripting

Oracle Query results to be stored in variables using unix

I want to store the sql query output into a variable #!/bin/ksh ORACLE_SID=DB01; export ORACLE_SID; export FILE_PATH=/home/asg/Tmp # Order Checking echo " removing old files " rm $FILE_PATH/Malformed_Order.txt echo " Enter the Malformed Order ....!" read orders echo "Regrade... (5 Replies)
Discussion started by: Nareshp
5 Replies

9. Shell Programming and Scripting

How to execute multiple(batch) oracle script in unix mechine

Hi All, How to run multiple oracle script in unix at-a-time.I appriciate if any send the script for me. Regards, Ravi kumar.Gongati (2 Replies)
Discussion started by: ravi gongati
2 Replies

10. Shell Programming and Scripting

$HOME Not Getting Set for Oracle Scheduler Script at Runtime

We are researching the possibility of using Oracle 10g Scheduler on Solaris 10 to launch scripts at our site, and the script that I am testing does not get $HOME (and other environment variables) set correctly. Here is the Korn shell script (show_info.ksh): #!/usr/bin/ksh id env | sort Here... (4 Replies)
Discussion started by: shew01
4 Replies
Login or Register to Ask a Question