1. View all users:
select * from dba_users;
select * from all_users;
select * from user_users;
2. View user or role system privileges (system privileges assigned directly to users or roles):
select * from dba_sys_privs;
select * from user_sys_privs; (view the privileges the current user has)
3. View the permissions contained in the role (only the roles owned by the logged in user)
sql>select * from role_sys_privs;
4. View user object permissions:
select * from dba_tab_privs;
select * from all_tab_privs;
select * from user_tab_privs;
5. View all roles:
select * from dba_roles;
6. View the roles owned by the user or role:
select * from dba_role_privs;
select * from user_role_privs;
7. Check which users have sysdba or sysoper system permissions (requires corresponding permissions when querying)
select * from V$PWFILE_USERS
8. To view the privileges of a user in SqlPlus
SQL>select * from dba_sys_privs where grantee='username';
where the username is the username must be capitalized.
For example:
SQL>select * from dba_sys_privs where grantee='TOM';
9. Oracle's method of deleting all tables of a specified user
select 'Drop table '||table_name||';' from all_tables
where owner='the user name to be deleted (note to be capitalized)';
10. Delete user
drop user user_name cascade;
such as: drop user SMCHANNEL CASCADE
11. Get all the tables under the current user: select table_name from user_tables;
12. Delete all table data under a user: select 'truncate table ' || table_name from user_tables;
13. Forbid foreign keys
The foreign key constraint names in the ORACLE database can be found in the table user_constraints. Where constraint_type='R' means it is a foreign key constraint.
The command to enable foreign key constraints is: alter table table_name enable constraint constraint_name
The command to disable foreign key constraints is: alter table table_name disable constraint constraint_name
Then use SQL to find out the constraint name of all foreign keys in the database:
select 'alter table '|| table_name||' enable constraint '||constraint_name||';' from user_constraints where constraint_type='R'
select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints where constraint_type= 'R'
14、ORACLE禁用/启用外键和触发器
--启用脚本
SET SERVEROUTPUT ON SIZE 1000000
BEGIN
for c in (select 'ALTER TABLE '||TABLE_NAME||' ENABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
for c in (select 'ALTER TABLE '||TNAME||' ENABLE ALL TRIGGERS ' AS v_sql from tab where tabtype='TABLE') loop
dbms_output.put_line(c.v_sql);
begin
execute immediate c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
end;
/
commit;
--禁用脚本
SET SERVEROUTPUT ON SIZE 1000000
BEGIN
for c in (select 'ALTER TABLE '||TABLE_NAME||' DISABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
for c in (select 'ALTER TABLE '||TNAME||' DISABLE ALL TRIGGERS ' AS v_sql from tab where tabtype='TABLE') loop
dbms_output.put_line(c.v_sql);
begin
execute immediate c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
end;
/
commit;