Displaying CLOB Column with 4000+ characters

▼魔方 西西 提交于 2019-12-04 22:42:17

问题


I have this CLOB column and I need to display it using a select statement.

I used DBMS_LOB.SUBSTR to convert it to varchar2:

select DBMS_LOB.SUBSTR(T1.CLOB_COL,4000,1) CLOB_COL from T1

My problem is some of my CLOBS contains more than 4000 characters. How can I display it...any idea/suggestion?

thanks a lot..


回答1:


I guess you could display the chunks as separate rows ?

SELECT ROWNUM as chunk_no,ID, SUBSTR (t1.clob_col, (ROWNUM-1)*4000, 4000) AS chunk
FROM t1
CONNECT BY (ROWNUM-1)*4000 <= LENGTH(t1.clob_col)

or if there is a constraint on the maximum size a clob could be in your system you could hard code the number of text columns returned

SELECT SUBSTR (t1.clob_col, 1, 4000) AS pt1,
       CASE WHEN LENGTH (t1.clob_col) > 4000  THEN SUBSTR (t1.clob_col, 4001, 4000) END AS pt2,
       CASE WHEN LENGTH (t1.clob_col) > 8000  THEN SUBSTR (t1.clob_col, 8001, 4000) END AS pt3,
       CASE WHEN LENGTH (t1.clob_col) > 12000 THEN SUBSTR (t1.clob_col, 1201, 4000) END AS pt4
FROM t1



回答2:


VARCHAR2 can only be 4000 bytes long when accessed with SQL. If you want to work with a CLOB larger than 4000 bytes, you can't convert it to VARCHAR2, you have to work it as a CLOB.

What tool do you use?

Most tools/languages can work with CLOB natively. Just select the column:

select T1.CLOB_COL from T1


来源:https://stackoverflow.com/questions/7357999/displaying-clob-column-with-4000-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!