Convert an NClob to Character in Oracle

Shaunsmith
Shaunsmith used Ask the Experts™
on
My requirement is to be able to do a distinct on a Table that has a Nclob

select distinct comment from finance_comments ;

Now since comment is a Nclob the DB does not allow me to use a distinct .

I was hoping to use "DBMS_LOB.SUBSTR" to convert it to chars .


SELECT distinct DBMS_LOB.SUBSTR(comments,4000,1)
FROM finance_comments

when I try to do this I get a 16:01:02  [SELECT - 0 row(s), 0.000 secs]  [Error Code: 6502, SQL State: 65000]  ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 1


Is this the right approch to this or is there a better way to be able to get distinct rows from
a table that has NClobs .
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Distinguished Expert 2018
Commented:
NCLOBs are multi-byte.  The MAX size for most of them is 2000.

Try:
SELECT distinct DBMS_LOB.SUBSTR(comments,2000,1)
FROM finance_comments


Are you storing multi-byte data in the NCLOB?

@nito8300,

That is for a CLOB not an NCLOB.  Was that a Google try or do you know Oracle CLOBs?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial