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.