用户表空间及权限
-- 创建表空间(根据不同环境配置表空间的数据文件路径)
Create Tablespace TBS_XX Datafile 'D:\APP\ADMINISTRATOR\ORADATA\ORCL\TBS_XX_01.dbf' Size 100M Autoextend On Next 100M Maxsize Unlimited;
-- 增加数据文件
Alter Tablespace TBS_XX Add Datafile 'D:\APP\ADMINISTRATOR\ORADATA\ORCL\TBS_XX_02.dbf' Size 100M Autoextend On Next 100M Maxsize Unlimited;
-- 创建用户及授权
-- Create the user
create user test
identified by 123456
default tablespace TBS_XX;
-- Grant/Revoke role privileges
grant connect to test;
grant dba to test;
grant resource to test;
-- Grant/Revoke system privileges
grant alter system to test;
grant execute any procedure to test;
grant select any dictionary to test;
grant unlimited tablespace to test;
备份/导出
注:下面@orcl需要配置tnsnames.ora
1.导出全部
exp test/123456@orcl file=D:\backup.dmp full=y
2.导出指定用户
exp test/123456@orcl file=D:\backup.dmp owner=test
3.导出指定表(rows=n|y是否导出数据)
exp test/123456@orcl file=D:\backup.dmp tables=(table1,table2) rows=n
举个栗子:
exp test/123456@192.168.1.201:1521/orcl file=D:\backup.dmp log=D:\backup.log owner=test
还原/导入
注:下面@orcl需要配置tnsnames.ora
1.导入当前用户(异常依旧提交,忽略创建错误)
imp test2/123456@orcl file=D:\backup.dmp log=D:\backup.log ignore=y full=y commit=yes
2.导入指定用户
imp test2/123456@orcl file=D:\backup.dmp fromuser=test2 touser=test ignore=y commit=yes
3.导入指定表
imp test2/123456@orcl file=D:\backup.dmp tables=(table1,table2) ignore=y commit=yes
举个栗子:
imp test2/123456@192.168.1.201:1521/orcl file=D:\backup.dmp log=D:\backup.log fromuser=test touser=test2 ignore=y commit=yes
注:操作用户需要拥有对应的权限
导出空表(对空表分配存储空间即可exp导出)
--导出dmp文件时,只有执行以下语句,才能导出0行数据的表结构.否则,dmp中不包含这些表.
--Alter Table Allocate Extent (Szie 500K); 对空表分配存储空间
--Alter Table Deallcoate Unused; 对表回收存储空间
Declare
Cursor rows Is select table_name from sys.USER_TABLES where table_name not in (select table_name from sys.USER_PART_TABLES);
sName Varchar2(1024);
temp Number(15);
tempSql Varchar2(1024);
Begin
Open rows;
Loop
Fetch rows
Into sName;
Exit When rows%NotFound;
tempSql := 'Select Count(*) From ' || sName;
Execute Immediate tempSql
Into temp;
if temp = 0 then
Execute Immediate 'alter table ' || sName || ' allocate extent (size 100k)';
end if;
End Loop;
Close rows;
End;