Oracl basic operation SQL

Source: Internet
Author: User

Declare rows integer;
Begin

-- Delete a table
Execute immediate 'select count (*) from user_all_tables where upper (table_name) = upper (''bm _ ratiodata_temp '') 'into rows;
If rows> 0 then
Execute immediate 'drop table bm_ratiodata_temp ';
End if;

-- Add a column
Execute immediate 'select count (*) from all_tab_columns where table_name = ''sjdwzt ''and column_name = ''isvirtual ''' into rows;
If rows <1 then
Execute immediate 'alter table sjdwzt add isvirtual int null ';
End if;

-- Modify a table column
Execute immediate 'select count (*) from all_tab_columns where table_name = ''sjfagroup ''and column_name = ''leibie ''' into rows;
If rows <1 then
Execute immediate 'alter table sjfagroup alter column leibie varchar (30 )';
End if;

-- Delete a foreign key
Execute immediate 'select count (*) from user_constraints where table_name = ''test2' and constraint_name = ''for _ test''' into rows;
If rows> 0 then
Execute immediate 'alter table Test2 drop constraint for_test ';
End if;

-- Checklist Name:
Select count (*) from user_tables where table_name = table name (uppercase );

-- Check the field name:
Select count (*) from user_tab_columns where table_name = 'bm _ effect' and column_name = 'benchmarkid'


Select * From user_cons_columns; -- all columns

-- Query the primary key
Select * From user_constraints where constraint_type = 'p' and constraint_name = 'pk _ bm_condition roup 'and table_name = 'test'

-- Search for Indexes
Select * From dba_indexes where index_name = 'idx _ grouping roup'

-- Create an index
-- Create index idx_sjobjectcollection_objecttype on sjobjectcollection (objecttype)

-- Cascade table Deletion
-- Drop table bm_ratio_type cascade constraints;

End;

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.