Sqlplus variable UNIX

hi guys
i have a sqlplus :

sqlplus -s  username/password << EOF
@mysql.sql
EOF

in mysql.sql there is a count of a table, i want to write in a variabile unix.
how can i do?
Thanks a lot
Regards
Francesco.

You could try:

somevar=$(sqlplus ...
EOF)

You'll need some directives in your SQL to throw away everything in the output except the value you're looking for.

SQL is / was a bit funny with file descriptors if I remember, and it's been a while since I've used it, so can't guarantee that will work.

Could i suggest that you get your credentials moved too?

Something more like:-

somevar=$(sqlplus <<EOSQL
username/password
@my.sql
EOSQL)

This will, of course, take ALL the output fromt he sqlplus command, so you might need to think about that. Perhaps add the -s flag to suppress much of the informational output might help you there.

Robin

For a task like that the file descriptors shouldn't be a problem.
I do not see why a heredoc is needed, sqlplus can process a sql-commandfile if told so:

$ a=$(sqlplus -s /nolog @a.sql)
$ echo "$a"

10-OCT-17
$ cat a.sql
set heading off
connect / as sysdba;
select sysdate from dual;
exit

Using bash on Debian 9, Oracle XE.