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

1023098Jul 6 2013 — edited Jul 10 2013

Hello guys,

First I want to say sorry for any mistake in English, is that I do not speak English very well, I'm Brazilian.

So let's get to my problem:

I have always worked with T-SQL in SQL Server, and now I'm having the need to work with PL / SQL in Oracle, so I'm trying to make a simple script that tests a table exists and, if not, the script should create the table and, if so, it just assigns the value of a field in a variable and display the value of it. Well, the fact is that when I run through the PL / SQL Developer, an error occurs stating that the table does not exist, however, with already informed above, the script should create the table if it does not exist, and that is exactly what I am not understand because in my opinion there is no problem in the script syntax or semantics and yet Oracle is criticizing.

Below is the script with dummy table:

Declare

i number;

v_date date;

v_name VARCHAR2(40);

BEGIN

SELECT count(*) INTO i FROM USER_OBJECTS WHERE OBJECT_TYPE='TABLE' AND OBJECT_NAME LIKE '%TEST%';

IF I < 1 THEN

DBMS_OUTPUT.PUT_LINE('Entered the IF');

EXECUTE IMMEDIATE 'CREATE TABLE DBO.TEST (NAME VARCHAR2(40))';

ELSE

DBMS_OUTPUT.PUT_LINE('Entered the else');

SELECT name INTO v_name from DBO.TESTE;

END IF;

END;

This post has been answered by Ishan on Jul 7 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 7 2013
Added on Jul 6 2013
26 comments
8,304 views