Oracle—查询所有用户信息

来源:互联网 发布:乐乎硬盘 编辑:程序博客网 时间:2024/06/05 17:58
如何查询Oracle中所有用户信息
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
1.查看所有用户:
 
select* fromdba_users;  
 
select* fromall_users;  
 
select* fromuser_users;
 
2.查看用户或角色系统权限(直接赋值给用户或角色的系统权限):
 
select* fromdba_sys_privs;  
 
select* fromuser_sys_privs; (查看当前用户所拥有的权限)
 
3.查看角色(只能查看登陆用户拥有的角色)所包含的权限
 
sql>select* fromrole_sys_privs;
 
4.查看用户对象权限:
 
select* fromdba_tab_privs;  
 
select* fromall_tab_privs;  
 
select* fromuser_tab_privs;
 
5.查看所有角色:select* fromdba_roles;
 
6.查看用户或角色所拥有的角色:
 
select* fromdba_role_privs;  
 
select* fromuser_role_privs;
 
7.查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)
 
select* fromV$PWFILE_USERS
 
8.SqlPlus中查看一个用户所拥有权限
 
SQL>select* fromdba_sys_privs wheregrantee='username'; 其中的username即用户名要大写才行。
 
比如: SQL>select* fromdba_sys_privs wheregrantee='TOM';
 
9、Oracle删除指定用户所有表的方法
 
select'Drop table '||table_name||';'from all_tables whereowner='要删除的用户名(注意要大写)';
 
10、删除用户
 
dropuser user_name cascade; 如:dropuser SMCHANNEL CASCADE
 
11、获取当前用户下所有的表:
 
selecttable_name fromuser_tables;
 
12、删除某用户下所有的表数据:
 
select'truncate table  ' || table_name fromuser_tables;
 
13、禁止外键 ORACLE数据库中的外键约束名都在表user_constraints中可以查到。
 
其中constraint_type='R'表示是外键约束。
 
启用外键约束的命令为:altertable table_name enable constraintconstraint_name
 
禁用外键约束的命令为:altertable table_name disable constraintconstraint_name
 
然后再用SQL查出数据库中所以外键的约束名:
 
select'alter table '||table_name||' enable constraint '||constraint_name||';'from user_constraints whereconstraint_type='R'
 
select'alter table '||table_name||' disable constraint '||constraint_name||';'from user_constraints whereconstraint_type='R'
 
14、ORACLE禁用/启用外键和触发器--启用脚本
 
SETSERVEROUTPUT ONSIZE 1000000
 
BEGIN
 
forc in(select'ALTER TABLE '||TABLE_NAME||' ENABLE CONSTRAINT '||constraint_name||' ' as v_sql fromuser_constraints
 
whereCONSTRAINT_TYPE='R') loop
 
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
 
begin
 
EXECUTEIMMEDIATE c.v_sql;
 
 exceptionwhenothers then
 
 dbms_output.put_line(sqlerrm);
 
 end;
 
endloop;
 
forc in(select'ALTER TABLE '||TNAME||' ENABLE ALL TRIGGERS ' AS v_sql fromtab wheretabtype='TABLE') loop
 
 dbms_output.put_line(c.v_sql);
 
 begin
 
 executeimmediate c.v_sql;
 
 exceptionwhenothers then
 
 dbms_output.put_line(sqlerrm);
 
 end;
 
endloop;
 
end;
 
/
 
commit;
 
--禁用脚本
 
SETSERVEROUTPUT ONSIZE 1000000
 
BEGIN
 
forc in(select'ALTER TABLE '||TABLE_NAME||' DISABLE CONSTRAINT '||constraint_name||' ' as v_sql fromuser_constraints
 
whereCONSTRAINT_TYPE='R') loop
 
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
 
begin
 
 EXECUTEIMMEDIATE c.v_sql;
 
 exceptionwhenothers then
 
 dbms_output.put_line(sqlerrm);
 
 end;
 
endloop;
 
forc in(select'ALTER TABLE '||TNAME||' DISABLE ALL TRIGGERS ' AS v_sql fromtab wheretabtype='TABLE') loop
 
 dbms_output.put_line(c.v_sql);
 
 begin
 
 executeimmediate c.v_sql;
 
exceptionwhenothers then
 
 dbms_output.put_line(sqlerrm);
 
 end;
 
endloop;
 
end;
 
/
 
commit;
原创粉丝点击