码迷,mamicode.com
首页 > 数据库 > 详细

Oracle11g创建表空间

时间:2018-12-31 11:22:59      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:out   proc   lin   procedure   where   ORC   emp_table   cascade   end   

/* 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:\app\Administrator\oradata\yycg\cg_data.dbf‘;
index_datafile_name CONSTANT VARCHAR2 (512)
:= ‘F:\app\Administrator\oradata\yycg\cg_index.dbf‘;
temp_datafile_name CONSTANT VARCHAR2 (512)
:= ‘F:\app\Administrator\oradata\yycg\cg_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/password@yycg BUFFER=64000 FILE=E:\岳阳\yycgcg.DMP FULL=Y

IMP cg_user/password@yycg BUFFER=64000 FILE=E:\岳阳\yycggps.DMP FULL=Y

IMP CG_DEV/password@yycg BUFFER=64000 FILE=E:\岳阳\cgdev.DMP FULL=Y

##impdp cg_user/system@orcl dumpfile=MD_TEST.DMP logfile=11.log schemas=MD_TEST

IMP MD_TEST/password@orcl BUFFER=64000 FILE=C:\MD_TEST.DMP FULL=Y

EXP CG_DEV/password@yycg BUFFER=64000 FILE=C:\cgdev.DMP
EXP qh_user/password@yycg BUFFER=64000 FILE=C:\cgqh.DMP

EXP MD_TEST/password@orcl BUFFER=64000 FILE=C:\MD_TEST.DMP

EXP wjzbcz/password@orcl BUFFER=64000 FILE=C:\wjzbcz.DMP

 

Oracle11g创建表空间

标签:out   proc   lin   procedure   where   ORC   emp_table   cascade   end   

原文地址:https://www.cnblogs.com/boosli/p/10201487.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!