While passing 1 character variables from sqlplus to shell, I find this annoying anomaly.
echo "Please enter the upgrade option: "
read type
if [[ "$type" != "1" ]] && [[ "$type" != "2" ]]
then
echo "You have entered an invalid response. Exiting."
exit 0;
fi
sql_result=$($ORACLE_HOME/bin/sqlplus -s /nolog <<-EOF
connect $eval_user/$eval_pass@$db_name
SPOOL results.txt;
WHENEVER OSERROR EXIT 9;
DEFINE vType = '$type'
DEFINE type_flag = '$t_flag'
DEFINE vOrigowner = '$origOwner'
@@EV_DBUPGRADE.sql '&vType' '&vOrigowner' '&vAppConvFromDt' '&vAppConvThruDt' '&vAppConvStatusFlg' '&type_flag'
Under EV_DBUPGRADE.sql, I find this error while using the variable vType:
vOption varchar2(1) := UPPER('&1');
I get this annoying error that complains of buffer length
declare
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 7
the error doesn't happen if the varchar2(10) is used. But, I don't want to change it in a million different places. Is there anyway to restrict it? And can anyone please tell me how to print debug messages in sqlplus outside of the BEGIN?
$fooin shell is not guaranteed to pass it in the form it was given -- it can be split into multiple arguments, expanded as a pattern, removed entirely (if all characters are in$IFS, etc). Always use quote your variables in shell, as in"$foo".