# Executing Multiple Queries in parallel in Shell

**URL:** <https://community.unix.com/t/executing-multiple-queries-in-parallel-in-shell/332826>\
**Category:** Shell Programming and Scripting\
**Created:** [August 8, 2013, 5:14am UTC](https://community.unix.com/t/executing-multiple-queries-in-parallel-in-shell/332826 "2013-08-08T05:14:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niranjancse](https://community.unix.com/letter_avatar/niranjancse/32/6_22734026db12803ebb3e059622ac3534.png) [@Niranjancse](https://community.unix.com/u/Niranjancse)\
**Post date:** [August 8, 2013, 5:14am UTC](https://community.unix.com/t/executing-multiple-queries-in-parallel-in-shell/332826/1 "2013-08-08T05:14:03Z")

</div>

I have n number of SQL queries needs to executed in Shell. Result of this query need to assign in a variable. Once all the queries are executed script needs to exit.

Sample Query:

SQL 1: Select Count(\*) from TABLE GROUP BY COL1,COL2

SQL 2: Select Count(\*) from TABLE GROUP BY COL1,COL2

Result of the above queries need to assign in variables and shell needs to exit once execution of all queries completed.

Can any one post how it can be achieve in shell script?

Envionment: LINUX  
Database : ORACLE 11.G

---

<div class="post-metadata">

**Author:** ![Showdown](https://community.unix.com/letter_avatar/showdown/32/6_22734026db12803ebb3e059622ac3534.png) [@Showdown](https://community.unix.com/u/Showdown)\
**Post date:** [August 8, 2013, 7:51am UTC](https://community.unix.com/t/executing-multiple-queries-in-parallel-in-shell/332826/2 "2013-08-08T07:51:01Z")

</div>

two times you have to connect. or else create two shells containing the sqls and call using nohup command and check the exit status.

```nohighlight
#!/bin/ksh

x=`sqlplus scott/tiger -s / <<endl | grep KEEP | sed 's/KEEP//;s/[]//g'
Select Count(*) from TABLE GROUP BY COL1,COL2;
exit
endl`
y=`sqlplus / <<endl | grep KEEP | sed 's/KEEP//;s/[]//g'
Select Count(*) from TABLE GROUP BY COL1,COL2;
exit
endl`

```

---

<div class="post-metadata">

**Author:** ![Niranjancse](https://community.unix.com/letter_avatar/niranjancse/32/6_22734026db12803ebb3e059622ac3534.png) [@Niranjancse](https://community.unix.com/u/Niranjancse)\
**Post date:** [August 13, 2013, 4:42am UTC](https://community.unix.com/t/executing-multiple-queries-in-parallel-in-shell/332826/3 "2013-08-13T04:42:03Z")

</div>

Also all the queries are writted in Parameter file. I need to read the queries from parameter one by one and pass to the Oracle.
