Oracle11g创建表空间

Posted boosli

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle11g创建表空间相关的知识,希望对你有一定的参考价值。

/* Formatted on 2008/11/04 15:44 (Formatter Plus v4.8.0) */
/*
创建表空间脚本,该脚本将创建以下表空间:
1.数据表空间
2.索引表空间
3.临时表空间
创建之前需要定义下列变量(只考虑一个表空间对应一个数据文件情形,如对应多个数据文件请用alter tablespace add datafile命令):
data_tablespace_name 数据表空间名称
index_tablespace_name 索引表空间名称
temp_tablespace_name 临时表空间名称
data_datafile_name 数据表空间对应数据文件名称,含路径
index_datafile_name 索引表空间对应数据文件名称,含路径
temp_datafile_name 临时表空间对应数据文件名称,含路径
data_datafile_size 数据表空间对应数据文件大小,单位M
index_datafile_size 索引表空间对应数据文件大小,单位M
temp_datafile_size 临时表空间对应数据文件大小,单位M

*/
SET SERVEROUTPUT ON

DECLARE
data_tablespace_name CONSTANT VARCHAR2 (64) := ‘cg_data‘;
index_tablespace_name CONSTANT VARCHAR2 (64) := ‘cg_index‘;
temp_tablespace_name CONSTANT VARCHAR2 (64) := ‘cg_temp‘;
data_datafile_name CONSTANT VARCHAR2 (512)
:= ‘F:appAdministratororadatayycgcg_data.dbf‘;
index_datafile_name CONSTANT VARCHAR2 (512)
:= ‘F:appAdministratororadatayycgcg_index.dbf‘;
temp_datafile_name CONSTANT VARCHAR2 (512)
:= ‘F:appAdministratororadatayycgcg_temp.dbf‘;
data_datafile_size CONSTANT VARCHAR2 (64) := ‘100m‘;
index_datafile_size CONSTANT VARCHAR2 (64) := ‘20m‘;
temp_datafile_size CONSTANT VARCHAR2 (64) := ‘20m‘;

FUNCTION f_tablespaceexists (v_tsname IN VARCHAR2)
RETURN BOOLEAN
IS
v_rowcount INT := 0;
BEGIN
SELECT COUNT (*)
INTO v_rowcount
FROM user_tablespaces
WHERE tablespace_name = UPPER (v_tsname);

IF v_rowcount <> 0
THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END f_tablespaceexists;

PROCEDURE p_execcmd (v_cmd IN VARCHAR2)
AS
v_cursorid INTEGER;
BEGIN
v_cursorid := DBMS_SQL.open_cursor;
DBMS_SQL.parse (v_cursorid, v_cmd, DBMS_SQL.native);
DBMS_SQL.close_cursor (v_cursorid);
EXCEPTION
WHEN OTHERS
THEN
DBMS_SQL.close_cursor (v_cursorid);
RAISE;
END p_execcmd;
BEGIN
DBMS_OUTPUT.put_line
(‘开始创建表空间,如果表空间已经存在将被删除........................‘);

IF f_tablespaceexists (data_tablespace_name)
THEN
DBMS_OUTPUT.put_line ( ‘删除数据表空间‘
|| data_tablespace_name
|| ‘........................‘
);
p_execcmd ( ‘DROP TABLESPACE ‘
|| data_tablespace_name
|| ‘ INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS‘
);
DBMS_OUTPUT.put_line (‘数据表空间‘ || data_tablespace_name || ‘已删除。‘);
END IF;

IF f_tablespaceexists (index_tablespace_name)
THEN
DBMS_OUTPUT.put_line ( ‘删除索引表空间‘
|| index_tablespace_name
|| ‘........................‘
);
p_execcmd ( ‘DROP TABLESPACE ‘
|| index_tablespace_name
|| ‘ INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS‘
);
DBMS_OUTPUT.put_line (‘索引表空间‘ || index_tablespace_name
|| ‘已删除。‘
);
END IF;

IF f_tablespaceexists (temp_tablespace_name)
THEN
DBMS_OUTPUT.put_line ( ‘删除临时表空间‘
|| temp_tablespace_name
|| ‘........................‘
);
p_execcmd ( ‘DROP TABLESPACE ‘
|| temp_tablespace_name
|| ‘ INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS‘
);
DBMS_OUTPUT.put_line (‘临时表空间‘ || temp_tablespace_name || ‘已删除。‘);
END IF;

---------------------------创建数据表空间-------------------------------------
DBMS_OUTPUT.put_line ( ‘创建数据表空间‘
|| data_tablespace_name
|| ‘..............................‘
);
p_execcmd ( ‘CREATE TABLESPACE ‘
|| data_tablespace_name
|| ‘
DATAFILE ‘‘‘
|| data_datafile_name
|| ‘‘‘ SIZE ‘
|| data_datafile_size
|| ‘
AUTOEXTEND ON NEXT ‘
|| data_datafile_size
);
DBMS_OUTPUT.put_line (‘数据表空间‘ || data_tablespace_name || ‘已创建。‘);
---------------------------创建索引表空间-------------------------------------
DBMS_OUTPUT.put_line ( ‘创建索引表空间‘
|| index_tablespace_name
|| ‘..............................‘
);
p_execcmd ( ‘CREATE TABLESPACE ‘
|| index_tablespace_name
|| ‘
DATAFILE ‘‘‘
|| index_datafile_name
|| ‘‘‘ SIZE ‘
|| index_datafile_size
|| ‘
AUTOEXTEND ON NEXT ‘
|| index_datafile_size
);
DBMS_OUTPUT.put_line (‘索引表空间‘ || index_tablespace_name || ‘已创建。‘);
---------------------------创建临时表空间-------------------------------------
DBMS_OUTPUT.put_line ( ‘创建临时表空间‘
|| temp_tablespace_name
|| ‘..............................‘
);
p_execcmd ( ‘CREATE TEMPORARY TABLESPACE ‘
|| temp_tablespace_name
|| ‘
TEMPFILE ‘‘‘
|| temp_datafile_name
|| ‘‘‘ SIZE ‘
|| temp_datafile_size
|| ‘
AUTOEXTEND ON NEXT ‘
|| temp_datafile_size
);
DBMS_OUTPUT.put_line (‘临时表空间‘ || temp_tablespace_name || ‘已创建。‘);
END;

 


create user cg_user identified by password;

grant connect to cg_user with admin option;
grant resource to cg_user with admin option;
grant dba to cg_user with admin option;


create user gps identified by password;

grant connect to gps with admin option;
grant resource to gps with admin option;
grant dba to gps with admin option;

create user qh_user identified by password;

grant connect to qh_user with admin option;
grant resource to qh_user with admin option;
grant dba to qh_user with admin option;

create user CG_DEV identified by password;

grant connect to CG_DEV with admin option;
grant resource to CG_DEV with admin option;
grant dba to CG_DEV with admin option;

IMP cg_user/[email protected] BUFFER=64000 FILE=E:岳阳yycgcg.DMP FULL=Y

IMP cg_user/[email protected] BUFFER=64000 FILE=E:岳阳yycggps.DMP FULL=Y

IMP CG_DEV/[email protected] BUFFER=64000 FILE=E:岳阳cgdev.DMP FULL=Y

##impdp cg_user/[email protected] dumpfile=MD_TEST.DMP logfile=11.log schemas=MD_TEST

IMP MD_TEST/[email protected] BUFFER=64000 FILE=C:MD_TEST.DMP FULL=Y

EXP CG_DEV/[email protected] BUFFER=64000 FILE=C:cgdev.DMP
EXP qh_user/[email protected] BUFFER=64000 FILE=C:cgqh.DMP

EXP MD_TEST/[email protected] BUFFER=64000 FILE=C:MD_TEST.DMP

EXP wjzbcz/[email protected] BUFFER=64000 FILE=C:wjzbcz.DMP

 































































































































































以上是关于Oracle11g创建表空间的主要内容,如果未能解决你的问题,请参考以下文章

oracle 创建表空间及oracle 11g表空间之最大最小

Oracle11g创建表空间语句

oracle11g 系统表空间满 会自动增加吗

Oracle 11g 创建表空间权限不足试过了好多方法还是没用

Oracle11g 脚本创建表空间和用户

oracle11g给某个用户创建表空间