Sponsored Content
Top Forums Shell Programming and Scripting Storing passing and executing select statement in loop Post 302953237 by Khushbu on Wednesday 26th of August 2015 06:58:46 AM
Old 08-26-2015
Well, I'm now trying the following script where I'm trying to run a .sql file from this script. But when i open the output file everything is blank. Why is this so?

Script:
Code:
PATH=..............
export PATH
ORACLE_HOME=...............
export ORACLE_HOME
TNS_ADMIN=...................
export TNS_ADMIN
cut -d " " -f15 demon | sort -n -r > /home/remedy/demo.txt
awk '{print "select * from apsdi-apaction where request_id= "$0}' /home/remedy/demo.txt > /home/remedy/output.sql
sqlplus -S user/pwd@databasename.co > /home/remedy/variable.txt << EOF
@output.sql
EOF

1.demon file contains the string which I'm able to cut for the 15 digit ID.

2.demo.txt file contains the list of IDs as follows:
Code:
000000000019879
000000000039043

3.output.sql file contains following:
Code:
select * from apsdi-apaction where request_id= 000000000039043
select * from apsdi-apaction where request_id= 000000000019879

4.variable.txt file should contain the output of above sql statements, but the file appears blank.

Please let know what changes are to be made in above script to make it work. How do i excute the .sql file from above script. Any other alternative will also work.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading from a file and passing the value to a select query

Hi all, Here is my problem. I want to read data from a file and pass the variable to a select query. I tried but it doesn't seem to work. Please advise. Example below. FileName='filekey.txt' while read LINE do var=$LINE print "For File key $var" ${ORACLE_HOME}/bin/sqlplus -s... (1 Reply)
Discussion started by: er_ashu
1 Replies

2. UNIX and Linux Applications

Oracle Select IN statement

If I recall, when I used informix I could do a sql statement like: SELECT Value from Table WHERE ID in (100,200,300); How do I do this in Oracle? I believe I am using Oracle 10 if that matters. Thanks. (1 Reply)
Discussion started by: benefactr
1 Replies

3. Shell Programming and Scripting

using SELECT sql statement in shell script

Hi there I have a database on a remote box and i have been using shell script to insert data into it for example, i could have a script that did this SN=123456 n=server1 m=x4140 sql="UPDATE main SET hostname='$n',model='$m' WHERE serial='$SN';" echo $sql |/usr/sfw/bin/mysql -h... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

4. Shell Programming and Scripting

How can i assign an select statement into a variable?

I am trying to assign an select statement into a variable. Can someone hel me with this. example : a='select * from dual' echo $a should give me select * from dual But this is not working. I trying with \ before * and quotes too. (1 Reply)
Discussion started by: rdhanek
1 Replies

5. Shell Programming and Scripting

Select variable within a if statement

i want to select a variable created and use it in a if statement, but not getting the desired results LINE='device for 0101a01: lpd://172.25.41.111:515' prt=`echo $LINE | awk '{print $3 }' | cut -c 1-7` echo $prt My if statement to select just what i want.. IFS=$":" while read prt... (11 Replies)
Discussion started by: ggoliath
11 Replies

6. Shell Programming and Scripting

for each value in an array, execute select statement

Hello All, I am new to shell scripting. I am working on Solaris O/S, bash script and sybase programming. I want to loop through multiple values in an array and for each value, I want to select a row from the database. following is the code written for it. output="loop.csv" ... (8 Replies)
Discussion started by: arundhati_s
8 Replies

7. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

8. Shell Programming and Scripting

Help in executing select query from perl script

Hi, I have a perl snippet that call a select query with a bind variable,when i compile the script I'm unable to get the query output. The same query when i fire in sqlplus fetches few rows. The query takes bit time to fetch results in sqlplus. my $getaccts = $lda->prepare("select distinct ... (1 Reply)
Discussion started by: rkrish
1 Replies

9. Shell Programming and Scripting

Problem with select statement

Hi I have run out of ideas as to why this select doesn't work in a script I am writing. The script sources a file of common functions and I am trying to use a select statement within one of the functions - PS3="Try? " select X in CONT EXIT; do if ] ... (4 Replies)
Discussion started by: steadyonabix
4 Replies

10. Shell Programming and Scripting

SQLPLUS command with more than 1 select statement

Hi all, I'm using below code processId=`sqlplus -s ${sysuser}/${syspwd} <<CHK_PROCESS whenever sqlerror exit sql.sqlcode; set head off feedback off echo off pages 0 SELECT PROCESS_ID FROM LSHADMIN.DATA_DOMAIN WHERE DOMAIN_NAME = '${tabname}' ... (8 Replies)
Discussion started by: Pratiksha Mehra
8 Replies
gen-index(8)						  GNATS Administration Utilities					      gen-index(8)

NAME
gen-index - generate new GNATS database index SYNOPSIS
gen-index [ -n | --numeric ] [ -h | --help ] [ -o outfile | --outfile=outfile ] [ -i | --import ] [ -e | --export ] [ -d databasename | --database=databasename ] [ -V | --version ] DESCRIPTION
Builds an index for the specified GNATS database. The index is printed to standard output by default. OPTIONS
-n, --numeric Sorts index entries numerically rather than by their order in the categories list. -d databasename, --database=databasename Specifies the database to be indexed. If no database is specified, the database named default is assumed. This option overrides the database specified in the GNATSDB environment variable. -o outfile, --outfile=outfile Prints the index to outfile rather than to the standard output. -i, --import Import the existing index file instead of re-indexing the database. -e, --export Force plaintext output -h, --help Prints usage for gen-index. -V, --version Prints the version number of gen-index. ENVIRONMENT VARIABLES
The GNATSDB environment variable is used to determine which database to use. For a local database, it contains the name of the database to access. For network access via gnatsd, it contains a colon-separated list of strings that describe the remote database, in the form server:port:databasename:username:password Any of the fields may be omitted, but at least one colon must appear; otherwise, the value is assumed to be the name of a local database. If GNATSDB is not set, it is assumed that the database is local and that its name is default. SEE ALSO
Keeping Track: Managing Messages With GNATS (also installed as the GNU Info file gnats.info) and Reporting Problems Using send-pr (also in- stalled as the GNU Info file send-pr.info). databases(5), dbconfig(5), delete-pr(8), edit-pr(1) file-pr(8), gen-index(8), gnats(7), gnatsd(8), mkcat(8), mkdb(8), pr-edit(8), query- pr(1), queue-pr(8), send-pr(1). COPYING
Copyright (c) 1993 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be included in translations approved by the Free Software Foundation instead of in the original English. GNATS
August 2003 gen-index(8)
All times are GMT -4. The time now is 06:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy