一、概述
在將dmp文件導入到Oracle中之前,需要先創建一個orcale用戶。然后使用該用戶名和密碼,以imp的方式將數據導入到oracle中。
二、執行步驟
1、登陸oracle數據庫
a、sqlplus / as sysdba
b、如果使用a不成功,則使用 sqlplus demo/demo@localhost/ORCLpdb1的方式
2、查詢臨時空間表和表空間的存儲位置
select name from v$tempfile;
select name from v$datafile;
3、創建用戶臨時表空間和表空間,使用上面查到的任一存儲位置即可
create temporary tablespace demo_temp tempfile '/oracle/u02/oradata/ERP2/demo_temp.dbf' size 100m reuse autoextend on next 20m maxsize unlimited;
create tablespace demo datafile '/oracle/u02/oradata/ERP2/demo.dbf' size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);
注:刪除表空間的命令drop tablespace temp including contents and datafiles;
4、創建用戶並指定表空間
create user demo identified by demo default tablespace demo temporary tablespace demo_temp;
5、如果此時報錯,Oracle 19c:創建用戶時出現“ORA-65096: invalid common user or role name”的錯誤
這時涉及到CDB和PDB的基本管理,資料來源oracle官方。
基本概念:
Multitenant Environment:多租戶環境
CDB(Container Database):數據庫容器
PD(Pluggable Database):可插拔數據庫
CDB與PDB關系圖
COMMON USERS(普通用戶):經常建立在CDB層,用戶名以C##或c##開頭;
LOCAL USERS(本地用戶):僅建立在PDB層,建立的時候得指定CONTAINER。
官方原始文件介紹如下:
The data dictionary in each container in a CDB is separate, and the current container is the container whose data dictionary is used for name resolution and for privilege authorization. The current container can be the root or a PDB. Each session has exactly one current container at any point in time, but it is possible for a session to switch from one container to another.
Each container has a unique ID and name in a CDB. You can use the CON_ID and CON_NAME parameters in the USERENV namespace to determine the current container ID and name with the SYS_CONTEXT function.
說白了,就是你當前的session不能創建你需要的用戶,需要使用SYS_CONTEXT函數
a、查看Oracle 19c的版本
select * from v$version;
select sys_context ('USERENV', 'CON_NAME') from dual;
b、我們可以通過ALTER SESSION SET CONTAINER 指定其他容器
select con_id,dbid,NAME,OPEN_MODE from v$pdbs;
C、將PDB open
alter pluggable database pdborcl open;
d、查看容器
select con_id,dbid,NAME,OPEN_MODE from v$pdbs;
e、切換到pdb
alter session set container=PDBORCL;
f、查看當前使用容器
select sys_context ('USERENV', 'CON_NAME') from dual;
g、創建用戶
create user demo identified by demo default tablespace demo temporary tablespace demo_temp;
6、導入文件到oracle
oracle連接方式用兩種,一般用戶喜歡使用Server_id的方式,導入方式為
imp demo/123456@orcl file="C:\Users\xiejiachen\Desktop\test20190630.DMP" full =y;
使用server_name的導入方式如下:
imp demo/123456@localhost/ORCLpdb1 file=home/oracle/demo.dmp ignore=y full=y
其中demo為用戶名,123456為密碼,@后面是主機名稱,ORCLpdb1是server的名稱。