0% found this document useful (0 votes)
5 views

sql

The document contains a series of SQL commands and procedures related to managing an Oracle database, including querying parameters, control files, data files, and tablespaces. It also details user account management, including password changes and unlocking accounts, as well as creating and altering tablespaces. Additionally, it includes examples of creating functions and procedures to manipulate and display table information within the database.

Uploaded by

ines.ben.jemaa12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

sql

The document contains a series of SQL commands and procedures related to managing an Oracle database, including querying parameters, control files, data files, and tablespaces. It also details user account management, including password changes and unlocking accounts, as well as creating and altering tablespaces. Additionally, it includes examples of creating functions and procedures to manipulate and display table information within the database.

Uploaded by

ines.ben.jemaa12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Enter user-name: sys/as sysdba

====================================================================

select value from v$parameter where name = 'spfile';

select 'spfile' type, value fichier


from v$parameter where name = 'spfile' ;
===================================================================================
======

select name from v$controlfile;

select 'contrôle' type, name from v$controlfile;


===================================================================================
======
select name from v$datafile;

select 'donnée' type, name from v$datafile;


===================================================================================
======
select name from v$tempfile;

select 'temporaire' type, name from v$tempfile;


===================================================================================
======
select member from v$logfile;

select 'journal' type, member from v$logfile;


===================================================================================
======

===================================================================================
======
set linesize 120
COLUMN type FORMAT A10
COLUMN fichier FORMAT A90

select type, fichier from (


select 'spfile' type, value fichier
from v$parameter where name = 'spfile' union all
select 'contrôle' type, name from v$controlfile union all
select 'donnée' type, name from v$datafile union all
select 'temporaire' type, name from v$tempfile union all
select 'journal' type, member from v$logfile );

clear column
===============================================================
select count(*) from dict ;
select username , program from V$SESSION ;

select username , type from V$SESSION ;

select sum(value)/1024/1024 from v$SGA ; taille , en mega

select account_status from dba_users where username ='HR';


alter user hr account unlock ;
Enter user-name: hr
Enter password:
ERROR:
ORA-28001: the password has expired

Changing password for hr


New password:
Retype new password:
Password changed

Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL>

5: select OBJECT_NAME , OBJECT_TYPE , CREATED, LAST_DDL_TIME from user_objects ;

6: select TABLE_NAME from ALL_tables ;


SQL> select owner , count(*) from ALL_tables
2 group by owner;

OWNER COUNT(*)
------------------------------ ----------
MDSYS 34
CTXSYS 5
HR 7
SYSTEM 4
APEX_040000 3
XDB 1
SYS 24

7 rows selected.

SQL> select owner , count(*) from ALL_tables


2 group by rollup(owner); donne somme

OWNER COUNT(*)
------------------------------ ----------
APEX_040000 3
CTXSYS 5
HR 7
MDSYS 34
SYS 24
SYSTEM 4
XDB 1
78

8 rows selected.

SQL>
7)
SQL-------------------------------------
desc user_tables;
select TABLE_NAME from user_tables ;
PL/SQL------Il va creer dans la dictionnaire de donner
-----------------------------
create or replace procedure aff_tables
is
cursor ctab is select TABLE_NAME from user_tables;
begin
for v in ctab loop
dbms_output.put_line(v.table_name);
end loop;
end;
/

execution
set serveroutput on

exec aff_tables

select text from user_source where name= 'AFF_TABLES'';

8)SQL> select count (*) from dba_tables;

COUNT(*)
----------
1687

SQL> select count (*) from all_tables;

COUNT(*)
----------
1687

SQL>
tous ce qui creer dans dictionnaire est en majuscule et sensible a la casse
9)SQL> select count (*) from all_tables where owner = 'HR';

COUNT(*)
----------
7

SQL>
10)

create or replace function fn_nb_tab_user(pnomu varchar)


return number
is
res number;
begin
select count (*) into res from all_tables where owner = upper(pnomu);
return res;
end;
/

desc fn_nb_tab_user

select fn_nb_tab_user('hr') from dual ;

begin
dbms_output.put_line(fn_nb_tab_user('hr'));
end;
/

11)
------------------
select table_name from dba_tables where owner = upper('hr');
---------------------show err

create or replace procedure aff_tables_user (pnomu varchar )


is
cursor ctab is select TABLE_NAME from dba_tables where owner = upper(pnomu);
begin
for v in ctab loop
dbms_output.put_line(ctab%rowcount || '/' || fn_nb_tab_user (pnomu) || ''||
v.table_name);
end loop;
end;
/

======================================================================

select TABLESPACE_NAME, CONTENTS, STATUS


2 from dba_tablespaces;

TABLESPACE_NAME CONTENTS STATUS


------------------------------ --------- ---------
SYSTEM PERMANENT ONLINE
SYSAUX PERMANENT ONLINE
UNDOTBS1 UNDO ONLINE
TEMP TEMPORARY ONLINE
USERS PERMANENT ONLINE
===================================
select FILE_name , tablespace_name
2 from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
TABLESPACE_NAME
------------------------------
C:\ORACLEXE\APP\ORACLE\ORADATA\XE\USERS.DBF
USERS

C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSAUX.DBF
SYSAUX

C:\ORACLEXE\APP\ORACLE\ORADATA\XE\UNDOTBS1.DBF
UNDOTBS1

FILE_NAME
--------------------------------------------------------------------------------
TABLESPACE_NAME
------------------------------
C:\ORACLEXE\APP\ORACLE\ORADATA\XE\SYSTEM.DBF
SYSTEM
==========================================================================
SQL> select FILE_name , tablespace_name
2 from dba_temp_files;

FILE_NAME
--------------------------------------------------------------------------------
TABLESPACE_NAME
------------------------------
C:\ORACLEXE\APP\ORACLE\ORADATA\XE\TEMP.DBF
TEMP
======================================================
create tablespace tbl01
datafile
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd01tbl01.dbf' size 6M,
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd02tbl01.dbf' size 4M

=======
select TABLESPACE_NAME, CONTENTS, STATUS
from dba_tablespaces
========
select file_NAME from dba_data_files
where tablespace_name = 'TBL01';
=============
select property_name, property_value
from database_properties
where property_name like '%TABLESPACE%' ;

PROPERTY_NAME
------------------------------
PROPERTY_VALUE
--------------------------------------------------------------------------------
DEFAULT_TEMP_TABLESPACE
TEMP

DEFAULT_PERMANENT_TABLESPACE
SYSTEM
================================================================================

alter database default tablespace tbl01;

Database altered. (modifier)


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

PROPERTY_NAME
------------------------------
PROPERTY_VALUE
--------------------------------------------------------------------------------
DEFAULT_TEMP_TABLESPACE
TEMP

DEFAULT_PERMANENT_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
;

=======

select file_NAME from dba_data_files


where tablespace_name = 'TBL02';

4)

alter tablespace tbl01


add datafile
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd03tbl01.dbf' size 20M
;
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;

select file_NAME from dba_data_files


where tablespace_name = 'TBL02';

4)
alter tablespace tbl01
add datafile
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd03tbl01.dbf' size 20M,

5)
-- Étape 1 : Mettre le tablespace hors ligne
ALTER TABLESPACE tbl02 OFFLINE;

host copy C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd0xtbl02.dbf C:\ORACLEXE\APP\ORACLE\


ORADATA\XE\fd03tbl02.dbf

-- Étape 2 : Copier le fichier de données


cp /oracle/data/scott_data_01.dbf /oracle/TSTTIORA/scott_data01.dbf

-- Étape 3 : Renommer le fichier de données dans Oracle


ALTER TABLESPACE tbl02
RENAME DATAFILE 'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd0xtbl02.dbf'
TO 'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd03tbl02.dbf';

-- Étape 4 : Remettre le tablespace en ligne


ALTER TABLESPACE tbl02 ONLINE;

pour verifier : select file_NAME from dba_data_files


where tablespace_name = 'TBL02'; ( tbadel c bon)

7)
declare
cursor c is
select A.tablespace_name , contents, NB_F
from
(select tablespace_name ,count(*) NB_F
from dba_data_files
group by tablespace_name
union
select tablespace_name ,count(*) NB_F
from dba_temp_files
group by tablespace_name) A,
dba_tablespaces B
where A.tablespace_name = B.tablespace_name;

begin
for vc in c loop

dbms_output.put_line(rpad(vc.tablespace_name,15 )||rpad( vc.contents,12 ) ||


vc.NB_f);
end loop;
end;
/

8) alter tablespace tbl02


add datafile
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\fd04tbl02.dbf' size 2M
autoextend on next 1M maxsize 4M

9)
create temporary tablespace montemp5
tempfile
'C:\ORACLEXE\APP\ORACLE\ORADATA\XE\FT1MONTEMPS.DBF' size 5M;

(pour afficher les chemins : select file name from dba_datafile)

alter database default temporary tablespace montemp5;

select property_name, property_value


from database_properties
where property_name like '%TABLESPACE%';

10) select count(*) from dba_tablespaces where contents = 'PERMANENT';


n3awthouha b :

create or replace function fn_nb_tb1 (ptype number)


return number
is
res number;
begin
if ptype not in (1,2,3) then return -1;
elsif ptype = 1 then select count(*) into res from dba_tablespaces
where contents = 'PERMANENT' ;

elsif ptype = 2 then select count(*) into res from dba_tablespaces


where contents = 'UNDO' ;

elsif ptype = 3 then select count(*) into res from dba_tablespaces


where contents = 'TEMPORARY' ;
end if;
return res;
end;
/

select fn_nb_tb1 (3) from dual


2

11)
create user td3 identified by td3;

select default_tablespace, temporary_tablespace


from dba_users where username = 'TD3';

12)

alter database default tablespace tbl02; (lezmna nbadlou khatr par defaut)
drop tablespace tbl02;

13)

set serveroutput on
exec PS_DETAILS_TAB

select A.tablespace_name , contents, NB_F


from
(select tablespace_name ,count(*) NB_F
from dba_data_files
group by tablespace_name
union
select tablespace_name ,count(*) NB_F
from dba_temp_files
group by tablespace_name) A,
dba_tablespaces B
where A.tablespace_name = B.tablespace_name;

TP3

EX 2

4)
create role ROLE_MANIP_TAB_TP32;
grant select , insert on etablissement to ROLE_MANIP_TAB_TP32;

grant create session TO ROLE_TP32 with admin option;

grant create session TO ROLE_MANIP_TAB_TP32 ;


select *

You might also like