A script pls( To retrieve database information)

KSH - Unix -AIX - db2

**************
Get the input from the user say '123' (It varies)

Then i want to connect to a database say "D1"
then i want th extract from the database by giving "select * from tablename where input = '123'

I also want to connect to another database "D2"
then i want th extract from the database by giving "select * from tablename where input = '123'

output should be displayed on the screen as it is when i execute the select statements individually.
********************************
This is what i want to do in a script

Can you show a script for that(For eg)?

##############################################
Data Base Connection & Get information from DB
##############################################

echo "Enter Input File Name"
read FILE

# To check the value in TABLE_CFS_DUMP table FILE_NAME value

RETVAL=`sqlplus -silent USERNAME/PASSWORD@DBNAME <<EOF
set pagesize 0 feedback off verify off heading off echo off
select * from TABLE_CFS_DUMP where FILE_NAME like '$FILE';
exit;
END`

echo "The DB Query Output is: $RETVAL "

Is this a script . Can i have it in a well defined form? please

this smells like homework.... please read the rules!