Skip to content
Keep Learning Keep Living
Keep Learning Keep Living

How to convert a LONG column to CLOB directly in a query

mustafakalayci, 2020-04-06

Hi,

This is a big problem since LONG is a very painful data type. You cannot search in it, use it in CTAS (create table as), pass it to a plsql object as parameter etc. Oracle strongly suggest not to use a LONG column anymore but unfortunately there are many LONG columns in data dictionary views like DBA_TRIGGERS, DBA_TAB_COLS, DBA_MVIEWS, DBA_VIEWS, DBA_TAB_PARTITIONS… I struggled with DBA_TAB_PARTITIONS a lot for example. HIGH_VALUE column is a LONG column and some of my codes to maintain partition operations need that data to identify the necessary partitions. I did so many works to get that data and today, finally I have found a way to convert LONG data to CLOB directly in a query!

I love Oracle community (community.oracle.com). so many Gurus are answering to so many questions and I just learn a lot just by reading. I just saw a thread based on a different topic but a valuable member of community Odie_63 provides a brilliant answer: https://community.oracle.com/message/15591644#15591644

SYS_DBUriGen function is allow you to convert long to clob directly:

Oracle PL/SQL
1
2
3
Select Owner, Trigger_Name,
       Sys_Dburigen(Owner, Trigger_Name, Trigger_Body, 'text()').Getclob() As Trigger_Body
From All_Triggers Where Rownum < 10;

Trigger_Body is a LONG column. first parameters in the function (Owner, trigger_name) are required for uniqueness of the row and they must be columns in the table. you can find information about Sys_DbUriGen at the documentation: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/SYS_DBURIGEN.html#GUID-ABA33BEB-F7B7-477B-9FF2-028D62768797

Of course performance is not much good but LONG data type is responsible of this. I hope Oracle will remove all LONG columns as soon as possible. even there is an idea thread for this at the community: https://community.oracle.com/ideas/3319

Thanks to community and Odie_63.

12c 18c 19c Development Useful Scripts CLOBLONGlong to cloblong2clobquery

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • 26ai Alert Log Size
  • What Should Change After Base DB System Clone
  • Using MFA While Logging into the Oracle Database
  • 2 of Most Practical New Features on 23.9
  • Milliseconds are lost after date to tz conversion on 19c

Recent Comments

  1. Mustafa on How to call HTTPS Url Without SSL Wallet in 19c
  2. Donatas on How to call HTTPS Url Without SSL Wallet in 19c
  3. Mustafa on 3 Ways to Migrate a Non-CDB Database to a PDB
  4. ulises lazarini on 3 Ways to Migrate a Non-CDB Database to a PDB
  5. Mustafa on How to call HTTPS Url Without SSL Wallet in 19c

Archives

  • November 2025
  • August 2025
  • July 2025
  • June 2025
  • April 2025
  • November 2024
  • July 2024
  • April 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • October 2021
  • September 2021
  • August 2021
  • April 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • July 2019
  • June 2019
  • May 2019
  • March 2019
  • February 2019
  • June 2018

Categories

  • 11g
  • 12c
  • 18c
  • 19c
  • 21c
  • 23ai
  • 26ai
  • Administration
  • Cloud
  • Compression
  • Development
  • Materialized View
  • Multi-tenant
  • Performance
  • Security
  • SQL / PLSQL
  • Uncategorized
  • Undocumented
  • Useful Scripts
©2025 Keep Learning Keep Living | WordPress Theme by SuperbThemes