You will need to convert the CLOB to Varchar to do the sorting. Unfortunately, Varchar columns are limited to 4,000 characters in Oracle. If sorting by the first 4000 characters is reasonable, here's an example of SQLPlus using DBMS_LOB.SUBSTR:
SQL> create table mytable (testid int, sometext clob); Table created. SQL> insert into mytable values (1, rpad('z',4000,'z')); 1 row created. SQL> update mytable set sometext = sometext || sometext || sometext; 1 row updated. SQL> select length(sometext) from mytable; LENGTH(SOMETEXT) ---------------- 12000 SQL> select testid from mytable 2 order by dbms_lob.substr(sometext, 0, 4000); TESTID ---------- 1 SQL> drop table mytable; Table dropped.
Joshl
source share