How to display CLOB column

19 篇文章 0 订阅

This article will give samples how database client display CLOB column for DB2 and Oracle


DB2 client

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 client (sqlplus)

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值