create user and grant privileges in oracle code example
Example 1: oracle sql create user
CREATE USER MY_USER IDENTIFIED BY "MyPassword"
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK;
GRANT CONNECT TO MY_USER;
GRANT RESOURCE TO MY_USER;
GRANT MY_ROLE TO MY_USER;
ALTER USER MY_USER DEFAULT ROLE "RESOURCE","CONNECT","MY_ROLE";
ALTER USER MY_USER GRANT CONNECT THROUGH MY_OTHER_USER;
SELECT PRIVILEGE FROM DBA_SYS_PRIVS WHERE GRANTEE = MY_USER;
Example 2: oracle user privileges
SELECT GRANTEE,
PRIVILEGE AS PRIVILEGE_ROLE,
NULL AS OWNER,
NULL AS TABLE_NAME,
NULL AS COLUMN_NAME,
ADMIN_OPTION AS PRIVILEGE,
NULL AS GRANTABLE
FROM all_SYS_PRIVS
WHERE GRANTEE = 'MY_USER'
UNION ALL
SELECT R.GRANTEE, R.GRANTED_ROLE AS PRIVILEGE_ROLE, P.OWNER, P.TABLE_NAME,
P.COLUMN_NAME, PRIVILEGE, P.GRANTABLE
FROM all_ROLE_PRIVS R
LEFT JOIN ROLE_TAB_PRIVS P ON P.ROLE = R.GRANTED_ROLE
WHERE R.GRANTEE = 'MY_USER';