Tuesday, February 16, 2010

Connect to SQL*PLUS(sqlplus) using shell script

The following script can be used to connect SQL*plus from a shell script and execute SQL statements.

function Execsql


{

        STATEMENT="$*"

        echo $STATEMENT

         sqlplus -s "username/pwd@sid" > /dev/null << END

          spool result.out

         $STATEMENT;

         quit
END

}

Execsql "Select sysdate from dual"


The function Execsql will accept an argument which will be executed by connecting to the DB.

The result will be spooled in result.out file.

The label END should be properly alligned.


No comments:

Powered By Blogger