Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PL/SQL: ORA-00942: table or view does not exist

onkar.nathNov 13 2009 — edited Nov 16 2009
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
This post has been answered by Twinkle on Nov 13 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 14 2009
Added on Nov 13 2009
5 comments
4,894 views