VARCHAR2 column type is limited to 4000 bytes (in tables) and in PL/SQL to 32000 bytes.
So you have to consider the real length of the data before doing this.
Main Topics
Browse All TopicsHi!
I want to convert a LONG data-type column to char/varchar when i provide a view for my view user. Any comments/suggestions are highly appreciated...
Thanks in Advance,
Regards,
Usman.
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.
Hi...
i found this useful hope it ll help u too...
First convert the long to a varchar2 ,
How do you move a LONG to varchar2?
It is not possible to change a long to a varchar useing the ALTER TABLE
command. You could create a new table with the varchar column, and
select the long into a PL/SQL variable, inserting that variable into
the varchar column in the new table.
Examples:
=========
(I) This example assumes the LONG column <=4000 characters:
--------------------------
create or replace procedure 12vc is
cursor c0 is
select rowid, long_column
from table_name
begin
for c1 in c0 loop
update table_name
set varchar_column = c1.long_column
where rowid = c1.rowid;
end loop;
end;
(II) Another example that also performs string manipulation on the long:
--------------------------
declare
cursor my_cursor is
select long_col
from my_table;
my_var varchar2(32767);
begin
open my_cursor;
loop
fetch my_cursor into my_var;
exit when my_cursor%notfound;
my_var := substr(my_var,1,4000);
insert into new_table values (my_var);
end loop;
close my_cursor;
end;
(III) A method that uses export and import:
--------------------------
a) export the table with the long column
b) drop the table with the long column
c) import with the indexfile option (this writes the create table
statements in the specified file)
d) edit the indexfile and change the column datatype from long
to varchar
e) run the file as a script to create the table with the same name
but the datatype being changed from long to varchar2
f) import the data with ignore=y
==========================
after that convert the varchar2 field to a number with the to_number function.
Just be sure that the varchar2 field has just number.
follow the link for more information,
http://www.experts-exchang
regards,
nishant vyas
Business Accounts
Answer for Membership
by: DrSQLPosted on 2005-06-02 at 08:59:21ID: 14131987
Usman,
What version of Oracle are you using?
Good luck!
DrSQL