Oracle Database 12c 如何创建数据库
1.过程:
-- 创建临时空间,找到D:\app\orcl\oradata\orcl目录,创建local目录
-- drop tablespace local_temp;
create temporary tablespace local_temp
tempfile 'D:\app\weblogic\oradata\orcl\local_temp.dbf'
size 32m
autoextend on
next 32m maxsize 2048m
extent management local;
2.
-- 创建数据表空间,找到D:\app\orcl\oradata\orcl目录,创建local目录
-- drop tablespace local_data;
create tablespace local_data
logging
datafile 'D:\app\weblogic\oradata\orcl\local_data.dbf'
size 32m
autoextend on
next 32m maxsize 2048m
extent management local;
3.. -- 创建用户并指定表空间
create user c##jwxt identified by jwxt
profile default
default tablespace local_data
temporary tablespace local_temp
account unlock;
-- 刚开始用户名为jwxt,提示错误ORA-65096:公用用户名或角色名无效
-- 网上查资料,说是取名前缀必须为c##,所以用户名也变成了c##jwxt
/*
ORA-65048:在可插入数据库PDBORCL中处理当前DDL语句时出错
ORA-00959:表空间‘LOCL_DATA’不存在
(注:开始一直提示这个错误,我就纳闷,后来重启下Oracle服务之后,就不会报这个错了)
*/
4. -- 授权给c##wangxin ,ps:根据需要设置权限。
grant create any view,drop any view,connect,resource,create session,dba to c##jwxt;
/*GRANT CREATE USER,DROP USER,ALTER USER,CREATE ANY VIEW,DROP ANY VIEW,
EXP_FULL_DATABASE,IMP_FULL_DATABASE,CONNECT,RESOURCE,CREATE SESSION,
select any table,DBA TO c##wangxin;*/
5. 删除表空间和用户
删除表空间
drop tablespace jwxt including contents and datafiles -- jwxt为之前创建的表空间名
删除用户
drop user jwxt cascade -- jwxt 为用户名
查看所有的用户
select username from dba_users;
-- Other (查看结构)
select * from v$version;
select name from v$datafile;
select * from v$pdbs;
--创建一个表 (测试一下)
CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10),
HIREDATE DATE);
--插入数据
INSERT INTO EMP VALUES (1, 'SMITH', TO_DATE('17-DEC-1980', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (2, 'ALLEN', TO_DATE('20-FEB-1981', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (3, 'WARD', TO_DATE('22-FEB-1981', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (4, 'JONES', TO_DATE('2-APR-1981', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (5, 'MARTIN',TO_DATE('28-SEP-1981', 'DD-MON-YYYY'));
select * from emp;