Declare
V_rowcount integer;
V_rowcount1 integer;
V_rowcount2 integer;
Begin
Select COUNT (*) into V_rowcount from dual where exists (
SELECT * from col
where tname = Upper (' Bailcalcinfo ')
and CNAME = upper (' operator_no '));
If V_rowcount = 0 Then
Execute immediate ' ALTER TABLE Bailcalcinfo Add (operator_no varchar2 () default "" Not NULL) ';
End If;
Select COUNT (*) into v_rowcount1 from user_indexes where index_name = ' idx_bailcalcinfo ';
If v_rowcount1 > 0 Then
Select COUNT (*) into V_rowcount2 from dual
where exists (select 1 from user_ind_columns where index_name = ' idx_bailcalcinfo ' and column_name = ' futu_exch_type ' and C Olumn_position = 1)
and exists (select 1 from user_ind_columns where index_name = ' idx_bailcalcinfo ' and column_name = ' contract_code ' and Colu Mn_position = 2)
and exists (select 1 from user_ind_columns where index_name = ' idx_bailcalcinfo ' and column_name = ' entrust_bs ' and column_ Position = 3)
and exists (select 1 from user_ind_columns where index_name = ' idx_bailcalcinfo ' and column_name = ' hedge_type ' and column_ Position = 4)
and exists (select 1 from user_ind_columns where index_name = ' idx_bailcalcinfo ' and column_name = ' operator_no ' and column _position = 5);
--exists but is not correct, delete index
If V_rowcount2 = 0 Then
Execute immediate ' drop index hs_futures. Idx_bailcalcinfo ';
End If;
End If;
--the index is rebuilt if there is no OR exists but is not correct
If v_rowcount1 = 0 or V_rowcount2 = 0 Then
Execute immediate ' CREATE INDEX hs_futures. Idx_bailcalcinfo on Hs_futures.bailcalcinfo (futu_exch_type,contract_code,entrust_bs,hedge_type,operator_no) Tablespace Hs_futures_idx ';
End If;
End
/
Oracle Modify table structure and table index Plsql script notation