Sponsored Content
Top Forums Shell Programming and Scripting Storing the SQL results in array variables Post 302843984 by Niranjancse on Friday 16th of August 2013 03:51:52 AM
Old 08-16-2013
Code

Code:
#!/bin/ksh
#*****************ORACLE CALL FUNCTION****************
function run_oracle {
sqlplus -s <<%%
${user}/${passwd}
set serveroutput off
set heading off
set feedback off
set verify off
set define off
set linesize 2000
${cmd};
exit
%%
}
#***********ORACLE CALL FUNCTION ENDS*************
 
#**********PROCESS TO RUN MULTIPLE QUERIES IN PARALLEL USING "&" IN ORACLE FUNCTION*****************
set -A result ### Declaring the Array
set -A Query ### Declaring the Array
i=0
echo "Dear all, Checks are :- ">${mailfile}
echo "" >> ${mailfile}
start_date=`date +'%H:%M:%S'`
while IFS=\| read chk_nbr chk_name chk_query ## Reading queries and check from parameter file ${chk_file} #######
do
echo ${chk_nbr}
cmd="${chk_query}"
Query[${i}]=${chk_name}
echo ${chk_query}
if [ ${chk_nbr} == "Y" ]; then
result[${i}]=`run_oracle | grep -v '^$' | tail -1` &
process[${i}]=`echo $! | head -1`
echo ${process[${i}]}
let i=i+1
fi
done < ${chk_file}
#***********************PROCESS TO RUN MULTIPLE QUERIES IN PARALLEL USING "&" IN ORACLE FUNCTION ENDS*****************
 
echo `echo ${result[0]}|sed 's/[ ]*//g'` 
 
cnt=`expr $i - 1`
n=0
while [ $n -le $cnt ]
do
p=${process[$n]} #### FETCHES ALL THE PROCESS IDS WHICH ARE TRIGGERED IN ORACLE BY ABOVE PROCESS #########
 
c=`ps -A | grep ${p} | tr ' ' '|' | awk -F'|' -v var=${p} '$1==var'|wc -l` #### CHECKS PROCESS IDS ARE LIVE WHICH ARE TRIGGERED ######
if [ $c -eq 0 ]; then 
echo " ${result[${n}]} : ${Query[$n]}"
let n=n+1
fi
done
n=`expr $n - 1`
if [ $n -eq $cnt ]; then
echo "completed successfully!!"
return 0
else
echo "failed.Please run again!"
return 1
fi

---------- Post updated at 01:21 PM ---------- Previous update was at 01:07 PM ----------

Code:
cat ${chk_file}
 

Y|Duplicate in Table1 |select count(count(*)) from TABLE1  group by COL1,COL2 having count(*)>1

Y|Duplicate in Table2 |select count(count(*)) from TABLE2 group by  COL1,COL2 having count(*)>1


This parameter file will be used by above script to trigger this queries. While i am executing the query output is not being assigned to Array variables. Please help me with this..

Last edited by Franklin52; 08-16-2013 at 04:58 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem while storing sql query value in a variable

Hi, When i execute the below statement , the value is not getting stored in the variable. AnneeExercice=`sqlplus $LOGSQL/$PASSWORDSQL << FIN >> $GEMOLOG/gemo_reprev_reel_data_ventil_$filiale.trc SELECT bi09exercice FROM bi09_scenario WHERE bi09idfiliale=UPPER('de') AND ... (1 Reply)
Discussion started by: krishna_gnv
1 Replies

2. Shell Programming and Scripting

storing variables in array.Please help

Hi All, I need some help with arrays. I need to take input from the user for hostname, username and password until he enters .(dot) or any other character and store the values in the variable array. I would further connect to the hostname using username and passwd and copy files from server to... (7 Replies)
Discussion started by: nua7
7 Replies

3. Shell Programming and Scripting

Storing commands in $variables.

Hi I'm trying to store commands in variables... like so.. # lastcmd=" $t1 | $t2 | $t3 | $t4 | sort | uniq" t1="sed -e 's/http:/<li><a href=\"http:/'" t2="sed -e 's/http:.*/&\">&<\/a>Web Link<br>/'" t3="sed -e 's/.*. mailto:/<li><a href=\"mailto:/'" t4="sed -e... (7 Replies)
Discussion started by: Paulw0t
7 Replies

4. Shell Programming and Scripting

perl: storing regex in array variables trouble

hi this is an example of code: use strict; use warnings; open FILE, "/tmp/result_2"; my $regex="\\ Starting program ver. (.*)"; my $res="Program started, version <$1> - OK.\n"; while (<FILE>) { if ($_ =~ /($regex)/) { print "$res"; } } close FILE; This finds $regex and print... (3 Replies)
Discussion started by: xist
3 Replies

5. UNIX for Dummies Questions & Answers

Storing variables and using them..

Hello Apologies for not having the most accurate of thread titles.. I'm using IBM Rational Synergy CM software. I use the Synergy commands in tandem with Unix commands. I have a directory containing source code objects: bash-3.00$ ccm ls *.fmb *.rdf *.pll *.mmb cre_applications.fmb-1... (1 Reply)
Discussion started by: Glyn_Mo
1 Replies

6. Shell Programming and Scripting

Storing outputs into variables

I need to know how to store output from one command so that it can initiate another command. chktraf -s | cut -c1-4 output would look like 321 142 256 342 123 Then if the value of the output = 0, then initiate next command. if then for xx in 01 02 03 04 05 06 07 08 09 10 do ... (4 Replies)
Discussion started by: Shaun74
4 Replies

7. Shell Programming and Scripting

SQL/Plus in a coprocess example. Also saves query results into shell variables

While assisting a forum member, I recommended running SQL/Plus in a coprocess (to make database connections and run a test script) for the duration of his script rather than starting/stopping it once for every row in a file he was processing. I recalled I made a coprocess example for folks at... (2 Replies)
Discussion started by: gary_w
2 Replies

8. Shell Programming and Scripting

How to store results of multiple sql queries in shell variables in ksh?

Hi, I have a script where I make a sqlplus connection. In the script I have multiple sql queries within that sqlplus connection. I want the result of the queries to be stored in shell variables declared earlier. I dont want to use procedures. Is there anyway else. Thanks in advance.. Cheers (6 Replies)
Discussion started by: gonchusirsa
6 Replies

9. Shell Programming and Scripting

How to Assign SQL Query Results to Variables in Linux?

Hi, I am new to linux... How to Assign SQL Query Results to Variables in Linux,i want ti generate it in param files, Can anyone please explain me. Ex: SQL> Select * from EMP; O/P: Emp_No Emp_Name 1 AAA 2 BBB 3 CCC and I want expected... (5 Replies)
Discussion started by: Sravana Kumar
5 Replies

10. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies
SQLITEDATABASE.QUERY(3) 												   SQLITEDATABASE.QUERY(3)

SQLiteDatabase.query - Executes a query against a given database and returns a result handle

SYNOPSIS
resource sqlite_query (resource $dbhandle, string $query, [int $result_type = SQLITE_BOTH], [string &$error_msg]) DESCRIPTION
resource sqlite_query (string $query, resource $dbhandle, [int $result_type = SQLITE_BOTH], [string &$error_msg]) Object oriented style (method): SQLiteResult SQLiteDatabase::query (string $query, [int $result_type = SQLITE_BOTH], [string &$error_msg]) Executes an SQL statement given by the $query against a given database handle. PARAMETERS
o $dbhandle - The SQLite Database resource; returned from sqlite_open(3) when used procedurally. This parameter is not required when using the object-oriented method. o $query - The query to be executed. Data inside the query should be properly escaped. o $result_type -The optional $result_type parameter accepts a constant and determines how the returned array will be indexed. Using SQLITE_ASSOC will return only associative indices (named fields) while SQLITE_NUM will return only numerical indices (ordinal field numbers). SQLITE_BOTH will return both associative and numerical indices. SQLITE_BOTH is the default for this function. o $error_msg - The specified variable will be filled if an error occurs. This is specially important because SQL syntax errors can't be fetched using the sqlite_last_error(3) function. Note Two alternative syntaxes are supported for compatibility with other database extensions (such as MySQL). The preferred form is the first, where the $dbhandle parameter is the first parameter to the function. RETURN VALUES
This function will return a result handle or FALSE on failure. For queries that return rows, the result handle can then be used with func- tions such as sqlite_fetch_array(3) and sqlite_seek(3). Regardless of the query type, this function will return FALSE if the query failed. sqlite_query(3) returns a buffered, seekable result handle. This is useful for reasonably small queries where you need to be able to ran- domly access the rows. Buffered result handles will allocate memory to hold the entire result and will not return until it has been fetched. If you only need sequential access to the data, it is recommended that you use the much higher performance sqlite_unbuffered_query(3) instead. CHANGELOG
+--------+---------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------+ | 5.1.0 | | | | | | | Added the $error_msg parameter | | | | +--------+---------------------------------+ NOTES
Warning SQLite will execute multiple queries separated by semicolons, so you can use it to execute a batch of SQL that you have loaded from a file or have embedded in a script. However, this works only when the result of the function is not used - if it is used, only the first SQL statement would be executed. Function sqlite_exec(3) will always execute multiple SQL statements. When executing multiple queries, the return value of this function will be FALSE if there was an error, but undefined otherwise (it might be TRUE for success or it might return a result handle). SEE ALSO
sqlite_unbuffered_query(3), sqlite_array_query(3). PHP Documentation Group SQLITEDATABASE.QUERY(3)
All times are GMT -4. The time now is 08:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy