zodiac sign program if any one ................. [message #247612] |
Tue, 26 June 2007 09:45 |
allthat
Messages: 5 Registered: June 2007 Location: pakistan
|
Junior Member |
|
|
Write a program that have no table
program output looks like
========================================================
Enter your date of birth: 30-10-1984
You are 23 years old and you are libra
========================================================
========================CODE============================
DECLARE
BIRTHDAY DATE:=TO_DATE(TO_DATE('&BIRTHDAY','DD-MON-RRRR'),'DD/MON/RRRR');
CURRENT_DATE DATE:=TO_DATE(SYSDATE);
RESULT VARCHAR2(100);
BEGIN
RESULT:=TRUNC((CURRENT_DATE-BIRTHDAY)/365);
IF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 0321 AND 0419 THEN
&D('YOU ARE ARIES'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 0420 AND 0520 THEN
&D('YOU ARE TAURUS'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 0521 AND 0620 THEN
&D('YOU ARE GEMINI'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 0621 AND 0722 THEN
&D('YOU ARE CANCER'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 0723 AND 0822 THEN
&D('YOU ARE LEO'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 0823 AND 0922 THEN
&D('YOU ARE VIRGO'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 0923 AND 1022 THEN
&D('YOU ARE LIBRA'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 1023 AND 1121 THEN
&D('YOU ARE SCORPIO'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 1122 AND 1221 THEN
&D('YOU ARE SAGITTARIUS'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 1222 AND 1231 THEN
&D('YOU ARE CAPRICORN'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 0101 AND 0119 THEN
&D('YOU ARE CAPRICORN'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 0120 AND 0218 THEN
&D('YOU ARE AQUARIUS'||' AND YOU ARE '||RESULT||' YEARS OLD');
ELSIF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 0219 AND 0320 THEN
&D('YOU ARE PISCES'||' AND YOU ARE '||RESULT||' YEARS OLD');
END IF;
END;
========================CODE============================
Hmmmm the program and output is there .............. my question is...... if condition look like this
-------------------------------------------------------------
IF TO_CHAR(BIRTHDAY,'MMDD') BETWEEN '21-MAR' AND '19-april' THEN
&D('YOU ARE ARIES'||' AND YOU ARE '||RESULT||' YEARS OLD');
END IF;
-------------------------------------------------------------
if this condition runs or not if its is not run what will be the condition if i checked the condition in '21-MAR' not pass the '0321'...
|
|
|
Re: zodiac sign program if any one ................. [message #247679 is a reply to message #247612] |
Tue, 26 June 2007 15:13 |
|
Michel Cadot
Messages: 68716 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Quote: | TO_DATE(TO_DATE(...
|
This is awful.
SYSDATE is already a date, this is an horror.
Quote: | TO_CHAR(BIRTHDAY,'MMDD') BETWEEN 0321 AND 0419
|
TO_CHAR returns string, 321 and 419 are numbers, you compare strings and numbers, this is scary.
This is not defined.
Well, one error per line. You get the highest score!
But the best one is:
Quote: | TO_CHAR(BIRTHDAY,'MMDD') BETWEEN '21-MAR' AND '19-april'
|
It is always FALSE. Guess why...
Regards
Michel
|
|
|
|
Re: zodiac sign program if any one ................. [message #247983 is a reply to message #247980] |
Wed, 27 June 2007 13:41 |
|
Michel Cadot
Messages: 68716 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
SQL> def BIRTHDAY='30-10-1984'
SQL> DECLARE
2 BIRTHDAY DATE:=TO_DATE(TO_DATE('&BIRTHDAY','DD-MON-RRRR'),'DD/MON/RRRR');
3 begin null; end;
4 /
begin null; end;
*
ERROR at line 3:
ORA-01843: not a valid month
ORA-06512: at line 2
SQL> alter session set nls_date_language=american;
Session altered.
SQL> def BIRTHDAY='30-OCT-1984'
SQL> DECLARE
2 BIRTHDAY DATE:=TO_DATE(TO_DATE('&BIRTHDAY','DD-MON-RRRR'),'DD/MON/RRRR');
3 begin null; end;
4 /
begin null; end;
*
ERROR at line 3:
ORA-01843: not a valid month
ORA-06512: at line 2
Nothing to do.
It is wrong, it is wrong.
TO_DATE returns a date. What can be TO_DATE of a date? How can a date be converted to a date? It is a date!
Regards
Michel
|
|
|