Storing passing and executing select statement in loop
Hi,
i want to do the following:
Grep the following kind of strings for the 15digit ID which is stored in filename1:
I achieved this using the following:
But i want this output in another file , say demo.txt
expected output of demo.txt:
Now, if we are able to get this , i want to pass the contents of this file, line by line, ID by ID to an SQL select Statement, using for loop:
For eg:
And while doing this we want to store the select staement's output in some variable. Then use this final variable for further processing.
please help in achieving this.
Last edited by Corona688; 08-25-2015 at 12:36 PM..
Reason: code tags, not font tags
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Thank You.
The UNIX and Linux Forums
These 2 Users Gave Thanks to Corona688 For This Post:
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:
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:
3.output.sql file contains following:
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.
There are two issues I see:
A SQL-Statement is terminated by a semicolon, which seems to be missing in output.sql.
A minus sign should be avoided in table names. If it is present the table name has to be put into double quotes. The double quotes make the reference to the table case sensitive, so make sure you reference it the way it was created (the user_tables view tells you the correct name).
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)