Initial Question
How do you create or replace a role (that might or might not exist) in Oracle? For example, the following does not work:
CREATE OR REPLACE ROLE role_name;
GRANT SELECT ON SCM1_VIEW_OBJECT_VW TO role_name;
Any way to do this without PL/SQL?
Update #1
The following does not compile:
CREATE OR REPLACE FUNCTION create_role( role_name IN VARCHAR2 ) RETURN BOOLEAN IS
BEGIN
CREATE ROLE role_name;
EXCEPTION
WHEN OTHERS THEN
-- ORA-01921: The role name already exists, so ignore the error.
IF SQLCODE = -01921 THEN
RETURN TRUE;
ELSE
RAISE;
END IF;
RETURN FALSE;
END create_role;
Error: PLS-00103: Encountered the symbol "CREATE" ... Line: 3 Text: CREATE ROLE role_name;