@Corona688 - I created a new script, the content is:
#!/bin/sh
ORACLE_HOME=/apps/oracle/10.2.0.4
export ORACLE_HOME
sqlplus u/p@sid <<selectupdate
spool selectupdateX.txt
@<script>.sql;
selectupdate
It created a file called selectupdateX.txt, and the contents are:
SQL> @<script>.sql;
93
I did try adding a -r after sqlplus, however when executing the script the sqlplus help popped up and nothing else happened (no file).
I'll keep playing with this, but do you have any more ideas?
@Peasant - I tried your script too:
#!/bin/sh
ORACLE_HOME=/apps/oracle/10.2.0.4
export ORACLE_HOME
(
sqlplus /nolog <<EOF
conn TMH7ESD0_TM_ONLINE/TMH7ESD0_TM_ONLINE@TMH3ESD0
@scrambler_SELECT_UPDATE_V0.4.sql;
EOF
) tee selectupdateX.txt
This generated the following error:
-bash: <scriptname>.sh: line 11: syntax error near unexpected token `tee'
-bash: <scriptname>.sh: line 11: `) tee selectupdateX.txt'
I haven't attempted to figure out the errors yet.
I'm going to keep trying with both versions.
Not sure I'll be able to put bash scripting as a skill on my CV just yet
Cheers,
g
---------- Post updated at 09:14 AM ---------- Previous update was at 03:34 AM ----------
There's something "wrong" with the SQL that I'm running within <script.sql>. Basically the SQL generates a whole load of UPDATE statements through CASE statements.
When I do something like this...
sqlplus u/p@sid <<selectupdate
spool selectupdateX.txt
select id from <table>;
selectupdate
...then the selectupdateX.txt file is generated with a list of ids!!
When I do something like this...
sqlplus u/p@sid <<selectupdate
spool selectupdateX.txt
select case when ... blah blah end from <table> where <something>;
selectupdate
...then the selectupdateX.txt file is generated with nothing other than some sqlplus stuff, no UPDATE statements at all.
The issue I have looks like it's because of something dodgy happening with the SQL, and not the UNIX script itself... but maybe I'm wrong...
---------- Post updated at 09:31 AM ---------- Previous update was at 09:14 AM ----------
Got it, and I feel pretty stupid. I failed to add a semi colon to the end of my massive select statement, so... that's the reason it wasn't doing what I hoped.
Thanks again for everyone's help, appreciated.