what is wrong with this code? [message #202261] |
Wed, 08 November 2006 21:50 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
qewani
Messages: 51 Registered: December 2005 Location: uaq
|
Member |
|
|
here is my code
function COMPARISON (in1 number, in2 number) is
if in1 = in2 then
return(1);
else
return(0);
end if;
end;
if i compile it it give me error saying that encountered the symbol "IF" when excepting one of the following:
Fatal syntax error, unable to recover.
Please help!
|
|
|
|
|
Re: what is wrong with this code? [message #202321 is a reply to message #202269] |
Thu, 09 November 2006 02:11 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](/forum/images/custom_avatars/72104.gif) |
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
'Declare' return value doesn't, actually, mean that the value itself has to be declared in the DECLARE section. It means that FUNCTION has to have, oh well, declared return value datatype. Also, your function doesn't have the BEGIN keyword. Therefore, it might look like this:CREATE OR REPLACE FUNCTION comparison (in1 NUMBER, in2 NUMBER)
RETURN NUMBER
IS
BEGIN
IF in1 = in2
THEN
RETURN (1);
END IF;
RETURN (0);
END;
However, you might also consider returning a BOOLEAN instead of a NUMBER:CREATE OR REPLACE FUNCTION Cmp (in1 NUMBER, in2 NUMBER)
RETURN BOOLEAN
IS
BEGIN
RETURN in1 = in2;
END;
Such a function is more meaningful, because your current function looks like this (for COMPARISON (2, 3)):
Q: Numbers 2 and 3 are equal
A: 0
If it was a Boolean, it would look like this:
Q: Numbers 2 and 3 are equal
A: FALSE
|
|
|
|
|
|
|
|