创建了用户:create ucfq identified by pcfq;
创建表
create table stud(
sid number primary key,
age number,
birthday date,
sex varchar2(6)
)
partition by range(sid) subpartition by list(sex)
(
partition p1 values less than(10) tablespace tablespace_102
(subpartition p1sub1 values('男'),
subpartition p1sub2 values('女'),
subpartition p1sub3 values('其他')
),
partition p2 values less than(20) tablespace tablespace_102
(
subpartition p2sub1 values('男'),
subpartition p2sub2 values('女'),
subpartition p2sub3 values('其他')
),
partition p3 values less than(30) tablespace tablespace_102
(
subpartition p3sub1 values('男'),
subpartition p3sub2 values('女'),
subpartition p3sub3 values('其他')
),
partition p4 values less than(41) tablespace tablespace_102
(
subpartition p4sub1 values('男'),
subpartition p4sub2 values('女'),
subpartition p4sub3 values('其他')
)
);
插入数据:
declare
psex varchar2(6);
random_chance number;
begin
for sid in 1..40 loop
random_chance:=dbms_random.value(0,100);
if(random_chance<40) then
psex:='女';
elsif(random_chance<90) then
psex:='男';
else
psex:='其他';
end if;
insert into stud(sid,sex) values(sid,psex);
end loop;
commit;
end;
通过exp/imp进行逻辑备份 win+r进入命令行:
1:将指定的表导出
exp 用户名/密码 file='路径名/文件名.dmp' tables=(tablename1,tablename2...)
如将ucfq用户的表stud导出 d:/oracleback1.dmp
exp ucfq/pcfq file='d:/oracleback1.dmp' tables=(stud);
2:将用户ucfq的所有数据导出到d:/oracleback2.dmp
exp ucfq/pcfq file='d:/oracleback2.dmp' ful=y
3:导出数据库
exp system/zhu123456 file='d:/c.dmp' full=y
导入表:
drop table stud;
imp ucfq/pcfq file='d:/oracleback1.dmp' tables=(stud) ignore=y
ignore:表示如果stud表已存在时,忽略
导入用户ucfq的所有数据
drop user ucfq cascade;
create user ucfq identified by pcfq;
grant dba to ucfq;
imp ucfq/pcfq file='d:/oracleback2.dmp'
导入数据库
imp system/oracle file=c.dmp full=y
二:通过expdp/impdp 进行逻辑备份
先建一个目录:用于存放导出文件
create directory(目录) directory_name(目录名) as '文件夹名';
create directory dir_dump as 'E:\dirback';
grant read,write on directory dir_dump to ucfq;
1:导出表
expdp ucfq/pcfq directory=dir_dump dumpfile=stud.dmp tables=stud
impdp system/zhu123456 directory=dump_dir dumpfile=schemaScott.dmp schemas=scott
三:脱机备份,冷备份
备份:
所有数据文件
所有控制文件
所有联机重做日志
init.ora
查看数据文件
select * from V$LOGFILE;
查看重演日志文件
select * from V$DBFile;
查看控制文件
select* from V$controlfile;
recover database until cancel;