Home » SQL & PL/SQL » SQL & PL/SQL » Help with column datatype conversion
Help with column datatype conversion [message #1851] Tue, 04 June 2002 15:10 Go to next message
Orakin
Messages: 3
Registered: June 2002
Junior Member
Hello everyone. I want to change my column datatype from long to varchar2(4000) while conserving the data. Can anyone give me suggestions on how to do this?

Thanks.
Re: Help with column datatype conversion [message #1852 is a reply to message #1851] Tue, 04 June 2002 15:48 Go to previous message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
The easiest way to "copy" a LONG data into a VARCHAR2 column is via PL/SQL.  
For instance, the following anonymous PL/SQL block copies a LONG column from 
table LONGTABLE into a VARCHAR2 column from table VARCHARTABLE, with the 
assumption that LONGTABLE.LONGCOLUMN does not exceed 2000 bytes in length: 
  
declare 
  string varchar2(2000); 
  character char(1); 
begin 
  select longcolumn, pk into string, character from longtable; 
  insert into varchartable values (string, character); 
end; 

<B>OR  USE THE COPY COMMAND </B>

You already have data in a table with a long column, and you want to change 
that column from long to varchar2.   
 
If you try the copy command, you will get the error 'CPY0005: Source and 
destination column attributes don't match' if the destination tables's column 
is not the same as the source tables. 
 
First 'set COPYTYPECHECK off' and then you will be able to use the copy 
command. 
   
 
 
SQL> SET COPYTYPECHECK OFF 
SQL> SET LONG 2000 
SQL> copy from jack/jack@T:wrvms:v7test - 
> insert dummy USING - 
> select x,y from test; 
 
Array fetch/bind size is 15. (arraysize is 15) 
Will commit when done.  (copycommit is 0) 
Maximum long size is 80. (long is 80) 
 
1 rows selected from jack@T:wrvms:v7test. 
1 rows inserted into DUMMY. 
1 rows committed into DUMMY at DEFAULT HOST connection.XX

Previous Topic: PL/SQL Error
Next Topic: Sum of Time
Goto Forum:
  


Current Time: Wed Apr 24 21:18:46 CDT 2024