DBMS_LOB.SUBSTR() throwing “character string buffer too small” error

匿名 (未验证) 提交于 2019-12-03 01:20:02

问题:

Does oracle have a method to get substring based on number of bytes from a CLOB field?

select DBMS_LOB.SUBSTR(a.COMMENTS, 3998, 1) FROM FOO; 

I am getting error:

"ORA-06502: PL/SQL: numeric or value error: character string buffer too small"

. The problem was in special characters. Each new special character takes 8 bytes so when I reduce the string limit to 3992 then it works.

DBMS_LOB.SUBSTR(a.COMMENTS, 3992, 1) works. 

For testing purpose I put many special characters and again it throws same error.

Does oracle have any method which finds substring based on number of bytes than number of characters?

Actually, we are fetching data from a table and need to display on UI with a limitation of 4000 characters. So, we want to fetch first 4000 characters only. As, a character size is 1 byte, we can accomodate 4000 bytes. So, if we use DBMS_LOB.CONVERTTOBLOB, we may not be able to display properly the characters string fetched. Can we convert it back it charater string somehow?

回答1:

I used the old SUBSTR function successfully, which works for the clob type as well. In this case, it's SUBSTR(a.COMMENTS, 1, 3992)



回答2:

try this method::

Use Oracle function LENGTHB() to get this result. there is a way around convert CLOB to BLOB by using DBMS_LOB.CONVERTTOBLOB and use DBMS_LOB.GET_LENGTH(). this is will return no of bytes.

You can use this thread for complete answer :: https://forums.oracle.com/forums/thread.jspa?threadID=2133623



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