Wednesday 26 October 2016

ORA-00942: table or view does not exist

Some times you may trying to  drop table which is exist in database but unfortunately you would get weird error saying that "table/view doesn't exist" even though table exist in database.


Here,one thing you need to observe.i.e.Check whether table is stored with upper case or lower case or mixed by querying in User_tables.

SQL> SELECT * FROM USER_TABLES;


By default all objects(i.e. table,view,procedures etc ) will be stored with upper case unless you specify case sensitive.

If you had created table or any object with with case sensitive then you cant drop those tables or objects directly with normal command.


You need specify double quotes " " both sides of your object while drop table/object.


lets check one example:


Tuesday 25 October 2016

EXIT In Oracle

Exit: 

In Oracle,Exit statement most commonly used to terminate LOOP statements.

Syntax: 

EXIT (when CONDITION);

here when condition is optional.


Example 1:

Loop
v_sal := sal * comm;
exit when v_sal >10000;
End loop;


In this example ,loop would be terminated when v_sal becomes more than 10000.

 Example 2:


LOOP

v_sal := sal * comm;
  IF v_sal >10000 THEN
    EXIT;
  END IF;
END LOOP;

WHILE LOOP

While Loop:


In Oracle,we use while loop if we are not sure how many times we need to execute particular LOOP or that LOOP may not execute even once also.


Syntax:
WHILE (CONDITION)
LOOP
STATEMENTS;
END LOOP;


Here condition is to pass the LOOP,if condition is satisfied then it ill continue LOOP otherwise it will terminate LOOP.


Example:

while (v_sal < 10000)
loop
v_sal := sal * comm;
End loop;


here while loop will check condition first,here condition is v_sal should be less than 10000.So until v_sal becomes 1000 this loop will get executed but once it becomes 10000 then it ill terminate LOOP.