If Oracle Data is not deleted, change the field type.

Source: Internet
Author: User

-- Modify the info_cus_complex_tax sequence number type
Alter table info_cus_complex_tax add AA number;
-- Add/Modify columns
Alter table info_cus_complex_tax modify no null;
-- Disable Constraints
Alter table info_cus_complex_tax disable constraint pk_info_complex_tax1;
Update info_cus_complex_tax set AA = NO, NO = NULL;
Commit;
Alter table info_cus_complex_tax modify no number (4 );
Update info_cus_complex_tax set no = AA, AA = NULL;
Commit;
Alter table info_cus_complex_tax drop column AA;
Alter table info_cus_complex_tax modify no not null;
-- Enable constraints

Alter table info_cus_complex_tax enable constraint pk_info_complex_tax1;

Problem: When a constraint is disabled or deleted in the database, the corresponding index is not deleted. As a result, the unique constraint is still reported when no column value is assigned to column AA.

Normal condition: When the constraint is disabled/deleted, the corresponding index will be deleted. When the constraint is enabled/created, it will be re-created.

Possible causes:

When you create a constraint, Oracle automatically creates the corresponding index. The two are associated. When the constraint is disabled or deleted, the corresponding index is deleted, when you enable/create an index, the corresponding index will be created. However, if you create an index first and then create a constraint, even if the two names are consistent with the associated fields, they do not have a relationship. It looks the same as above, the above problem occurs.

Solution 1: Determine whether the index exists

Script:

Declare
V_count varchar2 (2 );
Begin
-- Modify the info_cus_complex_tax sequence number type
Execute immediate 'alter table info_cus_complex_tax add AA number ';
-- Add/Modify columns
Execute immediate 'alter table info_cus_complex_tax modify no null ';
-- Disable Constraints
Execute immediate 'alter table info_cus_complex_tax disable constraint pk_info_complex_tax1 ';

Select count (T. Status) into v_count from user_indexes t where T. index_name = 'pk _ info_complex_tax1 ';
If (v_count> 0) then
Execute immediate 'drop index pk_info_complex_tax1 ';
End if;

Execute immediate 'Update info_cus_complex_tax set AA = No, no = null ';
Execute immediate 'alter table info_cus_complex_tax modify no number (4 )';

Execute immediate 'Update info_cus_complex_tax set no = AA, AA = null ';
Commit;
Execute immediate 'alter table info_cus_complex_tax drop column ';
Execute immediate 'alter table info_cus_complex_tax modify no not null ';
-- Enable constraints
Execute immediate 'alter table info_cus_complex_tax enable constraint pk_info_complex_tax1 ';

End;

Solution 2: cascade Deletion
Alter table tvehicle drop constraint check_only cascade drop index;
Re-create Index

 

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.