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;