Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

conn sys/as sysdba

select count(*) from dba_tablespaces ;


desc v$tablespace
desc dba_tablespaces
select file_name from dba_data_files;

1/create tablespace tbl01


datafile
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd01tbl01.dbf' size 6M,
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd02tbl01.dbf' size 4M;

2/ select property_name, property_value


from database_properties
where property_name like '%TABLESPACE%';

alter database default tablespace tbl01;

3/create tablespace tbl02


datafile
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd01tbl02.dbf' size 10M,
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd02tbl02.dbf' size 10M,
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd0xtbl02.dbf' size 5M;

4/alter tablespace tbl01


add datafile 'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd03tbl01.dbf' size 20M;

select file_name from dba_data_files


where tablespace_name = 'TBL01';

5/
select file_name from dba_data_files
where tablespace_name = 'TBL02';

alter tablespace tbl02 offline ;


sql> host copy C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd0xtbl02.dbf
C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd03tbl02.dbf;

alter tablespace tbl02


rename datafile
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd0xtbl02.dbf'
to
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd03tbl02.dbf';

alter tablespace tbl02 online ;

6/ select tablespace_name from dba_tablespaces;


select tablespace_name,contents from dba_tablespaces;

7/ select tablespace_name, count(*) from dba_data_files group by tablespace_name;


select tablespace_name, count(*) from dba_temp_files group by tablespace_name;
select tablespace_name, count(*) from dba_temp_files group by tablespace_name union
select tablespace_name, count(*) from dba_data_files group by tablespace_name;

with req as
2 (SELECT tablespace_name, COUNT(*) NB
3 FROM dba_temp_files
4 GROUP BY tablespace_name
5 union
6 SELECT tablespace_name, COUNT(*) NB
7 FROM dba_data_files
8 GROUP BY tablespace_name)
9 select req.tablespace_name,contents,NB from req, dba_tablespaces a
10 where req.tablespace_name = a.tablespace_name;

select tablespace_name, (select contents from dba_tablespaces


where tablespace_name = a.tablespace_name ) contents,
count(*) NB
from dba_data_files a
group by tablespace_name
union
select tablespace_name, (select contents from dba_tablespaces
where tablespace_name = a.tablespace_name) contents,
count(*) NB
from dba_temp_files a
group by tablespace_name;

8/ alter tablespace tbl02 add datafile 'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\


FD03TBL02.DBF' size 2M autoextend on next 1M maxsize 4M;

select file_name from dba_data_files where tablespace_name = 'TBL02';

9/
SQL> select property_name, property_value
2 from database_properties
3 where property_name like '%TABLESPACE%';

SQL> alter database default temporary tablespace montemp;

Database altered.

SQL> select property_name, property_value


2 from database_properties
3 where property_name like '%TABLESPACE%';

SQL> alter database default tablespace tbl02;

Database altered.

SQL> select property_name, property_value


2 from database_properties
3 where property_name like '%TABLESPACE%';

10/

show user
USER is "SYSTEM"
SQL> connect sys/as sysdba
Enter password:
Connected.
SQL> /

Function created.

SQL> create or replace function fn_nb_tbl (Ptype number)


2 return number
3 is
4 res number;
5 begin
6 if Ptype = 1 then
7 select count(*) into res from dba_tablespaces where contents = 'PERMANENT';
8 elsif Ptype = 2 then
9 select count(*) into res from dba_tablespaces where contents = 'TEMPORARY';
10 elsif Ptype = 3 then
11 select count(*) into res from dba_tablespaces where contents = 'UNDO';
12 else
13 res := -1 ;
14 end if;
15 return res;
16 end;
17 /

11/

select fn_nb_tbl(3) from dual;

SQL> create user td3 identified by td3 default tablespace tbl02;

User created.

SQL> select default_tablespace, temporary_tablespace from dba_users where username


= 'TD3';

12/
drop tablespace tbl02; => non

alter database default tablespace tbl02 ;


drop tablespace tbl01; => oui

13/

You might also like