Home
Deprecated function DBMS_SESSION.IS_ROLE_ENABLED should not be used
Description
This rule flags the use of the deprecated PL/SQL function DBMS_SESSION.IS_ROLE_ENABLED in application code. The function was used to check if a specific role is enabled in the current session.
DBMS_SESSION.IS_ROLE_ENABLED has been deprecated and is no longer recommended for use starting with Oracle 19c. Oracle recommends using DBMS_SESSION.CURRENT_IS_ROLE_ENABLED or DBMS_SESSION.SESSION_IS_ROLE_ENABLED as the appropriate alternatives.
Oracle advises replacing the deprecated function to ensure better compatibility with future releases and more precise role checking mechanisms.
Key Benefits
- Future Compatibility: Ensures code remains compatible with newer Oracle versions by avoiding deprecated functions that may be removed in future releases.
- Accuracy: Using the newer functions
DBMS_SESSION.CURRENT_IS_ROLE_ENABLEDorDBMS_SESSION.SESSION_IS_ROLE_ENABLEDprovides more accurate and predictable results when checking role status within a session. - Efficiency: Encourages modern coding practices by adopting up-to-date and officially supported functions, improving long-term maintainability and minimizing technical debt.
- Maintainability: Reduces reliance on outdated and deprecated routines, promoting cleaner and more maintainable application code.
Non-compliant Code Example
DECLARE
role_enabled BOOLEAN;
BEGIN
role_enabled := DBMS_SESSION.IS_ROLE_ENABLED('DBA'); --Non compliant code
IF role_enabled THEN
DBMS_OUTPUT.PUT_LINE('Role DBA is enabled.');
ELSE
DBMS_OUTPUT.PUT_LINE('Role DBA is not enabled.');
END IF;
END;
/
Compliant Code Example
DECLARE
role_enabled BOOLEAN;
BEGIN
role_enabled := DBMS_SESSION.CURRENT_IS_ROLE_ENABLED('DBA'); --Compliant code
IF role_enabled THEN
DBMS_OUTPUT.PUT_LINE('Role DBA is enabled in the current session.');
ELSE
DBMS_OUTPUT.PUT_LINE('Role DBA is not enabled in the current session.');
END IF;
END;
/DECLARE
role_enabled BOOLEAN;
BEGIN
role_enabled := DBMS_SESSION.SESSION_IS_ROLE_ENABLED('DBA'); --Compliant code
IF role_enabled THEN
DBMS_OUTPUT.PUT_LINE('Role DBA is enabled in the current session.');
ELSE
DBMS_OUTPUT.PUT_LINE('Role DBA is not enabled in the current session.');
END IF;
END;
/
