SQL Plus and SQLcl Formatation Tip for Macbook users

Introduction about my “problem”

On my day-to-day work I use a lot of scripts in SQLPLUS and SQLcl, where the most of these scripts have custom column formatation. Another common task in my routine is to copy the output from SQLPLUS directly to another place like VisualStudio Code or even to the wordpress when I’m writing a new blog post like this one.

Usually, after copy the output from the SQLPLUS and paste in anywhere, the formatation is preserved fine, and I can save these results as evidence or example of my actions with the original and friendly formatation.

For example, consider the below query about ASM diskgroup usage:

SET LINES 400
COL NAME HEADING "Disksgroup"   FORMAT A20
COL TYPE HEADING "Redundancy"   FORMAT A10
COL TOTAL_GB HEADING "Total GB" FORMAT 999,999,999,999.99
COL USED_GB  HEADING "Used GB"  FORMAT 999,999,999,999.99
COL FREE_GB  HEADING "Free GB"  FORMAT 999,999,999,999.99
COL PERCFREE HEADING "Free %"   FORMAT 999.99 

SELECT x.*, ROUND(FREE_GB/TOTAL_GB*100,2) AS PERCFREE
FROM (
        SELECT NAME, 
               TYPE,
                   ( TOTAL_MB / DECODE(TYPE,'HIGH',3,'NORMAL',2,1) ) / 1024 AS TOTAL_GB, 
                   (( TOTAL_MB / DECODE(TYPE,'HIGH',3,'NORMAL',2,1) ) - USABLE_FILE_MB) / 1024 USED_GB,
                   USABLE_FILE_MB/1024 AS FREE_GB
        FROM V$ASM_DISKGROUP
) x
ORDER BY 1;

This result example as it appear in the screen:

And if I copy this to Visual Code, the result should be like this:

And if I copy this result to the wordpress box code, this should works fine as well:

Disksgroup           Redundancy            Total GB             Used GB             Free GB  Free %
-------------------- ---------- ------------------- ------------------- ------------------- -------
DATA                 EXTERN                   47.97               44.37                3.60    7.50
RECO                 EXTERN                   23.97               21.80                2.17    9.06

Macbook Terminal or iTerm2 behavior

When I started to work with an Macbook in the last year, I noticed that when I copy the result from SQLPLUS or SQLcl to VisualCode or to wordpress, the formatation was not preserved as I was used for years.

For example, the result presented in the screen not changed:

But after copy to Visual Code, the original formatation get something wrong:

And unfortunately I noticed the same behaviour copying the result for the blog:

Disksgroup	     Redundancy 	   Total GB		Used GB 	    Free GB  Free %
-------------------- ---------- ------------------- ------------------- ------------------- -------
DATA		     EXTERN		      47.97		  44.37 	       3.60    7.50
RECO		     EXTERN		      23.97		  21.80 	       2.17    9.06

Solution

So, after test a number of different configurations on Terminal and iTerm2, nothing worked for me.

But recenlty was learned that the solution for this is very simple, and have no need for specific configuration in the terminal being used: Just set “TAB OFF” option in the SQLPLUS or SQLcl:

set tab off;

Now, when I copy the query result from SQLPLUS or SQLcl from terminal to VisualCode, the formatation is preserved as expected:

And now the same result copied directly to blog post:

Disksgroup           Redundancy            Total GB             Used GB             Free GB  Free %
-------------------- ---------- ------------------- ------------------- ------------------- -------
DATA                 EXTERN                   47.97               44.37                3.60    7.50
RECO                 EXTERN                   23.97               21.80                2.17    9.06

So, I hope this simple blog post can help someone that are moving from Windows to Macbook and getting frustrated with this same behavior impacting old queries that worked fines for years.

Reference:

https://docs.oracle.com/en/database/oracle/oracle-database/23/sqpug/SET-system-variable-summary.html#GUID-A0FE37A8-0D8F-4FF2-A6C3-B08D2AB83211

1 thought on “SQL Plus and SQLcl Formatation Tip for Macbook users”

  1. Pingback: Reading List – July 2025 #1 – Gerald on IT

Leave a Comment

Scroll to Top