Subject

hp (8) hpbsm (8) omi (8) bsm (7) hpom (6) om (5) hpomi (3) apm (2) oracle (2) agile (1) automation (1) create (1) extremeprogramming (1) hpma (1) hpomima (1) ma (1) monitoring (1) monitoringautomation (1) opr-agt (1) opr-jobs (1) plsql (1) privillege (1) programming (1) role (1) tablespace (1) user (1) xp (1)

Selasa, 07 April 2015

Oracle create table space SQL script

Oracle stores data logically in tablespaces and physically in datafiles associated with the corresponding tablespace.
Please refer to oracle documentation for more details:
http://docs.oracle.com/cd/B19306_01/server.102/b14220/physical.htm

In here I will provide the simple script with batch file to create oracle tablespace.
So it will consist of 2 portion:

  • Batch command file
  • PLSQL script 

Using both file, you'll have flexibility to create tablespace with specific parameter.

BATCH File
The first line on Batch command is sqlplus connection
sqlplus -s %1/%2@%3 @oracle_tablespace_create.sql %4 %5 %6

The Parameters: 
1) [admin_user]                = Username, with Administrative DB Privilages.
2) [admin_password]        = Password Of The Above user.
3) [conn_str]                     = DB Connection String As In Tnsnames.ora .
4) [tablespace_name]       = Tablespace name to be created.
5) [file_name]                    = Full path file name to be created.
6) [file_size]                      = File size (use M for Mb, K for Kb).


PLSQL Script

set echo on 
set feedback on 
set autoprint on 
set serveroutput on size 20000 
spool oracle_tablespace_create.log 
prompt Creating tablespace &&1 into file: &&2 with size of &&3

CREATE TABLESPACE "&&1" 
 LOGGING 
 DATAFILE 
 '&&2' SIZE &&3 
  REUSE 
   EXTENT MANAGEMENT LOCAL 
   SEGMENT SPACE MANAGEMENT AUTO 

spool off 

EXIT;

How to use?

here how to use the script to create 1 GB tablespace:
connection


oracle_tablespace_create.bat system password <conn_string> MY_TBS C:\APP\HPSWADM\ORADATA\<SID>\MY_TBS_01.DBF 1024M

Tidak ada komentar:

Posting Komentar