Tag Archive | "Oracle PL/SQL"

Tags:

Oracle User Privileges Scan


I had been looking for a really quick way to diagnose the roles and privileges of users that I created in a test database.

I snagged this code snippet from the web sometime ago (Sorry, I know longer have the reference if any credit is due at all).  I am posting it here mainly for my reference but perhaps it will help someone else as well.

select
lpad(' ', 2*level) || granted_role "User, his roles and privileges"
from
(
/* THE USERS */
select
null     grantee,
username granted_role
from
dba_users
where
username like upper('%&enter_username%')
/* THE ROLES TO ROLES RELATIONS */
union
select
grantee,
granted_role
from
dba_role_privs
/* THE ROLES TO PRIVILEGE RELATIONS */
union
select
grantee,
privilege
from
dba_sys_privs
)
start with grantee is null
connect by grantee = prior granted_role;

Posted in Business Intelligence, DatabaseComments (0)

Tags: ,

Row Count for all Tables


Recently a client wanted all the row counts from specific tables on a given scheme.  The list of tables to have their row counts documented was at about 50, which accounted for about 90% of the table objects in the scheme.  At first I was going to use the “Update Row Count” feature in OBI as this is where the project was grounded.  Then, I thought there had to be an easier approach.  Using the script below I was able to get the counts and simply eliminate the objects that where in the not needed 10%. The database we were using is Oracle so the PL/SQL won’t work for MS SQL Server. I will try to find the old SQL Server code I used to do this on a previous project and post it here as well at a later time.


set serveroutput on
declare
row_cnt number;
begin
for x in (select table_name
from user_tables
order by table_name) loop
execute immediate
'select count(*) from '
||x.table_name into row_cnt;
dbms_output.put_line(rpad(x.table_name,30)||lpad(to_char(row_cnt),7));
end loop;
end;
/

a variation of this is:

Set heading off
Set feedback off
Set pagesize 0
Set termout off
Set trimout on
Set trimspool on
Set recsep off
Set linesize 100
Column d noprint new_value date_
Column u noprint new_value user_
Spool tmp
Select 'Select '''||table_name||' : ''||count(*) from '||table_name||';',
to_char(sysdate, 'YYYYMMDDHH24MISS') d, user u
from user_tables
order by table_name
/
Spool off
Spool count_&user_._&date_
@tmp.LST
Spool off

References:

http://vivekagarwal.wordpress.com/2007/07/17/how-to-determine-row-count-for-all-tables-in-an-oracle-schema/
http://www.tek-tips.com/viewthread.cfm?qid=1393349&page=23

Posted in Business Intelligence, Database, OracleComments (2)