Oracle Modify table structure and table index Plsql script notation

Source: Internet
Author: User

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

Related Article

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.