[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2008-10-07
7
Medium Priority
?
5,600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

656 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