Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

oracle calling from shell unix script

Status
Not open for further replies.

keerthi2016

Programmer
Jul 20, 2015
14
0
0
IN
hi all,

I have tried unix scripting to call oracle functions. For the below requirement to call the oracle functions. kindly let me know whether it is a efficient code.

Oracle function to be called for the below scenario.
Code:
CASE 1: 
(LOCATION = 'chennai'| LOCATION = 'Banglore')
:VALUE:=LOCATION_COUNT.CHENNAI_BANG
               (&LOCATION,&SALES);
case 2: 
(LOCATION ='SALEM'|LOCATION = 'TRICHY' |LOCATION = 'PONDI')
:VALUE:=LOCATION_COUNT.SAL_TRICHY_PONDI
               (&LOCATION,&SALES);
 
case 3:
(LOCATION = 'TIRUPUR')
:VALUE:=LOCATION_COUNT.GET_TIRUP
               (&LOCATION,&SALES);

Code:
[b]Unix script :[/b]
cat function_check.ksh
chennai_blr () {
        VALUE=`sqlplus -S /NOLOG << EOF
        CONNECT dbs/passwd@dbtod
        SET head off
        SET serveroutput on
        select LOCATION_COUNT.CHENNAI_BANG
               (&LOCATION,&SALES) from dual;
        exit;
EOF
               }
 
Salem_Trichy_Pondi  () {
VALUE=`sqlplus -S /NOLOG << EOF
        CONNECT dbs/passwd@dbtod
        SET head off
        select :LOCATION_COUNT.SAL_TRICHY_PONDI
               (&LOCATION,&SALES) from dual;
        exit;
EOF`
 
     }
Tirupur () {
               VALUE=`sqlplus -S /NOLOG << EOF
        CONNECT dbs/passwd@dbtod
        SET head off
        select LOCATION_COUNT.GET_TIRUP
               (&LOCATION,&SALES); from dual;
        exit;
EOF`
           }
while read file
do
        if [[ "$file" == "chennai" || "$file" == "banglore" ]]
        then
                chennai_blr
        elif [[ "$file" == "salem" || "$file" == "trichy" || "$file" == "pondi" ]]
        then
                Salem_Trichy_Pondi
        elif [[ "$file" == "tripur" ]]
        then
                Tirupur
        else
                echo "You are out of chennai, blr, Salem_Trichy_Pondi and Tirupur, seems you are in $file"
        fi
done < "function_check"
 
The calling of the sql looks ok. I would probably change the stack of '[tt]if/then/else[/tt]' statements to a '[tt]case[/tt]' statment. It's easier to read, understand, and change.

Code:
case $file in
    chennai|bangalore)
        chennai_blr
        ;;
    salem|trichy|pondi)
        Salem_Trichi_Pondi
        ;;
    tirupur)
        Tirupur
        ;;
    *)
        echo "You are out of chennai, blr, Salem_Trichy_Pondi and Tirupur, seems you are in $file"
        ;;
esac
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top