oracle--determine if an object exists (not completed)

Source: Internet
Author: User

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)

  1. Declare
  2. V_exists number;
  3. Begin
  4. --1, Task type TASK_TYPE_CD build Table ...
  5. Select COUNT (*) into v_exists from user_tables where table_name = ' EDW_T99_TASK_TYPE_CD ';
  6. if v_exists > 0 Then
  7. Execute immediate ' drop table edw_t99_task_type_cd ';
  8. End if;
  9. Execute Immediate '
  10. CREATE TABLE Edw_t99_task_type_cd
  11. (
  12. CODE_CD VARCHAR2 () PRIMARY KEY,
  13. Code_desc VARCHAR2 (100)
  14. )‘;
  15. Execute immediate ' comment on table edw_t99_task_type_cd is 'task type ';
  16. Execute immediate ' comment on column edw_t99_task_type_cd.  CODE_CD is ' 'code ';
  17. Execute immediate ' comment on column edw_t99_task_type_cd.  Code_desc is ' 'code description ';
  18. --2, buy Product code BUY_TYPE_CD build Table ...
  19. Select COUNT (*) into v_exists from user_tables where table_name = ' EDW_T99_BUY_TYPE_CD ';
  20. if v_exists > 0 Then
  21. Execute immediate ' drop table edw_t99_buy_type_cd ';
  22. End if;
  23. Execute Immediate '
  24. CREATE TABLE Edw_t99_buy_type_cd
  25. (
  26. CODE_CD VARCHAR2 () PRIMARY KEY,
  27. Code_desc VARCHAR2 (100)
  28. )‘;
  29. Execute immediate ' comment on table edw_t99_buy_type_cd is 'buy product code ';
  30. Execute immediate ' comment on column edw_t99_buy_type_cd.  CODE_CD is ' 'code ';
  31. Execute immediate ' comment on column edw_t99_buy_type_cd.  Code_desc is ' 'code description ';
  32. End
  33. /

oracle--determine if an object exists (not completed)

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.