Solved

Change column data type from VARCHAR2 to CLOB, retaining column order

Posted on 2008-10-07
7
5,591 Views
Last Modified: 2013-12-19
Hi!

Is there a way to change the column order from varchar2 to clob in a table and still retain the columns order?

I would prefer to do this without using a temporary table as constraints and large amount of data may cause that solution to be time consuming and cumbersome.

Also, could you please list the 5-10 most important drawbacks of using clob as opposed to varchar2?
0
Comment
Question by:pcpaasche
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 22658932
Yes
  1. Create new column
  2. transfer from old to new column
  3. delete old column
This also could be made with the table
  1. Create new table
  2. transfer data from old to new table
  3. drop old table
hth
I
0
 

Author Comment

by:pcpaasche
ID: 22659112
Hi!

thank's for your proposal.

However, I am looking for a solution where:
1. Column order in the table doesn't change
2. No need to transfer data from the original table to a new table

Any other suggestions?
0
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 22659310
Then you should use second proposal.
I doubt direct varchar2 to clob transformation is possible unless you have *only numbers* in that column.
I
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 18

Expert Comment

by:rbrooker
ID: 22665600
modifying a column to a clob is not possible, it results in a ORA-22858.  http://www.error-code.org.uk/view.asp?e=ORACLE-ORA-22858
you will need to either:
  • create a new table with the column of the right  type in the right place and copy the data, or
  • add a column on to the end of the existing table and copy the data from one column to the other
good luck.
0
 

Accepted Solution

by:
pcpaasche earned 0 total points
ID: 22666977
Or I can do like this:

1. Add a new temporary CLOB column at the end of the existing table
2. Copy data from the existing VARCHAR2-column to the new temporary CLOB-column: Update mytable set newClobColumn = existingVarchar2Column
3. Empty the existing VARCHAR2-column:  Update my table set VARCHAR2-column = NULL;
4. Change existing column from VARCHAR2 to LONG
5. Change existing column from LONG to CLOB  (cannot change directly from varchar2 to clob, must go via long)
6. Update existing column with values from temporary column: Update mytable set existingColumnNowClob = TemporaryColumnAtEndOf Table
7. Remove temporary column added to table in step 1

I just tested this solution and it works fine:-)

ALTER TABLE VARIABLELOGSTATEMENT ADD  VARIABLEVALUE_NEW CLOB;
Update VARIABLELOGSTATEMENT set VARIABLEVALUE_NEW = VARIABLEVALUE;
Update VARIABLELOGSTATEMENT set VARIABLEVALUE = null;
ALTER TABLE VARIABLELOGSTATEMENT modify VARIABLEVALUE long;
ALTER TABLE VARIABLELOGSTATEMENT modify VARIABLEVALUE clob;
Update VARIABLELOGSTATEMENT set VARIABLEVALUE = VARIABLEVALUE_NEW;
ALTER TABLE VARIABLELOGSTATEMENT drop column VARIABLEVALUE_NEW;

Open in new window

0
 
LVL 74

Expert Comment

by:sdstuber
ID: 22683053
use an external table, save your data to the external table, then drop and recreate your table with the clob column and then use the external table to load the data.
you'll take extra space on your server but not in your database.

drawback to using a clob?  they are more complicated structures so they are a slower to work with.
depending on your version you may or may not be able to do things with them.  You posted to 9, 10 and 11 zones.

in 10 and 11, you can use clobs like "super varchar2" almost invisibly until you try to access more than 4000 characters in sql, or 32K in pl/sql
then you must use dbms_lob.


in 9, you can do a lot of things invisibly but you'll notice limitations when you try to use them across db links especially.
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 22683062
note, exporting to an external table is a 10g and above option.  So, for 9i, you'll have to save the data some otherway. then reimport
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question