Check whether the data table exists during Oracle

Source: Internet
Author: User

Check whether the data table exists during Oracle

During the process, especially for daily tasks, check that the queried data table does not exist. If the data table does not exist, wait for a while. The following code implements this function, if the table does not exist, an exception is thrown and the Exception Processing code is handed over to ensure data integrity.

Usage: the user name p_CheckTable ('username. tablename') does not exist.

Create or replace procedure p_CheckTable (p_TableName in varchar2)
V_count number;
V_TableName varchar2 (200 );
V_table varchar2 (200 );
V_owner varchar2 (100 );
Begin
V_TableName: = upper (p_TableName );
V_count: = instr (v_TableName, '.', 1, 1 );
-- Get owner
V_owner: = substr (v_TableName, 1, v_count-1 );
-- Dbms_output.put_line (v_owner );

-- Get table name
V_table: = substr (v_TableName, v_count + 1, length (v_TableName)-v_count );
-- Dbms_output.put_line (v_table );
 
-- If not use other user table, the owner string is null, then check all tables
If v_owner is null then
Select count (*) into v_count from all_tables a where a. TABLE_NAME = v_table;
Else
Select count (*) into v_count from all_tables a where a. TABLE_NAME = v_table and owner = v_owner;
End if;
If v_count = 0 then
Raise_application_error (-20010, p_TableName | 'is not exist, Please wait ..');
End if;
 
End p_CheckTable;

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.