調整Oracle資料庫print_bill表欄位BillMKID的順序,並判斷表print_bill是否存在及欄位billMKID是否存在
來源:互聯網
上載者:User
declare
existFlag int;
existColFlag int;
begin
select count(1) into existFlag from user_tables where table_name = upper('Print_Bill');
select count(1) into existColFlag from user_tab_columns where table_name=upper('Print_Bill') and column_name=upper('BillMKID');
IF existFlag>0 THEN
IF existColFlag=0 THEN
execute immediate 'alter table PRINT_BILL add BillMKID varchar(4) default '' '' not null';
END IF;
execute immediate 'alter table PRINT_BILL rename to PRINT_BILLTEMP';
execute immediate '
CREATE table PRINT_BILL
(BillMKID varchar(4) not null, /*單據所屬模組ID*/
BillID varchar(50) primary key not null, /*單據邏輯名稱*/
BillName varchar(50) not null, /*單據顯示名稱*/
RecordsPath varchar(200) null ,
ParamCount int default 0 /*產生的XML中的參數個數*/
)';
execute immediate 'insert into Print_Bill(BillMKID,BillID,BillName,RecordsPath,ParamCount) select BillMKID,BillID,BillName,RecordsPath,ParamCount from Print_Billtemp';
execute immediate 'drop table Print_Billtemp';
ELSE
execute immediate '
CREATE table PRINT_BILL
(
BillMKID varchar(4) not null, /*單據所屬模組ID*/
BillID varchar(50) primary key not null, /*單據邏輯名稱*/
BillName varchar(50) not null, /*單據顯示名稱*/
RecordsPath varchar(200) null ,
ParamCount int default 0 /*產生的XML中的參數個數*/
)';
END IF;
END;