{"id":14773,"date":"2020-10-05T15:59:03","date_gmt":"2020-10-05T13:59:03","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/"},"modified":"2020-10-05T15:59:03","modified_gmt":"2020-10-05T13:59:03","slug":"automatic-column-formatting-in-oracle-sqlplus","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/","title":{"rendered":"Automatic column formatting in Oracle sqlplus"},"content":{"rendered":"<p>Column formatting was always a pain in sqlplus when writing queries on the prompt. Most people use tools like SQL Developer or Quest TOAD which can scroll horizontally when running queries against a database, but as a consultant you are often still forced to use sqlplus. Here&#8217;s the issue: When running e.g. a query on a table T1 (which is a copy of ALL_OBJECTS) it looks by default as follows and is hard to read:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; create table t1 as select * from all_objects;\n\nTable created.\n\ncbleile@orcl@orcl&gt; select owner, oracle_maintained, object_name from t1 where rownum &lt; 4;\n\nOWNER                                                                                                                            O\n-------------------------------------------------------------------------------------------------------------------------------- -\nOBJECT_NAME\n--------------------------------------------------------------------------------------------------------------------------------\nSYS                                                                                                                              Y\nTS$\n\nSYS                                                                                                                              Y\nICOL$\n\nSYS                                                                                                                              Y\nC_FILE#_BLOCK#\n\n<\/pre>\n<p>The column width is defined by the maximum length of the data type. I.e. for a VARCHAR2(128) a column of width 128 is defined in the output (if the linessize is less than the column width then the linesize defines the maximum column width displayed).<\/p>\n<p>You can format columns of course:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; column owner format a32\ncbleile@orcl@orcl&gt; column object_name format a32\ncbleile@orcl@orcl&gt; select owner, oracle_maintained, object_name from t1 where rownum &lt; 4;\n\nOWNER                            O OBJECT_NAME\n-------------------------------- - --------------------------------\nSYS                              Y TS$\nSYS                              Y ICOL$\nSYS                              Y C_FILE#_BLOCK#\n<\/pre>\n<p>But running lots of ad hoc queries in sqlplus is quite annoying if you have to format all columns manually.<br \/>\nThis has been resolved in sqlcl by using &#8220;set sqlformat ansiconsole&#8221;:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\noracle@oracle-19c6-vagrant:\/home\/oracle\/ [orcl] alias sqlcl=\"bash $ORACLE_HOME\/sqldeveloper\/sqldeveloper\/bin\/sql\"\noracle@oracle-19c6-vagrant:\/home\/oracle\/ [orcl] sqlcl cbleile\n\nSQLcl: Release 19.1 Production on Thu Oct 01 08:43:49 2020\n\nCopyright (c) 1982, 2020, Oracle.  All rights reserved.\n\nPassword? (**********?) *******\nLast Successful login time: Thu Oct 01 2020 08:43:51 +01:00\n\nConnected to:\nOracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production\nVersion 19.6.0.0.0\n\n\nSQL&gt; set sqlformat ansiconsole\nSQL&gt; select owner, oracle_maintained, object_name from t1 where rownum &lt; 4;\nOWNER   ORACLE_MAINTAINED   OBJECT_NAME      \n------- ------------------- ----------------\nSYS     Y                   TS$              \nSYS     Y                   ICOL$            \nSYS     Y                   C_FILE#_BLOCK#   \n<\/pre>\n<p>In sqlcl all rows up to &#8220;pagesize&#8221; are pre-fetched and the column-format is adjusted for the page to the maximum length per column. E.g.<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\nSQL&gt; set pagesize 1\nSQL&gt; select 'short' val from dual\n  2  union all\n  3  select 'looooooooooooooooooooooooooooooooooooooooooooooooooooooong' val from dual;\nVAL     \n-------\nshort   \n\nVAL                                                          \n------------------------------------------------------------\nlooooooooooooooooooooooooooooooooooooooooooooooooooooooong   \n\nSQL&gt; set pagesize 2\nSQL&gt; select 'short' val from dual\n  2  union all\n  3  select 'looooooooooooooooooooooooooooooooooooooooooooooooooooooong' val from dual;\nVAL                                                          \n------------------------------------------------------------\nshort   \nlooooooooooooooooooooooooooooooooooooooooooooooooooooooong   \n<\/pre>\n<p>REMARK: Due to the algorithm in sqlcl you can force sqlcl to crash with sqlformat ansiconsole if it does not have enough memory to pre-fetch the data for a single page. E.g. having lots of data returned and the maximum pagesize set (50000):<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\nSQL&gt; set sqlformat ansiconsole\nSQL&gt; set pagesize 50000\nSQL&gt; select \n  2  'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' a,\n  3  'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' b,\n  4  'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' c,\n  5  'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' d,\n....\n315  'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' y3,\n316  'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' z3\n317  from all_objects;\nException in thread \"main\" java.lang.OutOfMemoryError: GC overhead limit exceeded\n\tat java.util.Arrays.copyOfRange(Arrays.java:3664)\n\tat java.lang.String.(String.java:207)\n\tat oracle.sql.CharacterSetUTF.toStringWithReplacement(CharacterSetUTF.java:134)\n\tat oracle.sql.CHAR.getStringWithReplacement(CHAR.java:307)\n\tat oracle.sql.CHAR.toString(CHAR.java:318)\n\tat oracle.sql.CHAR.stringValue(CHAR.java:411)\n\tat oracle.dbtools.raptor.nls.DefaultNLSProvider.format(DefaultNLSProvider.java:208)\n\tat oracle.dbtools.raptor.nls.OracleNLSProvider.format(OracleNLSProvider.java:214)\n\tat oracle.dbtools.raptor.utils.NLSUtils.format(NLSUtils.java:187)\n\tat oracle.dbtools.raptor.format.ANSIConsoleFormatter.printColumn(ANSIConsoleFormatter.java:149)\n\tat oracle.dbtools.raptor.format.ResultSetFormatterWrapper.print(ResultSetFormatterWrapper.java:274)\n\tat oracle.dbtools.raptor.format.ResultSetFormatterWrapper.print(ResultSetFormatterWrapper.java:222)\n\tat oracle.dbtools.raptor.format.ResultsFormatter.print(ResultsFormatter.java:518)\n\tat oracle.dbtools.db.ResultSetFormatter.formatResults(ResultSetFormatter.java:124)\n\tat oracle.dbtools.db.ResultSetFormatter.formatResults(ResultSetFormatter.java:70)\n\tat oracle.dbtools.raptor.newscriptrunner.SQL.processResultSet(SQL.java:798)\n\tat oracle.dbtools.raptor.newscriptrunner.SQL.executeQuery(SQL.java:709)\n\tat oracle.dbtools.raptor.newscriptrunner.SQL.run(SQL.java:83)\n\tat oracle.dbtools.raptor.newscriptrunner.ScriptRunner.runSQL(ScriptRunner.java:404)\n\tat oracle.dbtools.raptor.newscriptrunner.ScriptRunner.run(ScriptRunner.java:230)\n\tat oracle.dbtools.raptor.newscriptrunner.ScriptExecutor.run(ScriptExecutor.java:344)\n\tat oracle.dbtools.raptor.newscriptrunner.ScriptExecutor.run(ScriptExecutor.java:227)\n\tat oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli.process(SqlCli.java:404)\n\tat oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli.processLine(SqlCli.java:415)\n\tat oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli.startSQLPlus(SqlCli.java:1249)\n\tat oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli.main(SqlCli.java:491)\noracle@oracle-19c6-vagrant:\/home\/oracle\/ [orcl] \n<\/pre>\n<p>But back to sqlplus: To address the issue with the column-formatting several solutions were developed. E.g. Tom Kyte provided a procedure <a href=\"https:\/\/asktom.oracle.com\/pls\/apex\/f?p=100:11:0::::P11_QUESTION_ID:1035431863958\">print_table<\/a> over 20 years ago to list each column and its value in a separate line:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; exec print_table('select owner, oracle_maintained, object_name from t1 where rownum &lt; 4&#039;);\nOWNER                 : SYS\nORACLE_MAINTAINED     : Y\nOBJECT_NAME           : TS$\n-----------------\nOWNER                 : SYS\nORACLE_MAINTAINED     : Y\nOBJECT_NAME           : ICOL$\n-----------------\nOWNER                 : SYS\nORACLE_MAINTAINED     : Y\nOBJECT_NAME           : C_FILE#_BLOCK#\n-----------------\n\nPL\/SQL procedure successfully completed.\n\n<\/pre>\n<p>The same can be done with xmltable since more recent versions. See e.g. <a href=\"http:\/\/orasql.org\/2013\/04\/02\/sqlplus-tips-2\/\">here<\/a>.<\/p>\n<p>That was perfect when querying a couple of rows.<\/p>\n<p>Alternatively some people used a terminal emulation which provided horizontal scrolling like terminator on Linux (see e.g. <a href=\"https:\/\/www.dbi-services.com\/blog\/sqlplus-and-its-column-output\/\">here<\/a>).<\/p>\n<p>What I wanted to provide in this blog is another solution. Usually the issue is with VARCHAR2-output. So I asked myself, why not formatting all VARCHAR2 columns of a table to their average length. I.e. I created a script colpp_table.sql (colpp, because my initial objective was to provide a column-width per page like in sqlcl) which takes the statistic avg_col_len from ALL_TAB_COLUMNS. To run the script I have to provide 2 parameters: The owner and table-name I use in my query later on:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; !more colpp_table.sql\nset termout off heading off lines 200 pages 999 trimspool on feed off timing off verify off\nspool \/tmp\/&amp;1._&amp;2..sql\nselect 'column '||column_name||' format a'||to_char(decode(nvl(avg_col_len,data_length),0,1,nvl(avg_col_len,data_length))) \nfrom all_tab_columns \nwhere owner=upper('&amp;1.') \nand table_name=upper('&amp;2.') \nand data_type in ('VARCHAR2','NVARCHAR2');\nspool off\n@\/tmp\/&amp;1._&amp;2..sql\nset termout on heading on feed on timing on verify on\n\ncbleile@orcl@orcl&gt; @colpp_table CBLEILE T1\n<\/pre>\n<p>I.e. a temporary script \/tmp\/&lt;owner&gt;_&lt;table_name&gt;.sql gets written with format-commands for all VARCHAR2 (and NVARCHAR2) columns of the table. That temporary script is automatically executed:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; !cat \/tmp\/CBLEILE_T1.sql\n\ncolumn OWNER format a5\ncolumn OBJECT_NAME format a36\ncolumn SUBOBJECT_NAME format a2\ncolumn OBJECT_TYPE format a10\ncolumn TIMESTAMP format a20\ncolumn STATUS format a7\ncolumn TEMPORARY format a2\ncolumn GENERATED format a2\ncolumn SECONDARY format a2\ncolumn EDITION_NAME format a1\ncolumn SHARING format a14\ncolumn EDITIONABLE format a2\ncolumn ORACLE_MAINTAINED format a2\ncolumn APPLICATION format a2\ncolumn DEFAULT_COLLATION format a4\ncolumn DUPLICATED format a2\ncolumn SHARDED format a2\n<\/pre>\n<p>Now the formatting looks much better without having to format each column manually:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; @colpp_table CBLEILE T1\ncbleile@orcl@orcl&gt; select owner, oracle_maintained, object_name from t1 where rownum &lt; 4;\n\nOWNER OR OBJECT_NAME\n----- -- ------------------------------------\nSYS   Y  TS$\nSYS   Y  ICOL$\nSYS   Y  C_FILE#_BLOCK#\n\n3 rows selected.\n<\/pre>\n<p>But what happens when selecting from a view? The column avg_col_len in all_tab_columns is NULL for views:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; create view t1v as select * from t1;\ncbleile@orcl@orcl&gt; column column_name format a21\ncbleile@orcl@orcl&gt; select column_name, avg_col_len from all_tab_columns where owner=user and table_name='T1V';\n\nCOLUMN_NAME           AVG_COL_LEN\n--------------------- -----------\nEDITIONABLE\nORACLE_MAINTAINED\nAPPLICATION\nDEFAULT_COLLATION\nDUPLICATED\nSHARDED\nCREATED_APPID\nCREATED_VSNID\nMODIFIED_APPID\nMODIFIED_VSNID\nOWNER\nOBJECT_NAME\nSUBOBJECT_NAME\nOBJECT_ID\nDATA_OBJECT_ID\nOBJECT_TYPE\nCREATED\nLAST_DDL_TIME\nTIMESTAMP\nSTATUS\nTEMPORARY\nGENERATED\nSECONDARY\nNAMESPACE\nEDITION_NAME\nSHARING\n\n26 rows selected.\n<\/pre>\n<p>My idea was to do the following: Why not taking the &#8220;bytes&#8221;-computation per column from the optimizer divided by the number of rows returned by the view? I.e.<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; explain plan for select owner from t1v;\n\nExplained.\n\ncbleile@orcl@orcl&gt; select * from table(dbms_xplan.display);\n\nPLAN_TABLE_OUTPUT\n---------------------------------\nPlan hash value: 3617692013\n\n--------------------------------------------------------------------------\n| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time\t |\n--------------------------------------------------------------------------\n|   0 | SELECT STATEMENT  |\t     | 67944 |   331K|   372   (1)| 00:00:01 |\n|   1 |  TABLE ACCESS FULL| T1   | 67944 |   331K|   372   (1)| 00:00:01 |\n--------------------------------------------------------------------------\n\n8 rows selected.\n<\/pre>\n<p>Now I just calculate the Bytes\/Rows. As I just select 1 column I do get approximately the avg_col_len with that:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; select 331000\/67944 from dual;\n\n331000\/67944\n------------\n  4.87165901\n<\/pre>\n<p>That value is close to the avg_col_len statistic of the underlying table:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; select avg_col_len from user_tab_columns where table_name='T1' and column_name='OWNER';\n\nAVG_COL_LEN\n-----------\n          5\n<\/pre>\n<p>So the remaining question was just where to get the bytes and cardinality computation from? It&#8217;s in the plan_table:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; select bytes, cardinality, ceil(bytes\/cardinality) avg_col_len from plan_table where id=0;\n\n     BYTES CARDINALITY AVG_COL_LEN\n---------- ----------- -----------\n    339720       67944           5\n<\/pre>\n<p>With that information I had everything to create a script colpp_explain.sql:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; !more colpp_explain.sql\nset termout off heading off lines 200 pages 999 trimspool on feed off timing off verify off\nset serveroutput on size unlimited\nspool \/tmp\/&amp;1._&amp;2..sql\ndeclare\n   avg_col_len number;\nbegin\n   for i in (select column_name from all_tab_columns where owner=upper('&amp;1.') and table_name=upper('&amp;2.') and data_type in ('VARCHAR2','NVARCHAR2')) loop\n      delete from plan_table;\n      execute immediate 'explain plan for select '||i.column_name||' from &amp;1..&amp;2.';\n      select ceil(bytes\/cardinality) into avg_col_len from plan_table where id=0;\n      dbms_output.put_line('column '||i.column_name||' format a'||to_char(avg_col_len+1));\n   end loop;\nend;\n\/\nspool off\n@\/tmp\/&amp;1._&amp;2..sql\nset termout on heading on feed on timing on verify on\nset serveroutput off\n<\/pre>\n<p>I.e. I&#8217;m looping through all columns with type VARCHAR2 (or NVARCHAR2) of the view and do an <\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\nexplain plan for\nselect &lt;column&gt; from &lt;view&gt;;\n<\/pre>\n<p>With that information I can compute the avg_col_len by dividing the bytes by the cardinality and add the column formatting command to a script, which I finally execute. <\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; @colpp_explain CBLEILE T1V\ncbleile@orcl@orcl&gt; !cat \/tmp\/CBLEILE_T1V.sql\ncolumn EDITIONABLE format a3\ncolumn ORACLE_MAINTAINED format a3\ncolumn APPLICATION format a3\ncolumn DEFAULT_COLLATION format a5\ncolumn DUPLICATED format a3\ncolumn SHARDED format a3\ncolumn OWNER format a6\ncolumn OBJECT_NAME format a37\ncolumn SUBOBJECT_NAME format a3\ncolumn OBJECT_TYPE format a11\ncolumn TIMESTAMP format a21\ncolumn STATUS format a8\ncolumn TEMPORARY format a3\ncolumn GENERATED format a3\ncolumn SECONDARY format a3\ncolumn EDITION_NAME format a67\ncolumn SHARING format a15\n\ncbleile@orcl@orcl&gt; select owner, oracle_maintained, object_name from t1v where rownum &lt; 4;\n\nOWNER  ORA OBJECT_NAME\n------ --- -------------------------------------\nSYS    Y   TS$\nSYS    Y   ICOL$\nSYS    Y   C_FILE#_BLOCK#\n\n3 rows selected.\n<\/pre>\n<p>To use a single script for tables and views I created a simple wrapper-script around colpp_table.sql and colpp_explain.sql:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; !cat colpp.sql\nset termout off heading off lines 200 pages 999 trimspool on feed off timing off verify off\ndefine var=colpp_explain.sql\ncolumn objt new_value var\nselect decode(object_type,'TABLE','colpp_table.sql','colpp_explain.sql') objt from all_objects where owner=upper('&amp;1.') and object_name=upper('&amp;2.');\n@@&amp;var. &amp;1. &amp;2.\nset termout on heading on feed on timing on verify on\n<\/pre>\n<p>I.e. if the parameter is a table-name I do call colpp_table.sql. Otherwise I call colpp_explain.sql.<\/p>\n<p>Finally it looks as follows:<\/p>\n<p>For the table:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; @colpp CBLEILE T1\ncbleile@orcl@orcl&gt; select owner, oracle_maintained, object_name from t1v where rownum &lt; 4;\n\nOWNER OR OBJECT_NAME\n----- -- ------------------------------------\nSYS   Y  TS$\nSYS   Y  ICOL$\nSYS   Y  C_FILE#_BLOCK#\n<\/pre>\n<p>For the view:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\ncbleile@orcl@orcl&gt; @colpp CBLEILE T1V\ncbleile@orcl@orcl&gt; select owner, oracle_maintained, object_name from t1v where rownum &lt; 4;\n\nOWNER  ORA OBJECT_NAME\n------ --- -------------------------------------\nSYS    Y   TS$\nSYS    Y   ICOL$\nSYS    Y   C_FILE#_BLOCK#\n<\/pre>\n<p>I.e. with a call to colpp.sql I can format all VARCHAR-columns of a table or a view. It&#8217;s of course not perfect, but easy, quick and better than the default-settings. You may even extend the scripts to also provide the heading per column or specify a sql_id or a script as parameters to colpp.sql.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Column formatting was always a pain in sqlplus when writing queries on the prompt. Most people use tools like SQL Developer or Quest TOAD which can scroll horizontally when running queries against a database, but as a consultant you are often still forced to use sqlplus. Here&#8217;s the issue: When running e.g. a query on [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[59],"tags":[1333,2130,2131,985],"type_dbi":[],"class_list":["post-14773","post","type-post","status-publish","format-standard","hentry","category-oracle","tag-column","tag-format","tag-print_table","tag-sqlplus"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Automatic column formatting in Oracle sqlplus - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automatic column formatting in Oracle sqlplus\" \/>\n<meta property=\"og:description\" content=\"Column formatting was always a pain in sqlplus when writing queries on the prompt. Most people use tools like SQL Developer or Quest TOAD which can scroll horizontally when running queries against a database, but as a consultant you are often still forced to use sqlplus. Here&#8217;s the issue: When running e.g. a query on [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-05T13:59:03+00:00\" \/>\n<meta name=\"author\" content=\"Clemens Bleile\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ifgtxD2SrQ8r!YuXj\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Clemens Bleile\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/\"},\"author\":{\"name\":\"Clemens Bleile\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da\"},\"headline\":\"Automatic column formatting in Oracle sqlplus\",\"datePublished\":\"2020-10-05T13:59:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/\"},\"wordCount\":733,\"commentCount\":2,\"keywords\":[\"column\",\"format\",\"print_table\",\"sqlplus\"],\"articleSection\":[\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/\",\"name\":\"Automatic column formatting in Oracle sqlplus - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2020-10-05T13:59:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Automatic column formatting in Oracle sqlplus\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da\",\"name\":\"Clemens Bleile\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g\",\"caption\":\"Clemens Bleile\"},\"description\":\"Clemens Bleile has more than 30 years of IT experience, thirteen in Oracle Support and fifteen in Oracle Consulting. He is specialized in Oracle Database Performance Tuning (SQL Tuning, DB Tuning) and developing an Oracle DB IT architecture (highly available, low-maintenance, cost efficient storage of data). He is an expert in problem analysis and resolution. Prior to joining dbi services, Clemens Bleile was Manager of the EMEA Database Performance team at the Oracle Global Customer Support Services. Clemens Bleile is Oracle Certified Professional 11g, 12c and Oracle Certified Expert for Performance Management and Tuning and holds a Master Degree, Business Information Systems from the Fachhochschule Furtwangen, Germany.\",\"sameAs\":[\"https:\/\/www.dbi-services.com\",\"https:\/\/x.com\/ifgtxD2SrQ8r!YuXj\"],\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/clemens-bleile\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Automatic column formatting in Oracle sqlplus - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/","og_locale":"en_US","og_type":"article","og_title":"Automatic column formatting in Oracle sqlplus","og_description":"Column formatting was always a pain in sqlplus when writing queries on the prompt. Most people use tools like SQL Developer or Quest TOAD which can scroll horizontally when running queries against a database, but as a consultant you are often still forced to use sqlplus. Here&#8217;s the issue: When running e.g. a query on [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/","og_site_name":"dbi Blog","article_published_time":"2020-10-05T13:59:03+00:00","author":"Clemens Bleile","twitter_card":"summary_large_image","twitter_creator":"@ifgtxD2SrQ8r!YuXj","twitter_misc":{"Written by":"Clemens Bleile","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/"},"author":{"name":"Clemens Bleile","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da"},"headline":"Automatic column formatting in Oracle sqlplus","datePublished":"2020-10-05T13:59:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/"},"wordCount":733,"commentCount":2,"keywords":["column","format","print_table","sqlplus"],"articleSection":["Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/","url":"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/","name":"Automatic column formatting in Oracle sqlplus - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2020-10-05T13:59:03+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/automatic-column-formatting-in-oracle-sqlplus\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Automatic column formatting in Oracle sqlplus"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da","name":"Clemens Bleile","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g","caption":"Clemens Bleile"},"description":"Clemens Bleile has more than 30 years of IT experience, thirteen in Oracle Support and fifteen in Oracle Consulting. He is specialized in Oracle Database Performance Tuning (SQL Tuning, DB Tuning) and developing an Oracle DB IT architecture (highly available, low-maintenance, cost efficient storage of data). He is an expert in problem analysis and resolution. Prior to joining dbi services, Clemens Bleile was Manager of the EMEA Database Performance team at the Oracle Global Customer Support Services. Clemens Bleile is Oracle Certified Professional 11g, 12c and Oracle Certified Expert for Performance Management and Tuning and holds a Master Degree, Business Information Systems from the Fachhochschule Furtwangen, Germany.","sameAs":["https:\/\/www.dbi-services.com","https:\/\/x.com\/ifgtxD2SrQ8r!YuXj"],"url":"https:\/\/www.dbi-services.com\/blog\/author\/clemens-bleile\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/14773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=14773"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/14773\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=14773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=14773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=14773"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=14773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}