# Dynamic SQL query based on shell script parameters

**URL:** <https://community.unix.com/t/dynamic-sql-query-based-on-shell-script-parameters/259134>\
**Category:** Shell Programming and Scripting\
**Created:** [February 8, 2010, 1:55am UTC](https://community.unix.com/t/dynamic-sql-query-based-on-shell-script-parameters/259134 "2010-02-08T01:55:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![laiko](https://community.unix.com/letter_avatar/laiko/32/6_449c533f586939b6e5f246632a46421f.png) [@laiko](https://community.unix.com/u/laiko)\
**Post date:** [February 8, 2010, 1:55am UTC](https://community.unix.com/t/dynamic-sql-query-based-on-shell-script-parameters/259134/1 "2010-02-08T01:55:15Z")

</div>

Hi,

I need a script that will run a dynamic Oracle SQL. Dynamic meaning the SQL statement depends on the parameter.  
For instance, something like this:

```nohighlight
#!/bin/ksh -x

# Set environment
. /home/mine/set_vars

sqlplus $LOGINID <<! >> /home/mine/log.txt
select count(1) from $1
where init_date = $2;
exit;

```

Please help.. thanks in advance.

---

<div class="post-metadata">

**Author:** ![clx](https://community.unix.com/letter_avatar/clx/32/6_449c533f586939b6e5f246632a46421f.png) [@clx](https://community.unix.com/u/clx)\
**Post date:** [February 8, 2010, 3:11am UTC](https://community.unix.com/t/dynamic-sql-query-based-on-shell-script-parameters/259134/2 "2010-02-08T03:11:24Z")

</div>

Did you try or just asking?  
shell variable should work inside sql.

---

<div class="post-metadata">

**Author:** ![laiko](https://community.unix.com/letter_avatar/laiko/32/6_449c533f586939b6e5f246632a46421f.png) [@laiko](https://community.unix.com/u/laiko)\
**Post date:** [February 8, 2010, 3:54am UTC](https://community.unix.com/t/dynamic-sql-query-based-on-shell-script-parameters/259134/3 "2010-02-08T03:54:25Z")

</div>

Thanks anchal... yes that worked  
I found out there's some other problem in the code so it was not working.  
I thought that's because of those params..
