-
small function
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.
-
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;
-
I thought you wanted it to be a function? What about using INSTR and naming it something that tells you what it does?
Code:
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
-
I was not aware of instr function, so wrote a custom function for checking the string.
-
Originally Posted by malay_biswal
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....
Jurij Modic
ASCII a stupid question, get a stupid ANSI
24 hours in a day .... 24 beer in a case .... coincidence?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|