About Boolean Function [message #199079] |
Fri, 20 October 2006 01:01  |
romi
Messages: 67 Registered: October 2006
|
Member |
|
|
Hello Friends,
I am making a function to check that a word is palindrom or not.If it is plaindrom that it returns 1 otherwise 0.but i want to return boolean value "true" or "false".
My function is:-
Create or replace function palindrom(name in varchar2)return number
is
n number;
v_name varchar2;
t_name varchar2;
begin
n:=length(name);
for i in 1..n loop
v_name:=substr(name,1,n)
t_name:=t_name||substr(name,n-i+1,1);
end loop;
if v_name<>t_name then
return 0;
else
return 1;
end if;
end;
So,what changes should i do to achieve "TRUE" or "FALSE" return values instead of 0 and 1.
|
|
|
Re: About Boolean Function [message #199085 is a reply to message #199079] |
Fri, 20 October 2006 01:30   |
sukhadukkham
Messages: 3 Registered: September 2006 Location: Switzerland
|
Junior Member |
|
|
just change your function to this:
CREATE OR REPLACE FUNCTION palindrom ( NAME IN VARCHAR2
)
RETURN BOOLEAN
IS
n NUMBER;
v_name VARCHAR2(100);
t_name VARCHAR2(100);
BEGIN
n:=LENGTH(NAME);
FOR
i IN 1..n
LOOP
v_name:=SUBSTR(NAME,1,n);
t_name:=t_name||SUBSTR(NAME,n-i+1,1);
END LOOP;
IF
v_name<>t_name
THEN
RETURN FALSE;
ELSE
RETURN TRUE;
END IF;
END;
[Updated on: Fri, 20 October 2006 01:31] by Moderator Report message to a moderator
|
|
|
|
Re: About Boolean Function [message #199087 is a reply to message #199086] |
Fri, 20 October 2006 01:39   |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
Quote: | IF
v_name<>t_name
THEN
RETURN FALSE;
ELSE
RETURN TRUE;
END IF;
|
As a tutor of mine once said: "this shows you don't understand booleans. The way this should be coded is : return v_name = t_name;"
... and I still agree with him.
[Updated on: Fri, 20 October 2006 01:41] Report message to a moderator
|
|
|
|
|
|