Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 E-mail Us
 Oracle Articles

 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 







How to select a LONG table column?

Oracle Tips by Burleson Consulting
May 18, 2008

Question:  I need to select a LONG RAW column from a table.  How do you select a LONG or LONG RAW table column in SQL?

Answer:  First, the LONG and LONG RAW datatypes are superseded by the new LOB datatypes (CLOB, BLOB and BFILE), and I would consider re-defining the table to have a LOB column instead of raw.

Also see Insert into long raw column Tips.

Here is a simple way to display a long raw using utl_raw.cast_to_varchar2:

set long 32767

create table test (c1 long raw);

--insert into test values (utl_raw.cast_to_raw('hello world'));

a varchar(255);
b long raw;
cursor c1 is select c1 from test;
open c1;
fetch c1 into b ;
exit when c1%notfound;
end loop;


In SQL*Plus, you can use the "set long" command:

set long 32767
select long_column from mytable;

Outside of SQL*Plus, you need to write a PL/SQL function to convert the LONG column into standard text.  David Hunt has this example of a function to convert a LONG to a char datatype:

REM **********************************************************
REM Author: David Hunt
REM Date Created: July 18, 2007
REM Purpose: Creates function that returns contents of
REM         PART_COMNT:COMNT_TXT. (a LONG field)
REM    Warning: if the contents of COMNT_TXT exceed 32767 chrs, then
REM            none of the data from that row's LONG RETURN;
REM                     an error message results.
REM **********************************************************
create or replace function Get_Comnt_txt
    (RowID_of_Long in rowid)
    return varchar2
    Long_to_Varchar        varchar(32767);
    select comnt_txt into Long_to_Varchar
        from part_comnt
        where rowid = rowid_of_long;
    return long_to_varchar;
    when others then
        return 'Error occurred on rowid: '||rowid_of_long;
end; /

select replace(get_Comnt_txt(rowid),chr(10),null)comnt_txt
from part_comnt;

This is short text in a LONG column.
This is row 2; a <carriage return> is here ->This is row 2; a <carriage return> is here ->This is row 2; a <carriage return> is here ->


Laurent Schneider notes such a function to search a LONG column within a table:

create table rv_test (a number, b long)
insert into rv_test values (1, 'asdfjasraghavkjasdfdsafqafl;kasdfnbdsamnbfdasraghavasdfl')
insert into rv_test values (2, 'asdfjasdf;lkjadsflkjdasf;lkjasdflkjdsafl;kasdfnbdsamnbfdasraghavasdflkjasdf')
insert into rv_test values (3, & #39;asdfjasdf;lasdfa192387sfdsflkjdasf;lkjasdfdsafq3lkjdsafl;kasdfnbdsamnbfdasra

-- ************************
create or replace type rv_test_type as object(a number, b clob);

create or replace type rv_test_table as table of rv_test_type;

create or replace function rv_test_search(x varchar2)
return rv_test_table pipelined is
  r rv_test_type;
  for f in (select * from rv_test) loop
    if (f.b like x) then
      r:= rv_test_type(f.a,f.b);
      pipe row(r);
    end if;
  end loop;

select a from table(rv_test_search('%raghav%'));





oracle dba poster

Oracle performance tuning software 
Oracle Linux poster


Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


Copyright ? 1996 -  2014

All rights reserved by Burleson

Oracle ? is the registered trademark of Oracle Corporation.