创建表空间自动化脚本

/*====================================================================/
  ##  功能描述:
  ##   创建数据库用户脚本
  ##   默认创建用户为:username/password
  ##   username=username
  ##   password=password
  ##   schema=username(数据表空间)
  ##  设 计 者:michales
  ##  设计日期: 2010-11-18
 
  ##  更 新 人: /
  ##  更新内容: /
  ##  更新日期: /
 /====================================================================*/
REM
REM Create a tablespace and username user
REM username/password
REM

SET ECHO OFF

connect sys/&sys_passwd@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=&_host)(PORT=&_port)))(CONNECT_DATA=(SERVICE_NAME=&_instance))) as sysdba

SET ECHO ON
SET FEEDBACK 1
SET NUMWIDTH 10
SET LINESIZE 80
SET TRIMSPOOL ON
SET TAB OFF
SET PAGESIZE 100

REM Create username tablespace
REM Oracle database requires that the datafile be qualified
REM explicitly. This procedure checks where the SYSTEM datafiles
REM are and then uses that directory for the username datafile.
REM If the username tablespace already exists, then do nothing.

SET ECHO OFF

DECLARE
  unix    NUMBER;
  win     NUMBER;
  tsexists NUMBER;
  uname   varchar2(512);
  wname   varchar2(512);
  datadir varchar2(512);
BEGIN

--
-- Check if tablespace already exists
--

select count(*)
    into tsexists from v$tablespace
    where name = 'username';

IF tsexists >= 1 THEN
    dbms_output.put_line('Tablespace already exists.');
    RETURN;
END IF;

--
-- We could either be on Windows or Unix. Search for the last
-- character that's either a / or \ and figure out which platform
-- we're on.
--

select instr(name, '\', -1), name
    into win, wname from v$datafile
    where file# = (select min(file#) from v$datafile where
          ts# = (select ts# from v$tablespace where name = 'SYSTEM'));

select instr(name, '/', -1), name
    into unix, uname from v$datafile
    where file# = (select min(file#) from v$datafile where
          ts# = (select ts# from v$tablespace where name = 'SYSTEM'));

IF unix > win THEN
    datadir := SUBSTR (uname, 1, unix);
ELSE
    datadir := SUBSTR (wname, 1, win);
END IF;

dbms_output.put_line ('datadir = ' || datadir);


--
-- Create Tablespaces with datafiles in datadir.
--

execute immediate 'create tablespace username datafile ' ||
    '''' || datadir || 'username.dbf' || '''' ||
    ' SIZE 100M reuse autoextend on NEXT 30M maxsize unlimited';

END;
/


SET ECHO ON

REM
REM Create and grant privileges to username user
REM

drop user username cascade;

REM Create and assign privileges to username user
create user username identified by password
        default tablespace username;

GRANT CONNECT, RESOURCE TO username;
GRANT SELECT ANY TABLE TO username;
GRANT ALTER SESSION TO username;
GRANT ALTER DATABASE TO username;
GRANT CREATE ANY INDEX TO username;
GRANT CREATE SESSION TO username;
GRANT CREATE SYNONYM TO username;
GRANT CREATE VIEW TO username;
GRANT EXECUTE ANY PROCEDURE TO username;
GRANT IMP_FULL_DATABASE TO username;
GRANT DEBUG CONNECT SESSION TO username;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值