Q

Sorting a clob column

I'm trying to sort a column type asc as well as desc. I'm able to sort the clob column desc but not able to sort it asc. Can you please help me out?

I'm trying to sort a column type asc as well as desc. I'm able to sort the clob column desc but not able to sort

it asc. Can you please help me out? Please find below the sample query that I used.

select * from TAbleA A where A.col1='XXX'
order by dbms_lob.substr(clobCol, 1, dbms_lob.getlength(clobCol)) desc

Here clobcol is the clob column with which I wanted to sort.

In 9i release 2, the parameters in dbms_lob.substr is ordered differently then in a substr function. In substr the parameter order is: substr (string, position, length). In dbms_lob.substr the parameter order is: dbms_lob.substr (lob_locator, length, position). Therefore, your SQL will sort correctly if your function looks like this:

dbms_lob.substr(clobCol, dbms_lob.getlength(clobCol), 1) asc
This was first published in December 2006

Dig deeper on Using Oracle PL-SQL

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close