I have a query (SQL) that returns a rather long field from an Oracle database. The field in question is defined on 400 characters but all these 400 cannot be displayed by the echo command. Thus when I launch the following command:
echo "SELECT FIELD01 FROM TABLE_NAME;" | sqlplus -s <login>/<password>@<CONNECTION_NAME>
The advantages of using this structure over what you have are many:
1) keeps your password slightly more protected from prying eyes. it's much harder to sniff out (probably not impossible, but I'm not aware of a simple way to do it at this time).
2) you can build sql scripts in stand alone files, that actually "LOOK" like sql scripts. So they can have "set" commands at the start, var commands set if needed, parameters passed into them (using "&1", "&2", etc to catch them), and many queries if need be. Or as you need, even a simple, single SQL.
3) you can wrap unix braces around that block to capture all output in log file, variable, or whatever you need:
(that one's untested, sorry, I don't use that format alot myself)
but yeah, two main points are:
a) don't expose your password - use the connect keyword to delay the login and keep the password off the command line, or use External Ids, or some other login mechanism to help protect your password.
b) keep your sql in standalone sql scripts so you can easily test/modify it. Then all you need is "pass it through" to sql, via some wrapper, or such as above.
Tried setting the line size using myriad commands. However I keep getting the error message 'linesize option not a valid number' which is really weird since I am giving 400 which is definitely a valid number.
To be clear I am launching both queries together which is:
set lines 400;SELECT <column_name> FROM <table_name>;
This is because I ideally would not like to again have to create a script file (since that would mean an extra component.
Irregardless of your final destination, you have a problem, and are troubleshooting.
Create a script file for test purposes .. and see how it behaves ...
You just might find how much easier it is to troubleshoot
Once you have things figured out, you can always splice it back into your "one-liner" solution if you need it
Edit:
fully working sample ... try to setup this working sample first .. then change "my.sql" to use your query instead of the select * from dual .. and see what changes.
unix > more *
::::::::::::::
my.sql
::::::::::::::
set linesize 400
set pause off
select *
from dual;
::::::::::::::
sql.ksh
::::::::::::::
{
sqlplus -s /nolog << EOF
connect myid/password@dbname
@./my.sql
exit
EOF
} >./my_log.log 2>&1
unix > ksh sql.ksh
unix > ls -ltr
total 6
-rw-r----- 1 ditto group1 57 Jan 13 09:48 my.sql
-rw-r----- 1 ditto group1 121 Jan 13 09:51 sql.ksh
-rw-r----- 1 ditto group1 83 Jan 13 09:51 my_log.log
unix > more my_log.log
D
-
X
unix >
sqlplus -s <login>/<password>@<CONNECTION_NAME> << EOF
set serveroutput on
set trimspool on
set feedback off
set pagesize 0
set linesize 400
spool sqlresults.txt
SELECT <column_name> FROM <table_name>;
spool off
EOF