--------------------------------------------------------
--  DDL for Function FNC_AD_USERNAME
--------------------------------------------------------

  CREATE OR REPLACE EDITIONABLE FUNCTION "ENVX_OPER"."FNC_AD_USERNAME" (
    p_username IN VARCHAR2
) RETURN VARCHAR2 AS
    v_username VARCHAR2(2000);

BEGIN

    SELECT val usuario
      INTO v_username
      FROM TABLE ( apex_ldap.search(
                                   p_username => 'CN=LCU SICD LDAP,OU=Usuarios de Servicios,DC=lc,DC=gc,DC=local',
                                   p_pass => 'martesSICDsegura10',
                                   p_host => 'ldaplc.lc.gc.local',
                                   p_search_base => 'DC=lc,DC=gc,DC=local',
                                   p_search_filter => '&(objectClass=person)(cn='||p_username||')(memberOf=CN=LCGU_SICD_Users,OU=Grupos,DC=lc,DC=gc,DC=local)',
                                   p_attribute_names => 'sAMAccountName'
                   ) );

    RETURN v_username;
EXCEPTION
    WHEN OTHERS THEN
        v_username := NULL;
        RETURN v_username;
END;


/
