Showing posts with label DML and DCL Query. Show all posts
Showing posts with label DML and DCL Query. Show all posts

Tuesday, August 16, 2016

Oracle User Create, Grant Privileges, Create DML and DCL statement from Select Query

# User Creation
create user AMPRD identified by az7bc2
default tablespace data_ts
quota 100m on test_ts
quota 500k on data_ts
temporary tablespace temp_ts
profile clerk;

# Grant Priviliges to User
grant create session to AMPRD;
grant connect,resource to AMPRD;
alter user AMPRD default tablespace sm_static;
alter user AMPRD quota unlimited on tb_name;
alter user AMPRD quota 100m on tb_name;
grant unlimited tablespace to AMPRD;

# Select Query to Identify useful Information about User
select username,default_tablespace,account_status from DBA_USERS where username ='AMPRD';
select grantee,granted_role from DBA_ROLE_PRIVS where grantee='AMPRD';
select role from DBA_ROLES where role like '%HPXR%';
select owner,object_type,object_name from DBA_OBJECTS where object_name like '%TST%';
select grantee,privilege from DBA_SYS_PRIVS where grantee = upper('FACT');
select owner,grantee,table_name,grantor,privilege from DBA_TAB_PRIVS where grantee='AMPRD';


# Create Drop DML Statements with select query from dual
select 'drop '||object_type ||' '||owner||'.'||object_name||' CASCADE CONSTRAINTS;' from DBA_OBJECTS where owner='AMPRD' and object_type='TABLE';
select 'drop '||object_type ||' '||owner||'.'||object_name||';' from DBA_OBJECTS where owner='AMPRD' and object_type !='TABLE';

# Create Grant DCL Statements to Replicate user with existing user Privileges

select 'grant '||privilege||' to AMPRD;' from DBA_SYS_PRIVS where grantee = upper('FACT');
select 'grant '||privilege||' on '||owner||'.'||table_name||' to AMPRD;' from DBA_TAB_PRIVS where grantee = upper('FACT');