Steps for modifying the data type in an existing database:

Source: Internet
Author: User

Steps for modifying the data type in an existing database:

UNIT_PRICE: original database type: NUMBER)

AMOUNT: original database type: NUMBER)

If you modify the data directly, an error is reported because data already exists in the original field.

Alter table CLOUD_RELEASE.CONTRACT_PRODUCT_ITEM MODIFY (UNIT_PRICE NUMBER (18, 6 ));

Alter table CLOUD_RELEASE.CONTRACT_PRODUCT_ITEM MODIFY (amount number (18, 6 ));

-- Requirement: change the data type retention bits of the above two fields to 6 bits. The table already has data, and the twoFields also have values (the original data needs to be retained). The method is as follows:

-- 1: adds a field. The reserved number of digits in the data type is 6.
Alter table CLOUD_RELEASE.CONTRACT_PRODUCT_ITEM
ADD (UNIT_PRICES NUMBER (18, 6 ));

Alter table CLOUD_RELEASE.CONTRACT_PRODUCT_ITEM
ADD (amounts number (18, 6 ));
-- Field type Remarks
Comment on column CONTRACT_PRODUCT_ITEM.UNIT_PRICES IS 'unit price excluding tax (retain 6 bits )';
Comment on column CONTRACT_PRODUCT_ITEM.AMOUNTS IS 'amount excluding tax (retain 6 bits )';

-- 2: copy the data in the original field to the new field.

Note: the New and Old data types here are the same, so no conversion is required. If they are different, type conversion is required.
Update CONTRACT_PRODUCT_ITEM
Set UNIT_PRICES = UNIT_PRICE, AMOUNTS = AMOUNT

-- 3: delete the original field
Alter table CLOUD_RELEASE.CONTRACT_PRODUCT_ITEM drop column UNIT_PRICE;

Alter table CLOUD_RELEASE.CONTRACT_PRODUCT_ITEM drop column amount;

-- 4: Rename the new field to the original field.
Alter table CLOUD_RELEASE.CONTRACT_PRODUCT_ITEM
Rename column UNIT_PRICES TO UNIT_PRICE;

Alter table CLOUD_RELEASE.CONTRACT_PRODUCT_ITEM
Rename column amounts to amount;

You can modify the Data Type through the above steps, but pay attention to data type conversion in step 2.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.