| |
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.
|
| July 07, 2009 14:02:26 |
#9 |
| javedans |
Member Since: January 2009 Total Comments: 8 |
RE: Catch The Error |
TO_CHAR(sysdate,'Day') is always return day name with some blank space, So its better to use TRIM function to exact match. Like TRIM(TO_CHAR(sysdate,'Day')) Or You can match initial 3 character in the by using substr function. |
| |
Back To Question | |