1、创建表空间
----//删除oracle数据库用户对象
drop user hteval cascade
----//删除oracle数据库用户对象及磁盘上的数据文件
alter tablespace hteval offline;
drop tablespace hteval including contents and datafiles;
----//查询表空间
select tablespace_name,file_id,file_name from dba_data_files order by file_id;
----//创建oracle数据库用户对象
create tablespace hteval
logging
datafile 'E:\app\wangcg\oracledb\oradata\oradb\xbztpt.dbf'
size 200m
autoextend on
next 100m maxsize unlimited
extent management local;
----//创建用户并指定表空间
create user hteval identified by 111111 default tablespace hteval;
----//给用户授予权限
grant connect,resource to hteval;
----// 追加表空间
alter tablespace hymall add datafile '/u01/app/oracle/oradata/RHYRSM/hymall4.dbf' size 500m autoextend on next 100m maxsize unlimited;
----//查看表空间使用情况
select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used" from (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a, (select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b where a.tablespace_name=b.tablespace_name order by ((a.bytes-b.bytes)/a.bytes) desc;
----//空表分配表空间 设置deferred_segment_creation参数
show parameter deferred_segment_creation;
alter system set deferred_segment_creation=false;
----//空表处理
select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0
select * from user_tab_comments;
select * from user_col_comments;
select 'comment on column '||t.table_name||'.'||t.column_name||' is '''';' from user_col_comments t;
2、导入导出数据库
---- 导出
exp thkqspzt/111111@ORADB_191 file=d:\thkqszpt.dmp
---- 导入
imp thkqspzt/111111@ORADB_191 file=d:\thkqszpt.dmp
---- 示例
exp hymall/111111@orcl_aliyun file=d:\hymall.dmp direct=y indexes=n rows=y buffer=[104857600](tel:104857600) compress=n feedback=100000
exp 登录名/密码/@数据库名 file:d:\db.dmp
3、数据秒恢复
select * from report_plan_task_detail as of timestamp to_timestamp('2013-12-12 10:20:00', 'yyyy-mm-dd hh24:mi:ss');
4、Oracle 排序
oracle 按照名称排序 NLSSORT(DEPART_NAME, 'NLS_SORT=SCHINESE_PINYIN_M')
5、Linux下启动oracle
su - oracle
sqlplus /nolog
conn /as sysdba
startup
exit
# 启动监听
lsnrctl start
exit
6、数据泵导入导出
一、数据导出,执行命令:
- 运行cmd;
- 登录数据库,输入命令:sqlplus;
- 使用管理员角色登录需要在用户名后加“ as sysdba” 例如:sys as sysdba
** 创建目录路径:输入命令:create directory data_dir as 'E:\ora\data' ; 删除目录: drop directory data_dir - data_dir为路径名称,可自命名,E:\ora\data为数据库导出文件存放路径(路径必须存在);
- 使用命令:select * from dba_directories可查询用户创建目录.
** 为oracle用户授予访问数据目录的权限,输入命令:Grant read,write on directory data_dir to dbuser; - dbuser为数据库用户名(与第5步中相同)
** 导入导出操作授权,输入命令:grant exp_full_database,imp_full_database to dbuser
** 退出,输入命令:exit
** 数据导出,执行命令:
expdp dbuser/123456@orcl schemas=dbuser dumpfile=expdp.dmp directory=data_dir logfile=expdp.log
expdp [为用户名]/[密码]@[服务名]
schemas=[为用户名]
dumpfile=[导出数据库文件(可自命名)]
directory=[目录名]
logfile=[日志文件文件名(可自命名)]
二、数据导入,执行命令:
- 运行cmd;
- 登录数据库,输入命令:sqlplus;
- 使用管理员角色登录需要在用户名后加“ as sysdba” 例如:sqlplus sys as sysdba
** 创建目录路径:输入命令:create directory data_dir as 'E:\ora\data' 删除目录: drop directory data_dir - data_dir为路径名称,可自命名,E:\ora\data为数据库导入文件存放路径(路径必须存在)
- 使用命令:select * from dba_directories;可查询用户创建目录
** 为oracle用户授予访问数据目录的权限,输入命令:Grant read,write on directory data_dir to dbuser - dbuser为数据库用户名(与第5步中相同)
** 导入导出操作授权,输入命令:grant exp_full_database,imp_full_database to dbuser
** 将从A电脑中E:\ora\data目录下的.dmp数据泵导出文件拷贝至B电脑创建的目录(E:\ora\data)中(同一个电脑不需要)
** 退出,输入命令:exit
** 数据导入,执行命令:
impdp user/123456@orcl REMAP_SCHEMA = dbuser:dbuser table_exists_action = replace directory=data_dir schemas=hymall dumpfile=expdp.dmp logfile=expdp.log
impdp [用户名]/[密码]@[服务名]
REMAP_SCHEMA=[源用户名1]:[目标用户名2]
table_exists_action=replace /存在的表动作(覆盖)/
directory=[目录名]
exclude=table:in('TRACK_LOG')
dumpfile=[.dmp文件名]
logfile=[.log文件名]
Linux操作系统目录权限
root用户下:mkdir /u01/ 新建一个u01的文件夹du
root用户下:chown oracle:oinstall /u01 把新建的 /u01权限dao给予oracle用户
root用户下:chmod 755 /u01 赋予这个文件夹读写权限