Professional Documents
Culture Documents
Overview
Oracle terms
Schema logical collection of users
objects
Tablespace logical space used for
storage
Datafile physical file used for
storage
Extent group of contiguous blocks
Block unit of physical storage
Oracle Architecture
database vs. instance
Database Instance
Disk Memory
MySQL
Three files per table
Permissions based on user, database, and host
Oracle
Many files
Many roles/permissions possible
The Oracle Data
Dictionary
Collection of tables and views that show the
inner workings and structure of the db
static data dictionary views
owned by SYS
created by catalog.sql script at db creation
contain DDL info
dynamic data dictionary views
also referred to as V$ views
based on virtual tables (X$ tables)
provide info about the instance
More Data Dictionary
Create table samples (
ID number(3) primary key,
Type varchar2(5),
Constraint type_ck check (type in (photo,swatch))
);
inserting apostrophes
INSERT INTO emp (name) VALUES (ONeill);
Example:
select to_char (adate, dd-mon-yy hh24:mi:ss)
TO_CHAR(ADATE, DD-MON-YY:HH24:MI:SS)
17-feb-00 23:41:50
SELECT *
FROM emp, dept
WHERE emp.deptno(+)=dept.id;
Oracle SQL functions
Upper(), lower()
Substr(), replace(), rtrim(), concat()
Length()
Floor(), sqrt(), min(), max(), stddev()
decode()
Sort of like an If/Then statement
Decode(gender,0,Male,1,Female,Unknown)
Oracle error messages
Divided into groups by first three
letters (e.g. ORA or TNS)
Number gives more information
about error
Several messages may be related
to only one problem
oerr facility
Constraints
Primary key
Foreign key
Unique, not null
Check CREATE TABLE test (
id NUMBER(2),
col2 VARCHAR2(2),
col3 VARCHAR2(3),
CONSTRAINT test_pk PRIMARY KEY(id),
CONSTRAINT col3_ck CHECK (col3 IN ('yes','no'))
);
NAME T SEARCH_CONDITION
--------------- - -------------------------
COL3_CK C col3 IN ('yes','no')
TEST_PK P
Constraints
Oracle naming of constraints is NOT
intuitive!
TRIGGER_NAME
------------------------------
AFTER_INS_UPD_ON_EMP
end;
The above trigger was created with the following statement:
1 GREEN MED
2 RED MED
3 RED SMALL
4 BLUE LARGE
Part number 1 2 3 4