0

I know now how to store the result of sql procédure in shell variable

testvar=$(sqlplus foo/bar @test.sql)

my test.sql return a list of integer that i would use in another select calling by my shell. The aim of this procedure is to show the progress avancement of my treatment like

x=0;
while x <testvar.size
sqlplus foo/bar @test2.sql $testvar.x
print (x*100/testvar.size + "%")
end while 

(i dont know shell programming but it's easiest than my current problem...

2
  • I'm using bash script and I don't even know how to make it but i have people around me to help me on that but no on this problem Commented Sep 12, 2011 at 15:30
  • I am not familiar with the output of sqlplus. Could you paste some sample output when you run it with your script as input? If so I can tell you how to parse it form bash. Commented Sep 12, 2011 at 16:14

1 Answer 1

2

If the output of sqlplus is literally "A list of integers" as you describe, then this is easy enough.

SOMETHING=5

while -r read n ; do
    if [ $n -ge $SOMETHING ] ; then
        break
    fi
    sqlplus foo/bar @test2.sql "$n"
    printf '%.2f%%\n' $(expr "$n" \* 100 / "$SOMETHING")
done < <(sqlplus foo/bar @test.sql)

Presuming that "A list of integers" really means "A newline separated list of integers"

It's not clear to me what $testvar.x and testvar.size are supposed to represent, so I made some guesses and left the variable $SOMETHING to stand in for whatever testvar.size is supposed to be. If you want the total number of integers in the list from sqlplus then that would be different, and done like this:

intlist=($(sqlplus foo/bar @test.sql))

for n in "${intlist[@]}"; do
    if [ $n -ge ${#intlist[@]} ] ; then
        break
    fi
    sqlplus foo/bar @test2.sql "$n"
    printf '%.2f%%\n' $(expr "$n" \* 100 / ${#intlist[@]})
done < <(sqlplus foo/bar @test.sql)

If your output is more complex some additional filtering will need to be done up front.

Sign up to request clarification or add additional context in comments.

1 Comment

the second option is litteraly what I needed ! My test.sql is a select on id from a table. I'm home know but i'll make it tomorrow and tell you how I use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.