Processing of oracle field type conversion

Oracle's CLOB type data processing: http://donald-draper.iteye.com/admin/blogs/2335296
The table column in Oracle is changed from VARCHAR2 type to CLOB: http://blog.csdn.net/jssg_tzw/article/details /40829867
The data of one table is imported into another table in batches in mysql: http://blog.csdn.net/evan_endian/article/details/8652528
The table column in Oracle is changed from VARCHAR2 type to CLOB article
. Change the col field (VARCHAR2) in the test table to CLOB.
All the following tests are in the navicat environment: the table name is in quotation marks, but not in SQLPLUS, pay attention to the distinction
First the temp field will be added
alter table "test" add  "temp" CLOB;
UPDATE "test"  SET "temp" = "col";

When the table field order is irrelevant, delete the specified column,
alter table "test" drop column "col";

Then modify the temp field to col
alter table "test" RENAME COLUMN "temp" TO "col";

This solution is irrelevant to the order of the fields. When it is related to the order, and the primary key of the col field cannot be null, what should I do?


Suppose the original table is product, and product contains a field of fallTime (DATE), and the primary key is not empty. Now you need to change the fallTime field to
varchar type;
if you directly export the SQL script, modify the table structure, and data, the task is cumbersome. At the same time, in the SQL script, the records are often segmented. The insert
instance is as follows:
insert into product ....;
insert into product ....;
.....
This script runs quite slowly. Some people suggest that insert Commit once between Begin and commit,
instead of inserting a record, you need to commit once; some people suggest to modify it to the following form:
insert into product values ​​XXX, YYY, ......
these two methods are useless to me, You can try;


if you use temporary field conversion, because you want to modify the type of the field fallTime, and fallTime is the primary key, you cannot directly modify the fallTime field type
, this is because modify the fallTime field, the fallTime column value must be null, and fallTime is The primary key can not be empty, how is this good?

The following will introduce a solution:
first, export the product structure, including information such as primary key, index, table comment and field comment, modify the table structure, and modify the DATE type of fallTime to
varchar, create the test table according to the modified table structure information, note that the fallTime field
in the test table is varchar 1. Add a temporary conversion field to the test table:
alter table "test" add  "temp" varchar2(10);


2. Then import product data into test:
INSERT INTO "test" SELECT t.*,"TO_CHAR"(t.fallTime,'YYYY-MM-DD') FROM product t;


3. If fallTime can be null, execute the following statement:
UPDATE "test"  SET "fallTime" = NULL;
UPDATE "test"  SET "fallTime" = "temp";

If it cannot be empty, execute the following statement:
UPDATE "test"  SET "fallTime" = "temp";


4. Then delete product and delete the temp column of test:
alter table "test" drop column "temp";


5. Rename test to product.
Another method of 1 and 2:
first ensure that the table structure is the same, and insert data first
INSERT INTO "test" SELECT t.* FROM product t;

adding columns
alter table "test" add  "temp" varchar2(10);

update the column
UPDATE product SET "temp" = "TO_CHAR"(fallTime,'YYYY-MM-DD');

Summary:
If the column order is irrelevant, you can directly create a new temporary field, delete the previous field, and rename the temporary field; for the field order related, and the field cannot be empty, copy the table structure, and modify the type of the field that needs to be changed, Create a new temporary field, insert the field data that needs to be converted into the temporary field, then update and set the temporary field to the field that needs to be changed, delete the temporary field, and modify the table name.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326559374&siteId=291194637