This article will give samples how database client display CLOB column for DB2 and Oracle
DB2 client only show first 8K length, the rest are truncated with following WARNING message.
> DB29320W Output has been truncated.
I had not find a way to let DB2 client display CLOB length greater than 8K.
Oracle sqlplus has 3 setting items that will impact CLOB display
1. set LINESIZE [80|<int>] -- Sets the total number of characters that SQL*Plus displays on one line before beginning a new line.
2. set LONG [80|<int>] -- Sets maximum width (in bytes) for displaying CLOB, LONG, NCLOB and XMLType values; and for copying LONG values.
3. set LONGCHUNKSIZE [80|<int>] -- Sets the size (in bytes) of the increments SQL*Plus uses to retrieve a CLOB, LONG, NCLOB or XMLType value.
4. set wrap off -- Controls whether to truncate the display of a selected row if it is too long for the current line width. OFF truncates the selected row; ON enables the selected row to wrap to the next line.
I did not understand very much about the LONGCHUNKSIZE and LINESIZE how they affect display line; based on testing result, my conclusion is that the smaller will take effect; i.e., the real line length is determined by min(<LINESIZE>, <LONGCHUNKSIZE>)
For example, if a table CLOB column has value length 10;
$ sqlplus scott/tiger@orcl SQL*Plus: Release 12.1.0.2.0 Production on … Copyright (c) 1982, 2014, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> select length(<F>) len, <F> from <T>; LEN <F> ---------- -------------------------------------------------------------------------------- 10 1234567890 SQL> --SHOW ONLY 8 BYTES FOR CLOB FIELD <F> SQL> set long 8 SQL> select <F> from <T>; <F> -------- 12345678 SQL> -- HERE THE FIRST 8 CHARS ARE SHOWN, THE LAST 2 CHARS ARE DISCARDED. SQL> set longchunksize 4 SQL> set linesize 3 SQL> -- min(3, 4) == 3 will take effect. SQL> select <F> from <T>; <F> --- 123 456 78 SQL> -- SWITCH <LONGCHUNKSIZE> AND <LINESIZE> SQL> set longchunksize 3 SQL> set linesize 4 SQL> select <F> from <T>; <V> --- 123 456 78
Open issue:
Since for parameter <longchunksize> and <linesize>, the smaller value will take effect, and the maximum value of <linesize> is 32767, so if a CLOB field length is greater than 32767, there is still no solution (not programming language) to print it in a single line.
Anyway, we can use a programming language to query CLOB to avoid this issue, for example JDBC, ODBC, etc.