converting Oracle to postgres - Mailing list pgsql-general

From RobertD.Stewart@mail.state.ky.us
Subject converting Oracle to postgres
Date
Msg-id 098C0DC713F9D311B2FB00508B95327605971732@agency2.state.ky.us
Whole thread Raw
Responses Re: converting Oracle to postgres
List pgsql-general

Here is a copy of my function in oracle.

 

Create Or Replace FUNCTION SET_USERNAME

  ( eventtype IN varchar2,

    message IN varchar2)

  RETURN  varchar2 IS

username varchar2(30);

pos1  number(7);

pos2 number(7); 

BEGIN

    if eventtype = 'AUDIT_SUCCESS' then

      pos1 := instr(message, 'User Name:') + 10;

      pos2 := instr(message, 'Domain');

      return substr(message, pos1, pos2-pos1);  

    elsif eventtype = 'AUDIT_FAILURE' then

      pos1 := instr(message, 'User Name:') + 10;

      pos2 := instr(message, 'Domain:');

      if (pos1 = 0 or pos2 = 0) then

        pos1 := instr(message, 'Account Name:') + 13;

        pos2 := instr(message, 'Target Domain:');

      end if; 

 

      return substr(message, pos1, pos2-pos1);  

    end if;       

    return '' ;

EXCEPTION

   WHEN others THEN

       return '' ;

END;

 

 

How do I get it to work in postgres

Please help me with the SQL commands

 

Thanks

 

 

Robert Stewart

Division of Communications

Office of Infrastructure Services

Governors Office for Technology

Commonwealth of Kentucky

work: 502 564 4287

cell: 502 330 5991

pager 877 543 0473

 

 

pgsql-general by date:

Previous
From: Linh Luong
Date:
Subject: missing Pg.pm in Postgres v7.3.1
Next
From: Francisco J Reyes
Date:
Subject: Re: Dealing with complex queries