PL/SQL: ORA-00942: table or view does not exist
All,
I am running below anonymous block which is acting weired. Below blocks checks for the existence of a table. If it exists then it deletes records from the table else creates the table. But it is throwing below error:
Error
*********************************************************************************
delete from test;
*
ERROR at line 39:
ORA-06550: line 39, column 48:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 39, column 36:
PL/SQL: SQL Statement ignored
*********************************************************************************
Anonymous Block
*********************************************************************************
DECLARE
my_table_name tab.tname%type;
BEGIN
select tname
into my_table_name
from tab
where upper(tname) like 'test'
;
if my_table_name is null
then
dbms_output.put_line( 'Table NOT found!');
execute immediate ('create table tests select empno from test1 where 1 = 0');
else
dbms_output.put_line( 'Table found!');
delete from test;
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN
Null;
END;
/
*********************************************************************************
Please suggest.
TIA