永夜-Evernight

永夜降临之前,你都有改变的资格

oracle常用命令

1.导出命令

  • 导出本地数据库:exp [数据库名]/[数据库密码] owner=[数据库用户] file=E:[文件路径][文件名].dmp statistics=none
  • 导出远程数据库:exp [数据库名]/[数据库密码]@[远程服务器ip]:[端口号]/[数据库实例名] owner=[数据库用户] file=E:[文件路径][文件名].dmp statistics=none

2.导入命令

  • 导入数据库文件到本机用户下:imp [用户名]/[密码] fromuser=[导出文件所用用户] touser=[导入用户] file=[文件位置]
  • 导入数据库文件到远程数据库:imp [用户名]/[密码]@[远程主机ip]:[oracle端口]/[实例名] fromuser=[导出文件所用用户] touser=[导入用户] file=[文件位置]

3.删除数据库中某个用户并重新导入数据

1.删除本机该用户下所有对象(表、视图、序列、键。。。)
drop user lzrbcds cascade;
2.删除该用户的表空间
drop tablespace lzrbcds INCLUDING CONTENTS;
3.创建表空间
create tablespace lzrbcds datafile 'E:\oracle_db\lzrbcds.dbf' size 4084M;
4.创建用户并分配默认表空间
create user lzrbcds identified by lzrbcds default tablespace lzrbcds;
5.为该用户分配权限
grant connect,resource,dba to lzrbcds;
6.导入数据库文件到该用户下(本机)
imp lzrbcds/lzrbcds fromuser=lzrbcds touser=lzrbcds file=D:\桌面\lzrbcds.dmp
7.导入数据库文件到远程数据库
imp lzrbcds/lzrbcds@192.168.1.113:1521/orcl fromuser=lzrbcds touser=lzrbcds file=D:\桌面\lzrbcds.dmp
8.从远程数据库导出数据库文件
exp lzrbcds/lzrbcds@192.168.1.113:1521/orcl file=D:\桌面\lzrbcds.dmp statistics=none
9.从本地数据库导出数据库文件

4.Oracle删除当前用户下的所有表、视图、序列、函数、存储过程、包

https://www.iteye.com/blog/uu011-1627692
--delete tables
select 'drop table ' || table_name ||';'||chr(13)||chr(10) from user_tables;
select 'drop table ' || table_name ||';'||chr(13)||chr(10) from user_tables;
--delete views
select 'drop view ' || view_name||';'||chr(13)||chr(10) from user_views;
select 'drop view ' || view_name||';'||chr(13)||chr(10) from user_views;
--delete seqs
select 'drop sequence ' || sequence_name||';'||chr(13)||chr(10) from user_sequences;
select 'drop sequence ' || sequence_name||';'||chr(13)||chr(10) from user_sequences;
--delete functions
select 'drop function ' || object_name||';'||chr(13)||chr(10) from user_objects where object_type='FUNCTION';
select 'drop function ' || object_name||';'||chr(13)||chr(10) from user_objects where object_type='FUNCTION';
--delete procedure
select 'drop procedure ' || object_name||';'||chr(13)||chr(10) from user_objects where object_type='PROCEDURE';
select 'drop procedure ' || object_name||';'||chr(13)||chr(10) from user_objects where object_type='PROCEDURE';
--delete package
select 'drop package ' || object_name||';'||chr(13)||chr(10) from user_objects where object_type='PACKAGE';
select 'drop package ' || object_name||';'||chr(13)||chr(10) from user_objects where object_type='PACKAGE';


标题:oracle常用命令
作者:luomuren
地址:http://luomuren.top/oracle