Showing posts with label compile. Show all posts
Showing posts with label compile. Show all posts

Monday, January 18, 2021

How to compile package spec and body dynamically in shell script in Oracle

Hi, This post is to show how to compile package spec and package body in bash script.

Compile package spec:

pkg_spec=`ls *.pks -1|sed -e ''s/\.pks$//''`;
pkg_body=`ls *.pkb -1|sed -e ''s/\.pkb$//''`;
compile_spec()
{
sqlplus -s <user>/<password>@<host>:<port>/<SID> << EOF
WHENEVER SQLERROR EXIT SQL.SQLCODE;
SET LINES 255
SET PAGES 0
SET FEEDBACK OFF
SET ECHO OFF
SET PAGESIZE 0
SET TIMING OFF
SET SERVEROUTPUT ON
SET TERM ON
ALTER PACKAGE $pkg_spec COMPILE PACKAGE;
EOF
}
compile=`compile_spec`
echo $compile
if [ $? -ne 0 ]; then
  echo "error in compiling package spec"
  exit 1
fi

Here, <user> should be replaced with your username.
Eg: user12

Likewise, <password>, <host>, <port> and <SID> should also be replaced with their respective values.

Compile package body:

compile_body()
{
sqlplus -s <user>/<password>@<host>:<port>/<SID> << EOF
WHENEVER SQLERROR EXIT SQL.SQLCODE;
SET LINES 255
SET PAGES 0
SET FEEDBACK OFF
SET ECHO OFF
SET PAGESIZE 0
SET TIMING OFF
SET SERVEROUTPUT ON
SET TERM ON
ALTER PACKAGE $pkg_body COMPILE BODY;
EOF
}
PKB=`compile_body`
echo $PKB
if [ $? -ne 0 ]; then
  echo "error in compiling body"
  exit 1
fi  


Cheers!!

Featured Posts

Sample Real Time Assignment in Oracle SOA