ORACLE删除当前用户下所有的表的方法
如果有删除用户的权限,则可以:
drop user user_name cascade;
加了cascade就可以把用户连带的数据全部删掉。
删除后再创建该用户。
--创建用户
create user 用户名 identified by 密码 default tablespace space_data(表空间名称) temporary tablespace space_temp(临时表空间名称);
--授权
grant connect,dba to 用户名;
--修改限额
ALTER USER "用户名" QUOTA UNLIMITED ON SPACE_DATA(表空间名称);
--查看当前登录用户所有用户对象
select uo.object_name,uo.object_type from user_objects uo where uo.object_type<>'LOB' order by uo.object_type desc
测试结果如下,可以看到表,序列,索引 3个类型的数据
1 EDU_APP TABLE2 EDU_GAME_PARAM TABLE3 EDU_GAME_CROSSATT TABLE4 EDU_GAME_JARTOURL TABLE5 EDU_GAME_LOGS TABLE6 EDU_GAME_LOGSATT TABLE7 EDU_GAME_OBJ TABLE8 EDU_GAME_OBJATT TABLE9 EDU_GAME_ORDERFORM TABLE10 EDU_GAME_PROP TABLE11 EDU_GAME_USER TABLE12 EDU_GAME_USERATT TABLE13 EDU_GAME_USERATTVALUE TABLE14 EDU_GAME_USERCROSSATTVALUE TABLE15 EDU_GAME_USERLOGS TABLE16 EDU_GAME_USERLOGSATTVALUE TABLE17 EDU_GAME_USEROBJATTVALUE TABLE18 EDU_GAME_USERPROP TABLE19 EDU_GAME_USERPROPLOGS TABLE20 EDU_GAME_USERROLE TABLE21 EDU_GAME_USERROLEATT TABLE22 EDU_GAME_USERROLEATTVALUE TABLE23 EDU_GAME_USERROLECROSSATTVALUE TABLE24 EDU_GAME_USERROLELOGS TABLE25 EDU_GAME_USERROLELOGSATTVALUE TABLE26 EDU_GAME_USERROLEOBJATTVALUE TABLE27 EDU_GAME_USERROLEPROP TABLE28 EDU_GAME_USERROLEPROPLOGS TABLE29 EDU_USERINFO TABLE30 EDU_GAME_CROSS TABLE31 SEQ_EDU_GAME_ORDERFORM_ID SEQUENCE32 SEQ_EDUGAMELOGS SEQUENCE33 SEQ_EDUGAMELOGSATT SEQUENCE34 SEQ_EDUGAMEUSERLOGS SEQUENCE35 SEQ_EDUGAMEUSERROLELOGS SEQUENCE36 SEQ_EDU_APP SEQUENCE37 SEQ_EDU_GAME_JARTOURL SEQUENCE38 SEQ_EDU_GAME_OBJATTID SEQUENCE39 SEQ_EDU_GAME_OBJID SEQUENCE40 SEQ_EDU_GAME_USER SEQUENCE41 SEQ_EDU_GAME_USERATT SEQUENCE42 SEQ_EDU_GAME_USERATTVALUE SEQUENCE43 SEQ_EDU_GAME_USEROBJATTVALUEID SEQUENCE44 SEQ_EDU_GAME_USERPROP SEQUENCE45 SEQ_EDU_GAME_USERPROPLOGS SEQUENCE46 SEQ_EDU_GAME_USERROATTVALUEID SEQUENCE47 SEQ_EDU_GAME_USERROLEATT SEQUENCE48 SEQ_EDU_GAME_USERROLEATTVALUE SEQUENCE49 SEQ_EDU_GAME_USERROLEID SEQUENCE50 SEQ_EDU_GAME_USERROLEPROP SEQUENCE51 SEQ_EDU_GAME_USERROLEPROPLOGS SEQUENCE52 SEQ_EDU_USERINFO SEQUENCE53 SEQ_GAMECROSS SEQUENCE54 SEQ_GAMECROSSATT SEQUENCE55 SEQ_GAMEUSERCROSSATTVALUE SEQUENCE56 SEQ_GAMEUSERLOGSATTVALUE SEQUENCE57 SEQ_GAMEUSERROLECROSSATTVALUE SEQUENCE58 SEQ_GAMEUSERROLELOGSATTVALUE SEQUENCE59 GAME_CROSSKEY INDEX60 EDUUSERINFOINDEX1 INDEX61 GAME_LOGSKEY INDEX62 GAME_LOGSATTKEY INDEX63 GAME_OBJKEY INDEX64 GAME_OBJATTKEY INDEX65 GAME_PROPKEY INDEX66 GAME_USERKEY INDEX67 GAMEUSERINDEX0 INDEX68 GAME_USERATTKEY INDEX69 GAMEUSERATTINDEX0 INDEX70 GAME_USERATTVALUEKEY INDEX71 GAME_USERCROSSATTVALUEKEY INDEX72 GAME_USERLOGSKEY INDEX73 GAME_USERLOGSATTVALUEKEY INDEX74 PRIMARY_KEY INDEX75 GAME_USERPROPKEY INDEX76 GAME_USERPROPLOGSKEY INDEX77 GAME_USERROLEKEY INDEX78 GAME_USERROLEATTKEY INDEX79 GAME_USERROLEATTVALUEKEY INDEX80 GAME_USERROLECROSSATTVALUEKEY INDEX81 GAME_USERROLELOGSKEY INDEX82 GAME_USERROLELOGSATTVALUEKEY INDEX83 GAME_USERROLEOBJATTVALUEKEY INDEX84 GAME_USERROLEPROPKEY INDEX85 GAME_USERROLEPROPLOGSKEY INDEX86 EDUUSERKEY INDEX87 EDUUSERINFOINDEX0 INDEX88 GAME_CROSSATTKEY INDEX
用户锁定和解锁以及修改密码操作
alter user soctt account lock; // 把 scott用户锁定alter user scott account unlock; //把scott用户解锁alter user scott identified by tiger //修改scott用户密码为 tiger,scott用户默认密码为 tiger
使用imp导入oracle数据操作
C:\Users\Administrator>imp dawnweb/dawnwebdawn@nxdxora file=C:\1210\dawnweb.ora full=yImport: Release 10.2.0.5.0 - Production on 星期四 12月 10 17:22:13 2015Copyright (c) 1982, 2007, Oracle. All rights reserved.连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options经由常规路径由 EXPORT:V10.02.01 创建的导出文件已经完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的导入. 正在将 DAWNWEB 的对象导入到 DAWNWEB. . 正在导入表 "EDU_ACTIVE_CARD"导入了 0 行. . 正在导入表 "EDU_APP"导入了 56 行. . 正在导入表 "EDU_APPTYPE"导入了 1 行. . 正在导入表 "EDU_APP_ERROR"导入了 6 行. . 正在导入表 "EDU_APP_PAGETYPE"导入了 5 行. . 正在导入表 "EDU_APP_PIC"导入了 34 行. . 正在导入表 "EDU_APP_PLATFORM"导入了 52 行. . 正在导入表 "EDU_APP_PRODUCT"导入了 597 行. . 正在导入表 "EDU_AREA"导入了 124 行. . 正在导入表 "EDU_MODULE"导入了 1 行. . 正在导入表 "EDU_MSG"导入了 2 行. . 正在导入表 "EDU_NEWACTIVE"导入了 0 行. . 正在导入表 "EDU_OPERATOR_PRODUCT"导入了 41 行. . 正在导入表 "EDU_PARTNER"导入了 5 行. . 正在导入表 "EDU_PLATFORM"导入了 6 行. . 正在导入表 "EDU_PRODUCT"导入了 590 行. . 正在导入表 "EDU_RECHARGE"导入了 0 行. . 正在导入表 "EDU_RECHARGE_FAIL"导入了 0 行. . 正在导入表 "EDU_USERAPP"导入了 262 行. . 正在导入表 "EDU_USERINFO"导入了 16 行. . 正在导入表 "EDU_USERORDER"导入了 34 行. . 正在导入表 "EDU_USERORDER_FAIL"导入了 102 行. . 正在导入表 "EDU_USERTRACE"导入了 22 行. . 正在导入表 "EDU_USERVIRMONEYLOGS"导入了 0 行. . 正在导入表 "HS_BOSS_AREA"导入了 12 行成功终止导入, 没有出现警告。C:\Users\Administrator>imp dawnserv/dawnservdawn@nxdxora file=C:\1210\dawnserv.ora full=y经由常规路径由 EXPORT:V10.02.01 创建的导出文件已经完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的导入. 正在将 DAWNSERV 的对象导入到 DAWNSERV. . 正在导入表 "EDU_APP"导入了 17 行. . 正在导入表 "EDU_GAME_CROSS"导入了 0 行. . 正在导入表 "EDU_GAME_CROSSATT"导入了 0 行. . 正在导入表 "EDU_GAME_JARTOURL"导入了 0 行. . 正在导入表 "EDU_GAME_LOGS"导入了 0 行. . 正在导入表 "EDU_GAME_LOGSATT"导入了 0 行. . 正在导入表 "EDU_GAME_OBJ"导入了 0 行. . 正在导入表 "EDU_GAME_OBJATT"导入了 0 行. . 正在导入表 "EDU_GAME_PROP"导入了 322 行. . 正在导入表 "EDU_GAME_USER"导入了 1 行. . 正在导入表 "EDU_GAME_USERATT"导入了 0 行. . 正在导入表 "EDU_GAME_USERATTVALUE"导入了 0 行. . 正在导入表 "EDU_GAME_USERCROSSATTVALUE"导入了 0 行. . 正在导入表 "EDU_GAME_USERLOGS"导入了 0 行. . 正在导入表 "EDU_GAME_USERLOGSATTVALUE"导入了 0 行. . 正在导入表 "EDU_GAME_USEROBJATTVALUE"导入了 0 行. . 正在导入表 "EDU_GAME_USERPROP"导入了 0 行. . 正在导入表 "EDU_GAME_USERPROPLOGS"导入了 0 行. . 正在导入表 "EDU_GAME_USERROLE"导入了 0 行. . 正在导入表 "EDU_GAME_USERROLEATT"导入了 0 行. . 正在导入表 "EDU_GAME_USERROLEATTVALUE"导入了 0 行. . 正在导入表 "EDU_GAME_USERROLECROSSATTVALUE"导入了 0 行. . 正在导入表 "EDU_GAME_USERROLELOGS"导入了 0 行. . 正在导入表 "EDU_GAME_USERROLELOGSATTVALUE"导入了 0 行. . 正在导入表 "EDU_GAME_USERROLEOBJATTVALUE"导入了 0 行. . 正在导入表 "EDU_GAME_USERROLEPROP"导入了 0 行. . 正在导入表 "EDU_GAME_USERROLEPROPLOGS"导入了 0 行. . 正在导入表 "EDU_USERINFO"导入了 1 行成功终止导入, 没有出现警告。C:\Users\Administrator>
exp导出数据操作
C:\Users\Administrator>exp dawnweb/dawnwebdawn@dawnora file=c:\sql\dawnweb.ora owner=dawnwebExport: Release 10.2.0.1.0 - Production on Thu Dec 10 17:04:40 2015Copyright (c) 1982, 2005, Oracle. All rights reserved.Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith the Partitioning, OLAP and Data Mining optionsExport done in ZHS16GBK character set and AL16UTF16 NCHAR character setAbout to export specified users .... exporting pre-schema procedural objects and actions. exporting foreign function library names for user DAWNWEB. exporting PUBLIC type synonyms. exporting private type synonyms. exporting object type definitions for user DAWNWEBAbout to export DAWNWEB's objects .... exporting database links. exporting sequence numbers. exporting cluster definitions. about to export DAWNWEB's tables via Conventional Path .... . exporting table EDU_ACTIVE_CARD 0 rows exported. . exporting table EDU_APP 56 rows exported. . exporting table EDU_APPTYPE 1 rows exported. . exporting table EDU_APP_ERROR 6 rows exported. . exporting table EDU_APP_PAGETYPE 5 rows exported. . exporting table EDU_APP_PIC 34 rows exported. . exporting table EDU_APP_PLATFORM 52 rows exported. . exporting table EDU_APP_PRODUCT 597 rows exported. . exporting table EDU_AREA 124 rows exported. . exporting table EDU_MODULE 1 rows exported. . exporting table EDU_MSG 2 rows exported. . exporting table EDU_NEWACTIVE 0 rows exported. . exporting table EDU_OPERATOR_PRODUCT 41 rows exported. . exporting table EDU_PARTNER 5 rows exported. . exporting table EDU_PLATFORM 6 rows exported. . exporting table EDU_PRODUCT 590 rows exported. . exporting table EDU_RECHARGE 0 rows exported. . exporting table EDU_RECHARGE_FAIL 0 rows exported. . exporting table EDU_USERAPP 262 rows exported. . exporting table EDU_USERINFO 16 rows exported. . exporting table EDU_USERORDER 34 rows exported. . exporting table EDU_USERORDER_FAIL 102 rows exported. . exporting table EDU_USERTRACE 22 rows exported. . exporting table EDU_USERVIRMONEYLOGS 0 rows exported. . exporting table HS_BOSS_AREA 12 rows exported. exporting synonyms. exporting views. exporting stored procedures. exporting operators. exporting referential integrity constraints. exporting triggers. exporting indextypes. exporting bitmap, functional and extensible indexes. exporting posttables actions. exporting materialized views. exporting snapshot logs. exporting job queues. exporting refresh groups and children. exporting dimensions. exporting post-schema procedural objects and actions. exporting statisticsExport terminated successfully without warnings.
删除用户,cascade参数可以连用户对象一起删除
drop user jsyxedu cascade;drop user jsyxgame cascade;drop user jsyxweb cascade;drop user jsyxsys cascade;drop user jsyxserv cascade;
新建用户,指定表空间,分配权限
create user tjltedu identified by dawnedutjlt default tablespace HSEDUSP temporary tablespace HSEDUTMPSP quota unlimited on HSEDUSP;grant dba, connect, resource to tjltedu;create user tjltgame identified by dawngametjlt default tablespace HSEDUSP temporary tablespace HSEDUTMPSP quota unlimited on HSEDUSP;grant dba, connect, resource to tjltgame;create user tjltweb identified by dawnwebtjlt default tablespace HSEDUSP temporary tablespace HSEDUTMPSP quota unlimited on HSEDUSP;grant dba, connect, resource to tjltweb;create user tjltsys identified by dawnsystjlt default tablespace HSEDUSP temporary tablespace HSEDUTMPSP quota unlimited on HSEDUSP;grant dba, connect, resource to tjltsys;create user tjltserv identified by dawnservtjlt default tablespace HSEDUSP temporary tablespace HSEDUTMPSP quota unlimited on HSEDUSP;grant dba, connect, resource to tjltserv;
1.查看所有用户:
select * from dba_users; select * from all_users; select * from user_users;
2.查看用户或角色系统权限(直接赋值给用户或角色的系统权限):
select * from dba_sys_privs; select * from user_sys_privs; (查看当前用户所拥有的权限)
第二条查看自己当前用户的系统权限
3.查看角色(只能查看登陆用户拥有的角色)所包含的权限
sql>select * from role_sys_privs;
4.查看用户对象权限:
select * from dba_tab_privs; select * from all_tab_privs; select * from user_tab_privs;
5.查看所有角色:
select * from dba_roles;
6.查看用户或角色所拥有的角色:
select * from dba_role_privs; select * from user_role_privs;
第一条看的是当前数据库每个用户的权限
第二条看的是当前用户的权限
7.查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)
select * from V$PWFILE_USERS
8.SqlPlus中查看一个用户所拥有权限
SQL>select * from dba_sys_privs where grantee='username'; 其中的username即用户名要大写才行。比如: SQL>select * from dba_sys_privs where grantee='TOM';
9、Oracle删除指定用户所有表的方法
select 'Drop table '||table_name||';' from all_tables where owner='要删除的用户名(注意要大写)';
测试如下
10、删除用户
drop user user_name cascade; 如:drop user SMCHANNEL CASCADE
11、获取当前用户下所有的表:
select table_name from user_tables;
12、删除某用户下所有的表数据:
select 'truncate table ' || table_name from user_tables;
测试如下
imp导入参数full=y和fromuser
full=y,是导入文件中全部内容,有可能有多个用户的内容。比如将数据库中system用户与sys用户的表导出exp system/manager@TEST file=d:\daochu.dmp owner=(system,sys)full=y和fromuser参数冲突。只能二者选一个如果导出的时候按照用户来导出的,就必要添加参数full=y