0

I have a Query(Oracle) in Bash like that

RETVAL=`sqlplus -S /nolog <<EOF
         connect $ORCL_USR/$ORCL_PWD@$ORCL_TNS;
        SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
        select trim(Colm1) from $MyTable 
    EXIT;
    EOF`
 Result="Result.txt"
 touch $Result
 echo "$RETVAL" >> "$Result"
 cat $Result

If i just select a column then the result is correct , every column( i just have a column) have a line so.

cat Result.txt
 111
 222
 333

The problem is when i try to query 2 columns or more so in Revalt i put:

  select trim(Colm1),trim(column2) from $MyTable

when i do the Cat $Result.txt the result is:

111
Car
222
Hause
333
Dog

when i would wish

111 Car
222 Hause
333 Dog

So every row in a line for the File.

How can achieve it?

Thanks in Advance , Enrique

4
  • 1
    What are the column data types in your table? Looks like the output is being wrapped because it is too wide. Possible duplicate if you just need to set linesize.. Commented Jul 12, 2017 at 11:44
  • Hi @AlexPoole I thoung the same Column1 -> nummber , Column2-> Varchar 255 , it seems what you said. I ll try it. Commented Jul 12, 2017 at 11:59
  • 1
    OK, then try adding LINESIZE 300 to your SET command. Why are you using trim() for a number - so it's aligned on the left instead of the right? Using to_char() would be more intuitive. Commented Jul 12, 2017 at 12:20
  • Adding set LINESIZE 300 to the SET command ,didn't solve the problem. i just put the trim() cause i wanted to be sure that was not empty whitespace in the database(even if it was a number) . I know it could seen stupied but i was desesperate. Commented Jul 12, 2017 at 13:48

1 Answer 1

1

You can use the spool command to get the desired output.

sqlplus -S /nolog <<EOF
connect $ORCL_USR/$ORCL_PWD@$ORCL_TNS;
spool filepath/Result.txt
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
select trim(Colm1),trim(column2) from $MyTable 
EXIT;
spool off;
EOF
cat filepath/Result.txt
Sign up to request clarification or add additional context in comments.

3 Comments

Hi @Lohit thanks for the idea but with Spool i have exactly the same result.
@Enrique check the column width of your columns and set linesize accordingly. I think linesize is exceeding the column width.
Hi @Lohit i did it but it didnt get better . :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.