GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Oracle  >  Basics

 Print  |  
Question:  Catch The Error

Answer: SQL>DECLARE
2 dayofweek VARCHAR2(200);
3 BEGIN
4 SELECT TO_CHAR(sysdate,'Day') INTO dayofweek FROM DUAL ;
5
6 IF dayofweek = 'Tuesday'
7 THEN
8 DBMS_OUTPUT.PUT_LINE('Aloha!!! Today Is Tuesday');
9 ELSE
10 DBMS_OUTPUT.PUT_LINE('Today is '||to_char(sysdate,'Day'));
11 END IF;
12 END;
13 /
Today is Tuesday

PL/SQL procedure successfully completed.
SQL>

What's wrong in the above anonymous block if anything at all.



December 12, 2008 15:10:36 #8
 sriatit   Member Since: December 2008    Total Comments: 2 

RE: Catch The Error
 
Actually there is no sytactical error in this code. It just that the if condition always evaluates to false 'coz the query returns the day of the week with trailing spaces(except for Wednesday) and thus will never be equal to 'Tuesday'. So, the output will be :

On Tuesday :

Today is Tuesday
On other days :
Today is Wednesday

The output 'Aloha!!! Today Is Tuesday' is never displayed.

     

 

Back To Question