puneet
puneet

Reputation: 89

sqlplus removes extra whitespace

I have a below test ksh file

#!/bin/ksh
(
sqlplus -s << EOF
    ${DATABASE}
    SET SERVEROUTPUT ON;
    SET HEAD OFF
    SET FEED OFF
    SET DEFINE OFF
    SET PAGES 0
    SET COLSEP ";"
    WHENEVER SQLERROR EXIT SQL.SQLCODE      
    SELECT 'aaaa  vvvv   cccc'  FROM DUAL;          
    EXIT
EOF
) | while read sql_out
    do
        echo ${sql_out} 
    done

The expected output is

aaaa  vvvv   cccc

however the output observed is

aaaa vvvv cccc

Sqlplus is stripping out extra white spaces from my output and I want to preserve it.

Upvotes: 1

Views: 496

Answers (1)

Alex Poole
Alex Poole

Reputation: 191235

It isn't SQL*Plus doing that, it's the shell. You need to enclose your variable in quotes:

To preserve whitespace within a string or in a variable, use quoting.

So instead of

echo ${sql_out}

do either of these:

echo "${sql_out}"
printf "%s\n" "${sql_out}"

and the output will then be:

aaaa  vvvv   cccc

Upvotes: 5

Related Questions