Click to See Complete Forum and Search --> : small function
malay_biswal
11-10-2005, 11:02 AM
Hi,
I'm writing one pl/sql package. One of my function inside package is
getdata(servername).
My requierement now is not check if the servername has a 'CN' charaacter inside it. That means if servername is appcn01 then it should tell me yes it's the server and if something like appprn02 then no it's not.
Can anybody let me know how to write this.
Thanks in advance.
malay_biswal
11-10-2005, 11:17 AM
sorry for posting simple thing.
got the result.
DECLARE
i number;
n number;
str varchar2(40);
begin
str := 'appdsfsfncn';
n := length(str);
for i in 1..n loop
if (lower(substr(str,i,2))='cn') then
dbms_output.put_line('GOT IT...');
--else
--dbms_output.put_line('NOT RIGHT...');
end if;
end loop;
end;
gandolf989
11-10-2005, 03:07 PM
I thought you wanted it to be a function? What about using INSTR and naming it something that tells you what it does? :rolleyes:
CREATE OR REPLACE FUNCTION server_name_has_cn
( p_server_name IN VARCHAR2)
RETURN BOOLEAN
AS
v_char_location BINARY_INTEGER;
v_search_str CHAR(2) := 'CN';
BEGIN
IF INSTR(p_server_name, v_search_str) > 0
THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END server_name_has_cn;
instr function (http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions55a.htm#77600)
malay_biswal
11-10-2005, 04:34 PM
I was not aware of instr function, so wrote a custom function for checking the string.
jmodic
11-10-2005, 05:25 PM
I was not aware of instr function, so wrote a custom function for checking the string.
And you've managed to wrote one in the most inefficient way of them all.... :rolleyes: :D