2.4 HAS_USER_ROLE Function

This function returns TRUE if the user is assigned to the specified role.

Syntax

APEX_ACL.HAS_USER_ROLE (
    p_application_id IN NUMBER   DEFAULT apex_application.g_flow_id,
    p_user_name      IN VARCHAR2 DEFAULT apex_application.g_user,
    p_role_static_id IN VARCHAR2 )
    RETURN BOOLEAN;

Parameters

Parameter Description
p_application_id The application ID for which you want to check if a user is assigned to the specific role. Defaults to the current application.
p_user_name The case insensitive name of the application user to check. It defaults to the current logged in user.
p_role_static_id The case insensitive name of the role static ID.

Example

The following example uses the HAS_USER_ROLE function to check if the user name 'SCOTT' is assigned to any role static IDs of 'ADMINISTRATOR' in application 255.

DECLARE
    l_is_admin boolean := false;
BEGIN
    l_is_admin := APEX_ACL.HAS_USER_ROLE (
                    p_application_id  => 255,
                    p_user_name       => 'SCOTT',
                    p_role_static_id  => 'ADMINISTRATOR' );

    IF not l_is_admin THEN
        raise_application_error(-20001, 'Scott is NOT an administrator' );
    END IF;
END;