First, the system table:
1. User_tables: Store information of all the tables under the user;
2. Dba_tables: Store All the information of the table under Administrator's permission;
3. All_tables: Stores information for all tables.
Second, determine whether the object exists
1. Judgment table
We can only determine if the current table exists by using SELECT COUNT (*), return 1 for existence, and 0 for non-existence, for example:
SELECT COUNT (*) from user_tables WHERE table_name = ' CODE_BMDM '; (this method can also be used in SQL)
It is important to note that table names (or other object names) must all be uppercase, except for special characters (there are special characters such as spaces between table names), otherwise the query is not available. The User_tables (all tables under the user) can also be replaced with dba_tables (all tables under Administrator privileges) or all_tables (all tables)
- Declare
- V_exists number;
- Begin
- --1, Task type TASK_TYPE_CD build Table ...
- Select COUNT (*) into v_exists from user_tables where table_name = ' EDW_T99_TASK_TYPE_CD ';
- if v_exists > 0 Then
- Execute immediate ' drop table edw_t99_task_type_cd ';
- End if;
- Execute Immediate '
- CREATE TABLE Edw_t99_task_type_cd
- (
- CODE_CD VARCHAR2 () PRIMARY KEY,
- Code_desc VARCHAR2 (100)
- )‘;
- Execute immediate ' comment on table edw_t99_task_type_cd is 'task type ';
- Execute immediate ' comment on column edw_t99_task_type_cd. CODE_CD is ' 'code ';
- Execute immediate ' comment on column edw_t99_task_type_cd. Code_desc is ' 'code description ';
- --2, buy Product code BUY_TYPE_CD build Table ...
- Select COUNT (*) into v_exists from user_tables where table_name = ' EDW_T99_BUY_TYPE_CD ';
- if v_exists > 0 Then
- Execute immediate ' drop table edw_t99_buy_type_cd ';
- End if;
- Execute Immediate '
- CREATE TABLE Edw_t99_buy_type_cd
- (
- CODE_CD VARCHAR2 () PRIMARY KEY,
- Code_desc VARCHAR2 (100)
- )‘;
- Execute immediate ' comment on table edw_t99_buy_type_cd is 'buy product code ';
- Execute immediate ' comment on column edw_t99_buy_type_cd. CODE_CD is ' 'code ';
- Execute immediate ' comment on column edw_t99_buy_type_cd. Code_desc is ' 'code description ';
- End
- /
oracle--determine if an object exists (not completed)