DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: small function

  1. #1
    Join Date
    Nov 2002
    Location
    Mooresville, NC
    Posts
    349

    Arrow 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.
    http://www.perf-engg.com
    A performance engineering forum

  2. #2
    Join Date
    Nov 2002
    Location
    Mooresville, NC
    Posts
    349
    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;
    http://www.perf-engg.com
    A performance engineering forum

  3. #3
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,166
    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

  4. #4
    Join Date
    Nov 2002
    Location
    Mooresville, NC
    Posts
    349
    I was not aware of instr function, so wrote a custom function for checking the string.
    http://www.perf-engg.com
    A performance engineering forum

  5. #5
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Quote 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
  •  


Click Here to Expand Forum to Full Width