Oracleデータベースは、データが完全な場合にフィールドの精度を変更することを保証します.
7097 ワード
orderテーブルのtotalフィールドの精度を変更するとします。
alter table order modify (total NUMBER(24,4) NOT NULL);
declare
size Int;
Begin
size := 0;
Select Count(1) Into size From SqlUpgradeLog Where ID = ' id';
If size = 0 Then
--total tmp_total
execute immediate 'alter table order rename column total to tmp_total';
-- total ,
execute immediate 'alter table order add total NUMBER(24,4) default 0 NOT NULL';
-- total
execute immediate 'update order set total = tmp_total';
-- tmp_total
execute immediate 'alter table order drop column tmp_total';
Insert Into SqlUpgradeLog(id,time,desc) values(' id',sysdate,' ');
commit;
End If;
End;
declare
size Int;
Begin
size := 0;
Select Count(1) Into size From SqlUpgradeLog Where ID = ' id';
If size = 0 Then
--total tmp_total
execute immediate 'alter table order rename column total to tmp_total';
-- total ,
execute immediate 'alter table order add total NUMBER(24,4) NULL';
-- total
execute immediate 'update order set total = tmp_total';
-- total not null
execute immediate 'alter table order modify (total NUMBER(24,4) NOT NULL)';
-- tmp_total
execute immediate 'alter table order drop column tmp_total';
Insert Into SqlUpgradeLog(id,time,desc) values(' id',sysdate,' ');
commit;
End If;
End;