# Executing procedure using script

**URL:** <https://community.unix.com/t/executing-procedure-using-script/317525>\
**Category:** Shell Programming and Scripting\
**Created:** [October 1, 2012, 11:01am UTC](https://community.unix.com/t/executing-procedure-using-script/317525 "2012-10-01T11:01:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sv0081493](https://community.unix.com/letter_avatar/sv0081493/32/5_5575768a8748004e209b776fc1b2916d.png) [@sv0081493](https://community.unix.com/u/sv0081493)\
**Post date:** [October 1, 2012, 11:01am UTC](https://community.unix.com/t/executing-procedure-using-script/317525/1 "2012-10-01T11:01:21Z")

</div>

Hi,

I want to have a automted script to exceute 20 procedures one by one.  
Suppose below is one procedure once it get executed script will write  
"PL/SQL procedure successfully completed." to a log

for ex-

```nohighlight
exec dbms_stats.gather_table_stats();

```

Now later procedure starts executing only when previous one gets completed.  
Can it be possible to have such script

Your prompt help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [October 1, 2012, 11:13am UTC](https://community.unix.com/t/executing-procedure-using-script/317525/2 "2012-10-01T11:13:43Z")

</div>

See the top line: the proc name followed by \. Add as many procedures as you wish.  
They have to be procedures because functions produce a return value. procedures do not.

```nohighlight
for proc in 'dbms_stats.gather_table_stats();' \
                'dbms_stats.foo_table_stats();' \
                'dbms_stats.bar_table_stats();' \
                'last you procedure want goes here with a comma at the end ; '
do
   $ORACLE_HOME/bin/sqlplus -s user/password@oracleinstancename <<EOF
    set lines 120
    set whatever else you want
    DECLARE
    BEGIN
    $proc
    exit
    END;
/
EOF
    echo "$proc Succesfully completed"
done > mylogfile.log

```

See the two EOF? they have to be placed exactly as shown, with the last EOF has to be in the leftmost column. The /  
above the last EOF also should be in the leftmost column.
