Reading data from multiple tables from Oracle DB

Hi ,

I want to read the data from 9 tables in oracle DB into 9 different files in the same connection instance (session). I am able to get data from one table to one file with below code :

X=`sqlplus -s user[EMAIL="user/pwd@c"]/pwd@DB[/EMAIL] <<eof
select col1 from table1;
EXIT;
eof`
echo $X>myfile

Can anyone suggest how the code can be modified to read multiple tables?

sqlplus -s user/pwd@DB <<eof
spool file1.txt
select col1 from table1;
spool file2.txt
select col2 from table2;
spool file3.txt
select col3 from table3;
:
:
spool file9.txt
select col9 from table9;
spool off
EXIT;
eof

Thanks !! Its working :slight_smile: