Joey,
First, because LONG columns represent such a pragmatic nightmare, avoid their use unless you have no alternative. (Fellow Tek-Tipster, Carp, and I have been collaborating on your issue this morning and resolve that we shall NEVER use LONG RAWs. We have found, for example, that we cannot use Oracle LONG-RAW-handling utilities from SQL directly; If we wish to use SQL for LONG-RAW access, we must contrive a PL/SQL user-defined function.
Second, Oracle supports LONG RAW mainly for backward compatibility to earlier versions (such as Oracle7). Conventional wisdom suggests your using BLOB or CLOB instead of LONG RAW, and again, only when some form of LONG is absolutely necessary.
Now to your case, If you are satified that there is no good reason for your column to remain "LONG RAW", then I would certainly change it to become VARCHAR2. I would, however, get the backing/blessing of your colleagues. To do this, I would "get my ducks in a row" by confirming the following:
1) What was the original reason was for the column to be LONG RAW? If the original designer is still accessible, contact her/him for the rationale.
2) Does the original rationale still exist? If so, can the rationale be "redesigned"?
3) What is the current maximum length of your LONG RAW column?
4) Is there any negative impact on software infrastructure to implement this change?
Once you gain the advocacy on this matter from your IT and applications colleagues, I would convert the column. The following sections in my post are: Section 1 -- Simulating your situation, Section 2 -- Creating a function to access LONG RAW data as VARCHAR2, Section 3: Converting your LONG RAW column to VARCHAR2. (This code is similar to the code I posted yesterday to resolve Bookouri's thread759-796135, but LONG RAW requires an even more intricate resolution than Bookouri's.)
Section 1 -- Simulating your situation:
Code:
create table longthang (x long raw, id number);
desc longthang
insert into longthang values (utl_raw.cast_to_raw('hello'), 1);
Section 2 -- Creating a function to access LONG RAW data as VARCHAR2:
Code:
create or replace function get_long (row in rowid) return varchar2 is
longhold varchar2(4000);
begin
for r in (select x from longthang where rowid = row) loop
longhold := utl_raw.cast_to_varchar2(r.x);
end loop;
return longhold;
end;
/
Section 3: Converting your LONG RAW column to VARCHAR2:
Code:
create table long2 (id number, x varchar2(4000));
insert into long2 select id, get_long(rowid) from longthang;
update longthang set x = null;
alter table longthang modify x varchar2(4000);
update longthang set x = (select x from long2 where id = longthang.id);
desc longthang
col x format a20
select * from longthang;
Again, many thanks to my distinguish colleague, Carp, whose collaboration was vital to producing this result.
Let us know how it worked for you (if you decide to convert).
![[santa] [santa] [santa]](/data/assets/smilies/santa.gif)
Mufasa
(aka Dave of Sandy, Utah, USA @ 18:31 (11Mar04) UTC (aka "GMT" and "Zulu"), 11:31 (11Mar04) Mountain Time)