You are on page 1of 72

Introduction to the Oracle DBMS

Kristian Torp
Department of Computer Science
Aalborg University
www.cs.aau.dk/torp
torp@cs.aau.dk
December 2, 2011
daisy.aau.dk
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 1 / 72
Outline
1
Users
2
The Data Dictionary
3
General Stuff
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 2 / 72
Learning Goals
Prerequisites
Knowledge about basic database concepts, e.g., table and index
Basic knowledge of SQL
Learning Goals
Use the Oracle DBMS
Know where Oracle different from standard or other DBMSs
Know how to nd database metadata
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 3 / 72
Outline
1
Users
2
The Data Dictionary
3
General Stuff
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 4 / 72
Disclaimer
For Testing Only!
Examples in the following are only for test machines!
Should not be used in a production environment!
For Production
Contact your local DBA
Read the manual on how to make a secure environment
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 5 / 72
Overview
Supplied Users
SYS, the root user of the Oracle DBMS
SYSTEM, has database administration rights
Note
It is a good idea to create a separate user for your database
How to create users is different on different DBMSs
There are nice GUI tools for creating users
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 6 / 72
New DBA User
User Requirements
Create a new super user on the Oracle DBMS
The new user must not be one of the supplied users.
Example (Create a Super User)
l ogi n as system ( pr edef i ned super user )
sql pl us system@<system i d e n t i f i e r >
Creat e a new super user , make ni cer password
cr eat e user dbadm i d e n t i f i e d by dbadm;
gr ant r i ght s
gr ant dba t o dbadm;
l ogout
e x i t ;
l ogi n as new dba
sql pl us dbadm/ dbadm@<system i d e n t i f i e r >
Now change your password
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 7 / 72
New User
User Requirements
Create a new user on the Oracle DBMS no administration rights
Should be able to create tables and query them
Example (Create a Super User)
l ogi n as system
sql pl us dbadm@<system i d e n t i f i e r >
Creat e a new user
cr eat e user dbuser i d e n t i f i e d by dbuser ;
gr ant r i ght s t o new user
gr ant connect , r esour ce t o dbuser ;
connect as new user
connect dbuser / dbuser
Now change your password
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 8 / 72
Drop Users
Example (Drop New Super User and Plain Users)
l ogi n as system
sql pl us system@<system i d e n t i f i e r >
drop t he users cr eat ed above
drop user dbuser ;
Note
All schema object owned by the dropped users are also dropped!
You cannot drop the user currently used
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 9 / 72
Outline
1
Users
2
The Data Dictionary
3
General Stuff
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 10 / 72
Overview of Data Dictionary
The idea in the naming
Name Description
all [rest of name] All the stuff that the current user can see
dba [rest of name] All the stuff in the database
user [rest of name] All the stuff that the current user owns
user all dba
Access Rights
It is possible that you do not have access to the dba views.
Example (Info. on Indexes)
sel ect
from al l i ndexes
Example (Info. on Views)
sel ect
from user vi ews
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 11 / 72
What Stuff is in the DBMS
Example (Objects users have in the database)
sel ect ao . owner , ao . obj ect t ype , count ( ) as cnt
from a l l o b j e c t s ao
group by ao . owner , ao . obj ect t ype
or der by cnt desc
Note
The all objects lists all objects stored in the database
The object type is, e.g., tables, indexes, java classes, and synonyms
Example (Object Types)
sel ect d i s t i n c t obj ect t ype
from a l l o b j e c t s
Result
OBJECT TYPE
TABLE
INDEX
SYNONYM
..
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 12 / 72
Outline
1
Users
2
The Data Dictionary
3
General Stuff
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 13 / 72
The Unix ls command
Example (Show me the stuff)
sel ect
from cat ;
Note
cat is short for catalog
A view with two columns table name and table type
Contains tables, views, sequences (but not itself!)
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 14 / 72
Limiting the Number of Rows Returned
Example (Give me the rst ten rows)
sel ect
from cat
where rownum <= 10
Note
The rownum pseudo column is Oracle specic on other DBMSs it is
called limit
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 15 / 72
Outline
4
Tables
5
Columns
6
Constraints
7
Views
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 16 / 72
Available Tables
Example (Look at all my tables)
sel ect
from user t abl es ;
Example (Look at all tables available to me)
sel ect
from a l l t a b l e s ;
Example (Find tables that are non-local)
sel ect
from a l l t a b l e s
except
sel ect
from user t abl es ;
Note
Not union compatible!
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 17 / 72
The dual Table
Example (Find the current time)
sel ect cur r ent t i mest amp
from dual
Note
A utility table in Oracle because the from clause is required
Has one column dummy
Has one row (with the value X)
Uses the built-in function current timestamp

Cultural format, e.g., 2012-02-28 12:34:56 vs. 02-28-2012 12:34:56


Uses the dual table
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 18 / 72
Space Consumption I
Example (How much space are my tables taking up?)
sel ect us . segment name as t abl e name ,
byt es /1024 as KB
from user segments us
where us . segment t ype = TABLE
or der by KB desc ;
Note
Note the word TABLE has to be in upper case
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 19 / 72
Space Consumption II
Example (How much space are my tables taking up (take two)?)
Another way to calculate size http://askanantha.blogspot.com/
2007/09/get-oracle-table-size.html
sel ect segment name as tabl e name ,
sum( byt es ) / ( 1024) as t abl e si ze kb
from user ext ent s
where segment t ype = TABLE
group by segment name ;
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 20 / 72
Space Consumption III
Example (How much space are my tables taking up (take three)?)
Size of table based on rows http://askanantha.blogspot.com/
2007/09/get-oracle-table-size.html
sel ect tabl e name , ( avg r ow l ennum rows ) / ( 1024)
from user t abl es ;
Example (Show more information on table size calculation)
sel ect tabl e name ,
avg r ow l en ,
num rows ,
( avg r ow l ennum rows ) / ( 1024) si ze kb
from user t abl es ;
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 21 / 72
Create a SQL Script to drop all Tables I
Example (Drop Single Table)
drop t abl e t ab ;
Note
Time consuming when many tables
Example (A script that drops all table)
sel ect drop t abl e | | ua . t abl e name | | ;
from user t abl es ua ;
Note
|| is the string concatenation operator in Oracle

hello, || world! = hello, world!


Recall keywords case insensitive in SQL
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 22 / 72
Create a SQL Script to drop all Tables II
User Requirements
All names in lower case in scripts
Example (A script that drops all tables (all lower case))
sel ect drop t abl e | | l ower ( ua . t abl e name ) | | ;
from user t abl es ua ;
Note
The function lower converts a character string to lower case
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 23 / 72
Create a SQL Script to drop all Tables III
Example (Store the drop script in a le)
set headi ng o f f do not show t he column names
set feedback o f f do not wr i t e n rows r et ur ned at t he end
set pagesi ze 50000 make t he page si ze ver y l ar ge
send out put t o a f i l e
spool c : \ dr op t abl es . sql
The act ual query t o execut e
sel ect drop t abl e | | l ower ( ua . t abl e name ) | | ;
from user t abl es ua ;
spool o f f st op wr i t i ng t o a f i l e
Example (Execute the commands in the le from within SQLPlus)
SQL>@c: \ dr op t abl es . sql
Note
Assume le is stored in c: drop les.sql
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 24 / 72
Outline
4
Tables
5
Columns
6
Constraints
7
Views
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 25 / 72
Columns for a Table
Example (The columns on the student table)
sel ect
from user t ab col s ut c
where ut c . t abl e name = STUDENT
Note
Internally all identiers are in upper case
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 26 / 72
Finding Specic Columns Based on Name
Example (Columns names that include the string ID)
sel ect ut c .
from user t ab col s ut c
where ut c . column name l i k e %ID%
Note
likeis simple string matching and % is multi-character wildcard
Recall that internally in Oracle all identiers are in upper case
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 27 / 72
Space Consumption Column Values
Example (Find the number of bytes needed to store a date)
sel ect vsi ze ( dat e )
from dual ;
Example (Find the number of bytes needed to store an interval)
sel ect vsi ze ( i n t e r v a l 37 12 day t o hour )
from dual ;
Example (Find the number of bytes needed to store a oat)
sel ect vsi ze (123456789012345.34567890)
from dual ;
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 28 / 72
Data Types for Columns
Example (Find the most used data type for columns)
sel ect ut c . dat a t ype , count ( ) as no col s
from user t ab col s ut c
group by ut c . dat a t ype
or der by no col s desc
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 29 / 72
Outline
4
Tables
5
Columns
6
Constraints
7
Views
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 30 / 72
Finding Primary Keys
Example (Name of tables that have a primary key)
sel ect uc . t abl e name
from user const r ai nt s uc
where uc . c ons t r ai nt t y pe = P
Constraint Types
Constraint Type Description
P Primary key
R Referential Integrity (foreign key)
C Check constraint
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 31 / 72
Missing Primary Keys
Example (Tables with no primary key)
sel ect t abl e name
from user t abl es
where t abl e name not i n ( sel ect t abl e name
from user const r ai nt s
where c ons t r ai nt t y pe = P ) ;
Action to Take
Now you should add the missing primary keys or face the consequences!
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 32 / 72
Constraints on Which Columns
Example (Columns associated with a constraint)
sel ect
from user cons col umns ucc
where ucc . t abl e name = STUDENT
Note
Only for the Student table
All types of constraints are used
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 33 / 72
Composite Primary Keys
Example (Find tables with a composite primary key)
sel ect uc . tabl e name , count ( ucc . column name )
from user cons col umns ucc , user const r ai nt s uc
where uc . c ons t r ai nt t y pe = P pr i mar y key
and uc . owner = ucc . owner
and uc . const r ai nt name = ucc . const r ai nt name
group by uc . t abl e name
havi ng count ( ucc . column name ) > 1
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 34 / 72
Outline
4
Tables
5
Columns
6
Constraints
7
Views
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 35 / 72
Which Views are Dened
Example (Show all views)
sel ect
from user vi ews
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 36 / 72
View Implementation
Example (The select statements used for creating the view)
sel ect uv . t ex t
from user vi ews uv
Note
The text is a long column (an old type of clob) therefore the text may not
be directly visible. Click on the eld to see the content in most IDEs.
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 37 / 72
Outline
8
Sequences
9
Directories and Files
10
Synonyms
11
Comments
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 38 / 72
Which Sequences are Available
Example (Find all sequences)
sel ect
from user sequences
Example (Find the last number used from the sequence)
sel ect us . l ast number
from user sequences us
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 39 / 72
Outline
8
Sequences
9
Directories and Files
10
Synonyms
11
Comments
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 40 / 72
Examples
Example (Create a Directory Alias)
cr eat e di r ec t or y f i l e s t u f f as c : \ tmp ;
Note
Directory alias le stuff is stored and used in upper case FILE STUFF
Directory name is case sensitive
No warning if directory does not exists on server side
Example (Create a Stupid Directory Alias)
cr eat e di r ec t or y dummy as c : \ DoesNot Exi st ;
Note
Create a directory alias to a non-existing directory
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 41 / 72
Overview: Directories
Idea
An alias for a directory on the server le system
Can be used to read from and write to les
Must have the create any directory to create directories
Directory aliases can be use for external tables
If the directory is drop in the operating system, a run-time error is
raised if alias is used.
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 42 / 72
List Directory Aliases
Example
sel ect
from a l l d i r e c t o r i e s ;
Note
Describes all directories aliases accessible to the current user
View is in the sys schema
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 43 / 72
Grant
Example (Grant Read/Write Access)
gr ant read , wr i t e on di r ec t or y f i l e s t u f f t o <user name>;
Note
Provides both read and write rights the directory alias
Example (Grant Read-Only Access)
gr ant read on di r ec t or y f i l e s t u f f t o <user name>;
Note
Provides only read rights the directory alias
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 44 / 72
Write A String to A File
cr eat e or r epl ace procedure s t r 2 f i l e ( di r name varchar2 ,
f i l e name varchar2 ,
s t r var char 2 )
as
v f i l e u t l f i l e . f i l e t y p e ;
begi n
v f i l e : = u t l f i l e . fopen ( di r name , f i l e name , w ) ;
u t l f i l e . put l i ne ( v f i l e , s t r ) ;
u t l f i l e . f cl ose ( v f i l e ) ;
except i on
when ot her s t hen
i f u t l f i l e . i s open ( v f i l e ) t hen
u t l f i l e . f cl ose ( v f i l e ) ;
end i f ;
end ;
Example (Called the Stored Procedure)
execut e s t r 2 f i l e ( FILE STUFF , new f i l e . t x t , Hel l o Fi l e ! ) ;
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 45 / 72
Convert a Text le to a clob I
cr eat e or r epl ace f unct i on f i l e 2 c l o b ( di r name varchar2 ,
f i l e name var char 2 )
r et ur n cl ob i s
v f i l e u t l f i l e . f i l e t y p e ; v cl ob cl ob ;
v l i n e var char 2 ( 2000) ; v l engt h i n t ;
begi n
dbms l ob . cr eat et empor ar y ( v cl ob , f al se ) ;
v f i l e : = u t l f i l e . fopen ( di r name , f i l e name , r ) ;
begi n
l oop
u t l f i l e . get l i ne ( v f i l e , v l i n e ) ;
v l engt h : = dbms l ob . get l engt h ( v cl ob ) + 1;
dbms l ob . wr i t e ( v cl ob , l engt h ( v l i n e ) , v l engt h , v l i n e ) ;
end l oop ;
except i on when ot her s t hen
i f u t l f i l e . i s open ( v f i l e ) t hen
u t l f i l e . f cl ose ( v f i l e ) ;
end i f ;
end ;
r et ur n v cl ob ;
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 46 / 72
Convert a Text le to a clob II
Example (Use the Clob Conversion)
Creat e a t abl e wi t h a cl ob column
cr eat e t abl e wi t hACl ob ( i i nt , l cl ob ) ;
Use t he new f unct i on t o l oad a f i l e i nt o a cl ob columkn
i ns er t i nt o wi t hACl ob
val ues ( 1 , f i l e 2 c l o b ( FILE STUFF , t e s t r e a d f i l e . t x t ) ) ;
commit ;
Check f i l e i s upl oaded as a cl ob
sel ect
from wi t hACl ob ;
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 47 / 72
Updating/Moving a Directory
Example (Relocate Directory Alias)
cr eat e or r epl ace di r ec t or y f i l e s t u f f as c : \ tmp\ d b f i l e s ;
Note
The directory alias has now been relocated
Example (Stupid Relocation)
cr eat e or r epl ace di r ec t or y f i l e s t u f f as / uni x / pat h / dos / machine ;
Note
No warning/error when creating non-existing directory
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 48 / 72
Dropping
Example (Drop a Directory)
drop di r ec t or y f i l e s t u f f ;
Note
The directory alias is now removed
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 49 / 72
Outline
8
Sequences
9
Directories and Files
10
Synonyms
11
Comments
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 50 / 72
Introduction
Concept
A synonym is an alias, such that it is simpler to refer to database
objects own by another user.
Example (List all non-public synonyms)
sel ect
from al l synonyms al s
where al s . owner <> PUBLIC ;
Note
A public synonym is visible to all database users
Public synonyms are used heavily by the Oracle DBMS to provide
access to meta data.
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 51 / 72
Synonyms for Tables
Example
Find the synonym name plus the base table for a public synonym that
is a table and starts with a D
sel ect al s . synonym name , al s . t abl e owner , al s . t abl e name
from al l synonyms al s
where al s . owner = PUBLIC
and al s . synonym name l i k e D%
and exi st s ( sel ect x
from a l l t a b l e s a t t
where a t t . owner = al s . t abl e owner
and a t t . t abl e name = al s . t abl e name ) ;
Note
The dual is return. This means that dual is real table and not a view.
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 52 / 72
Outline
8
Sequences
9
Directories and Files
10
Synonyms
11
Comments
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 53 / 72
Comments on Tables
Example (Find all tables with comments)
sel ect ut c .
from user t ab comment s ut c
where ut c . comments i s not n u l l
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 54 / 72
Column Comments
Example (Find column comments on the Student table)
sel ect ucc . column name , ucc . comments
from user col comment s ucc
where ucc . t abl e name = STUDENT
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 55 / 72
Outline
12
Stored Procedures
13
Triggers
14
Timing
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 56 / 72
The Unix ls command I
Example (Create the ls command as a stored procedure)
cr eat e or r epl ace procedure l s i s
cur sor c t abl es i s
sel ect from cat ;
v t abl e name cat . t abl e name%t ype ;
v t ype cat . t abl e t ype%t ype ;
begi n
open c t abl es ;
l oop
f et ch c t abl es i nt o v t abl e name , v t ype ;
e x i t when c t abl es%not f ound ;
p( v t abl e name ) ;
end l oop ;
cl ose c t abl es ;
end ;
/
Note
The slash / at the end
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 57 / 72
The Unix ls command II
Example (Executed the stored procedure)
t o enabl e out put from t he ser ver
set ser ver out put on
exec i s shor t f or execut e
exec l s ;
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 58 / 72
Space Usage Function I
User Requirements
Create a stored procedure that returns the space usage for a table
Must take the table name as input and return the size in KB
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 59 / 72
Space Usage Function II
Example
cr eat e or r epl ace f unct i on space usage
( p t abl e name i n user t abl es . t abl e name%t ype )
r et ur n number i s
v si ze kb number ;
begi n
sel ect ( ut . avg r ow l en ut . num rows ) / ( 1024)
i nt o v si ze kb
from user t abl es ut
where ut . t abl e name = upper ( p t abl e name ) ;
r et ur n v si ze kb ;
end ;
/
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 60 / 72
Space Usage Function III
Note
The into keyword
The upper keyword
The return keyword
It is very important that parameter names, e.g., p table name are
different from any colum name

The code convention is to prex all parameter names with p


There is no error handling here at all

Should be added in a production version


Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 61 / 72
Space Usage Function IV
Example (Executed the function)
t o enabl e out put from t he ser ver
set ser ver out put on
decl ar e
v r v number ;
begi n
v r v : = space usage ( st udent ) ;
dbms out put . put l i ne ( Si ze st udent t abl e i s | | v r v | | KB ) ;
end ;
/
Note
Note allowed to use lower case table names, e.g., student
The return value has to be dened
The return is printed to the screen
The trailing slash
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 62 / 72
See the Source Code
Example (Show source code for the ls stored procedure )
sel ect us . t ex t
from user sour ce us
where us . name = LS
or der by us . l i n e
Note
The text comes out in the corrected order due to the order by clause
Note the bad name convention there is a column name name. This
names overlaps with a reserved word
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 63 / 72
Reserved Words in PL/SQL
Reserved Words
There is a huge number of reserved words in PL/SQL.
They can (naturally) be queried
Example (List the Reserved Words)
sel ect
from v$reserved words
Note
All v$ views are also called dynamic views
Access Rights
It is possible that you do not have access to the view v$reserved words
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 64 / 72
Outline
12
Stored Procedures
13
Triggers
14
Timing
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 65 / 72
Introduction
Example (List all tables with triggers)
sel ect d i s t i n c t ut . t abl e name
from us er t r i gger s ut
where ut . base obj ect t ype = TABLE
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 66 / 72
Outline
12
Stored Procedures
13
Triggers
14
Timing
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 67 / 72
Timing a Query
Example (From SQLPlus)
set headi ng o f f
set pagesi ze 50000
set t er mout o f f
spool c : \ t es t . l s t
t i mi ng s t a r t
St ar t query t o t i me
sel ect c . car i d , c . r oad i d , c . speed
from car gps ar r ay c
or der by c ar i d desc ;
Stop query t o t i me
t i mi ng st op
spool o f f
set t er mout on
Note
Output is spooled to a le
The result of the query is not displayed on screen
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 68 / 72
Outline
15
Tablespace Usage
16
Additional Information
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 69 / 72
Space Usage
Example (Space consumption for tablespaces)
sel ect segment name , tabl espace name , sum( byt es / ( 10241024) ) MB
from dba segments
where owner= TORP and segment name not l i k e BIN
group by segment name , tabl espace name
or der by segment name , tabl espace name ;
Note
Dropped tablespaces are not included
Dropped database objects are in the BIN segment
The size is in MB
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 70 / 72
Outline
15
Tablespace Usage
16
Additional Information
Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 71 / 72
Web Sites
Sites
Oracle technical network otn.oracle.com

The ofcial homepage good information but no critique


Morgans Library www.psoug.org/library.html

Many concrete examples, little or no explanation


dbazine.coms Oracle home page www.dbazine.com/oracle

Good examples
dbasupport.coms www.dbasupport.com/oracle/

Overall good site with informaton on several DBMSs


Kristian Torp (Aalborg University) Introduction to the Oracle DBMS December 2, 2011 72 / 72

You might also like