Skip to Main Content

Column Long to Clob (PL/SQL function)

A PL/SQL function to return a long column value as a clob - see the code for package ted_p1026 below.
Based in part on the code from the link below, but modified to accept a table/column/where-clause instead of a query/bind-variable.
More background info & original code: https://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:665224430110.

Column Long to Clob (SQL)

Table NameColumn NameData TypeData DefaultData Default VcData Default Vc2
TED_YM_EPISODESIDNUMBER"TEDSTRUIK"."ISEQ$$_77839".nextval"TEDSTRUIK"."ISEQ$$_77839".nextval"TEDSTRUIK"."ISEQ$$_77839".nextval
TED_YM_QUOTESIDNUMBER"TEDSTRUIK"."ISEQ$$_96713".nextval"TEDSTRUIK"."ISEQ$$_96713".nextval"TEDSTRUIK"."ISEQ$$_96713".nextval

In SQL you may not always be able to create and use a PL/SQL function, so a pure SQL solution would be nice (and probably faster as well).
Such a solution is shown below, using sys_dburigen - see the view code for ted_p1026_v below.
I found that method at https://forums.oracle.com/ords/apexds/post/how-to-convert-long-to-any-character-string-varchar2-char-8263.

In database 26ai, a new column data_default_vc was introduced for the [user/all/dba]_tab_cols views, so in the view both that one and the sys_dburigen solution are used to show it actually works :-)
You can use the sys_dburigen solution by itself for other Long columns in other tables of course.

Note: I used a with-clause in the view for performance reasons, but also because I couldn't get it to work without one.
I expected this simpler query to work as well: However, that one gives an "ORA-19334: invalid column specification for the SYS_DBURIGEN function" error.
Somehow joining the table that is used in sys_dburigen triggers this error, but I can't explain that behavior...

Code

Package

Package
Name
Source

Package Body

Package Body
Name
Source

Region

Identification
Sequence
Title
Type
Source
Location
Query Type
Table Name
Where Clause
Order By Clause

View

View
Name
DDL