If it's less than 32,000 characters, you can stick it in a VARCHAR2 as well.
May be less with 'old' versions of Oracle (pre 8i)
Main Topics
Browse All TopicsI am trying to pull back data from an oracle database using PL/SQL however one of the columns is a long datatype! When I export the data that column just comes out as <LONG>, Is there anyway I can convert this column so that the true contents of the field are exported??
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Ben's suggestion looks good to me.
One other approach I used in the past for a one-time conversion was SQL*Plus and the "spool" command to put the primary key and the long_column (which for me was all ASCII data and less than 4,000 bytes long) into an ASCII file that I could then load back into a varchar2 column in a table via SQL*Loader or PL\SQL with utl_file.
It depends on what you wish to do with the LONG column.
The to_lob function can be used in very limited circumstances.
Here's what the fine manual says about to_lob:
TO_LOB converts LONG or LONG RAW values in the column long_column to LOB values. You can apply this function only to a LONG or LONG RAW column, and only in the SELECT list of a subquery in an INSERT statement.
Before using this function, you must create a LOB column to receive the converted LONG values. To convert LONGs, create a CLOB column. To convert LONG RAWs, create a BLOB column.
You can use the to_lob function to insert the LONG into a global temporary table, where you can then do a number of other operations that aren't allowed on longs.
Here's an example of converting LONG -> LOB
drop table gt;
drop table t1;
drop table t2;
create table t1 (
id number not null
, data long not null
)
/
create table t2 (
id number not null
, data clob not null
)
/
create global temporary table gt (
id number not null
, data clob not null
) on commit delete rows
/
insert into t1 values(1,'this is long test data');
insert into t1 values(2,'more long test data');
insert into t1 values(3,'really, not so long test data');
commit;
declare
v_sql varchar2(1000);
v_clob clob;
type r_clob_type is record (
id number
, src_clob clob
);
r_clob r_clob_type;
begin
for lrec in (select rowid from t1)
loop
v_sql := ' insert into gt (id,data) '
|| 'select id, to_lob(data) '
|| 'from t1 '
|| 'where rowid = ' || '''' || lrec.rowid || '''';
execute immediate v_sql;
insert into t2 (id, data)
select id,data
from gt;
commit;
end loop;
end;
/
select * from t2;
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
accept benpung's comment as an answer
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
patelgokul
EE Cleanup Volunteer
Business Accounts
Answer for Membership
by: benpungPosted on 2003-01-16 at 12:43:00ID: 7743734
i'm not sure about the export, but i know when i am using pl/sql procedures and i need to work with a long or long raw, i have to select them into a clob or blob variable. long and long raw are going away. lobs are the way of the future in oracle. they are better to work with b/c of the dbms_lob package and can hold more data. so, i guess my answer is to look into using a lob datatype somehow, maybe creating a staging table where the current long column is a clob, then loading that table with a pl/sql procudure using a clob variable and a cursor. that would be one way. if this won't work if you could be more specific with the question on exactly you are trying to do i will try to help.
ben