Oracle
 sql >> Base de données >  >> RDS >> Oracle

Renvoie la valeur du script sql au script shell

Un exemple bash avec l'utilisation d'une fonction bash (note ! Database OS-authentication "/")

#!/bin/bash

get_count () {
    sqlplus -s / <<!
    set heading off
    set feedback off
    set pages 0
    select count(*) from all_objects where object_type = '$1'; 
!
}

count=$(get_count $1)

echo $count

if [ "$count" -gt 0 ]; then
    echo "is greater than zero"
else
    echo "is less or equal to zero"
fi


~/tmp/ $ ./count.sh INDEX
2922
is greater than zero
~/tmp/ $ ./count.sh TABLE
1911
is greater than zero
~/tmp/ $ ./count.sh FUNCTION
226
is greater than zero
~/tmp/ $ ./count.sh "SUPEROBJECT"
0
is less or equal to zero