# how towrite sql in shell scripting

**URL:** <https://community.unix.com/t/how-towrite-sql-in-shell-scripting/189728>\
**Category:** Shell Programming and Scripting\
**Created:** [March 20, 2008, 5:33am UTC](https://community.unix.com/t/how-towrite-sql-in-shell-scripting/189728 "2008-03-20T05:33:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![naveeng.81](https://community.unix.com/letter_avatar/naveeng.81/32/6_449c533f586939b6e5f246632a46421f.png) [@naveeng.81](https://community.unix.com/u/naveeng.81)\
**Post date:** [March 20, 2008, 5:33am UTC](https://community.unix.com/t/how-towrite-sql-in-shell-scripting/189728/1 "2008-03-20T05:33:26Z")

</div>

hi  
iam new of scipiting.give me the some Material of regarding sql in scripting.  
and i have no backup's in 3 severs.how to write script in dirctory.  
please give me some usefull information

cheers  
Naveen.g

---

<div class="post-metadata">

**Author:** ![raman1605](https://community.unix.com/letter_avatar/raman1605/32/6_449c533f586939b6e5f246632a46421f.png) [@raman1605](https://community.unix.com/u/raman1605)\
**Post date:** [March 20, 2008, 5:36am UTC](https://community.unix.com/t/how-towrite-sql-in-shell-scripting/189728/2 "2008-03-20T05:36:51Z")

</div>

Here is sm example code that you can use accordingly.

```nohighlight
  diffdays=`sqlplus -s <username>/<password> <<END
  set pagesize 0
  set feedback off
  set heading off
  set echo off
  set verify off
  select to_date($sysdate, 'yyyymmdd') - to_date($currfile, 'yyyymmdd') from dual;

```

diffdays will be having the output of the query in this case

---

<div class="post-metadata">

**Author:** ![curleb](https://community.unix.com/letter_avatar/curleb/32/6_449c533f586939b6e5f246632a46421f.png) [@curleb](https://community.unix.com/u/curleb)\
**Post date:** [March 20, 2008, 5:05pm UTC](https://community.unix.com/t/how-towrite-sql-in-shell-scripting/189728/3 "2008-03-20T17:05:30Z")

</div>

Just make sure you note the heredoc in the example ... and that you make sure to close it:

```nohighlight
  diffdays=`sqlplus -s <username>/<password> <<END
  set pagesize 0
  set feedback off
  set heading off
  set echo off
  set verify off
  select to_date($sysdate, 'yyyymmdd') - to_date($currfile, 'yyyymmdd') from dual;

```

```nohighlight
END ` 

```
