4.16.24 21st Century Movements for Black Lives.pptx
Â
Oracle 9i notes(kamal.love@gmail.com)
1. Oracle 9i is fully SQL:1999 join compliant.
CROSS JOIN (Cartesian Product).
SELECT
E.ENAME, D.DNAME
FROM
EMP E CROSS JOIN DEPT D;
NATURAL JOIN (Equijoin on All Identically Named Columns).
SELECT
E.ENAME, D.DNAME
FROM
EMP E NATURAL JOIN DEPT D;
USING clause (Similar to a Natural Join, but allows for the designation of which
column(s) to use in the equijoin).
SELECT
E.ENAME, D.DNAME
FROM
EMP E JOIN DEPT D USING (DEPTNO);
ON clause (Used to define columns to join on)
SELECT
E.ENAME, D.DNAME
FROM
EMP E JOIN DEPT D ON (E.DEPTNO = D.DEPTNO);
LEFT OUTER JOIN (All records from first table with matching rows from second)
SELECT
E.ENAME, D.DNAME
FROM
EMP E LEFT OUTER JOIN DEPT D ON (E.DEPTNO = D.DEPTNO);
RIGHT OUTER JOIN (All records from second table with matching rows from first)
SELECT
E.ENAME, D.DNAME
FROM
EMP E RIGHT OUTER JOIN DEPT D ON (E.DEPTNO = D.DEPTNO);
FULL OUTER JOIN (All records from both tablesâIdentical to a union of left outer
join and right outer join)
SELECT
E.ENAME, D.DNAME
FROM
EMP E FULL OUTER JOIN DEPT D ON (E.DEPTNO = D.DEPTNO);
Keyword OUTER is optional with RIGHT,LEFT or FULL.
--------------------------------------------------------------------------------
--
Oracle 9i has also introduced several new functions:
2. NULLIF(expr1, expr2) âReturns NULL if the first argument is equal to the second,
otherwise returns the first argument.
COALESCE(expr1, expr2, expr3, ...) âReturns the first non-null argument.
CASE Statement
SELECT ENAME, EXTRACT(YEAR FROM HIREDATE) AS YEAR_OF_HIRE,
(CASE EXTRACT(YEAR FROM HIREDATE)
WHEN 2002 THEN 'NEW HIRE'
WHEN 1997 THEN 'FIVE YEARS SERVICE'
WHEN 1992 THEN 'TEN YEARS SERVICE'
ELSE 'NO AWARD THIS YEAR'
END ) AS AWARD
FROM EMP;
CASE Expression
SELECT ENAME, SAL,
(CASE
WHEN JOB = âDBAâ THEN SAL * 1.5
WHEN HIREDATE < SYSDATE - TO_YMINTERVAL(â05-00â) THEN SAL * 1.25
WHEN DEPTNO IN (40,30,10) THEN SAL * 1.1
ELSE SAL * .9
END ) AS NEW_SAL
FROM EMP;
Explicit Defaults âOracle 9i now allows for the keyword DEFAULT to be used in
INSERT or UPDATE statements:
INSERT INTO EMP (EMPNO, ENAME, DEPTNO)
VALUES (8000,âMIKEâ,DEFAULT);
UPDATE EMP SET COMM = DEFAULT;
MERGE Statement. âThis excellent feature also known as an UPSERT will either do
an insert or an update depending on the existence of the record in the target
table.
MERGE INTO T1
USING T2 ON (T1.C9=T2.C9)
WHEN MATCHED THEN UPDATE SET T1.C1=T2.C2, T1.C2=T2.C2 ...
WHEN NOT MATCHED THEN INSERT (C1,C2, ...) VALUES (C1,C2, ...);
Multiple Table Inserts Statement. âAllows for insertion into multiple tables as
part of a single DML statement.
UNCONDITIONAL
INSERT ALL
INTO T1 (C1, C2, ...) VALUES (C1, C2, ...)
INTO T2 (C1, C2, ...) VALUES (C1, C2, ...)
...
SELECT C1, C2, ... FROM T9;
CONDITIONAL âFIRST will only insert into the first statement that returns true,
ALL will insert into each statement that returns true.
3. INSERT [ALL|FIRST]
WHEN c1 = 1 THEN INTO T1 (C1, C2, ...) VALUES (C1, C2, ...)
WHEN c1 = 2 THEN INTO T2 (C1, C2, ...) VALUES (C1, C2, ...)
WHEN c2 = 3 THEN INTO T3 (C1, C2, ...) VALUES (C1, C2, ...)
...
SELECT C1, C2, ... FROM T9;
We also have several new conversion functions:
TO_TIMESTAMP âFrom String to Timestamp.
TO_TIMESTAMP_TZ âFrom String to Timestamp with Time Zone.
TO_DSINTERVAL âFrom String to Interval Day to Second.
TO_YMINTERVAL âFrom String to Interval Year to Month
TO_CHAR âExtended to accept the new format characters.
EXTRACT âReturns the requested value (as a number) from a datetime or interval
datatype. Options are Year, Month, Day, Hour, Minute, Second, Timezone_Hour,
Timezone_Minute, Timezone_Region, or Timezone_ABBR.
SELECT EXTRACT(YEAR FROM SYSDATE) FROM DUAL;
DBMS_METADATA is a package that allows for object DDL to be retrieved from the
database.
This package will work for tables, indexes, views, packages, functions,
procedures, triggers, synonyms, and types.
DBMS_METADATA has functions for casual use:
DBMS_METADATA.GET_DDL(object_type, name, schema)
DBMS_METADATA.GET_XML(object_type, name, schema)
--
SELECT DBMS_METADATA.GET_DDL(âTABLEâ, âEMPâ, âSCOTTâ) from dual;
CREATE TABLE "SCOTT"."EMP"
( "EMPNO" NUMBER(4,0),
"ENAME" VARCHAR2(10),
"JOB" VARCHAR2(9),
"MGR" NUMBER(4,0),
"HIREDATE" DATE,
"SAL" NUMBER(7,2),
"COMM" NUMBER(7,2),
"DEPTNO" NUMBER(2,0),
CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0
FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" ENABLE,
CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE NOVALIDATE
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0
FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS"
--
External tables are flat files stored outside of the database that Oracle treats
as a table.
4. The data is read-only and no indexes can be created.
Object rights are controlled through âSELECT TABLEâ and âREAD DIRECTORYâ
privileges.
UTL_FILE_DIR must be set appropriately.
CREATE DIRECTORY external_tables AS âc:oracleoradataexternalâ;
CREATE TABLE EMP_EXT (EMPNO NUMBER(4,0), ENAME VARCHAR2(10), JOB VARCHAR2(9),
MGR NUMBER(4,0), HIREDATE DATE, SAL NUMBER(7,2), COMM NUMBER(7,2), DEPTNO
NUMBER(2,0))
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY external_tables
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE
BADFILE external_tables:âbad_emp_ext.txtâ
LOGFILE external_tables:âlog_emp_ext.txtâ
FIELDS TERMINATED BY â,â
MISSING FIELD VALUES ARE NULL)
LOCATION (âemp.txtâ))
REJECT LIMIT UNLIMITED
--
Once the table metadata has been created (as in the previous slide) , then this
table can be queried just like any other table. This includes functions, joins,
etc.
Two new views help in the administration of these external tables:
DBA_EXTERNAL_TABLES lists the attributes of each external table in the database.
DBA_EXTERNAL_LOCATIONS lists the specific flat files and their associated
directories.
--
Flashback Query allows users to see a consistent view of the database at a point
in time in the past.
This view of the data is read-only.
This view of the data is re-created by undo and is only available if the undo
blocks are still available.
PL/SQL cursors opened in flashback mode are available for DML after flashback
mode is disabled.
Flashback Query is also supported by EXP.
--
EXEC DBMS_FLASHBACK.ENABLE_AT_TIME(
TO_DATE(â03-20-2002 14:00:00â,âMM-DD-YYYY HH24:MI:SSâ));
Oracle uses a new table, SMON_SCN_TIME to translate timestamps to SCNs.
Documentation states that it only tracks the last five days and is only in five
minute increments.
SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL;
5. This is a excellent new feature for capturing the current SCN.
EXEC DBMS_FLASHBACK.DISABLE;
--
Automatic Undo Management
UNDO_MANAGEMENT (MANUAL or AUTO)
Specifies whether or not to use AUM. Default = MANUAL
UNDO_TABLESPACE (valid tablespace)
Specifies which undo tablespace to use.
UNDO_RETENTION (in seconds default=30)
Specifies how long to keep committed undo.
UNDO_SUPPRESS_ERRORS (TRUE or FALSE)
Specifies whether or not to return an exception when âSET TRANSACTION USE
ROLLBACK SEGMENTâ is issued. Default = TRUE
--
DBA_ROLLBACK_SEGS, V$TRANSACTION, V$ROLLSTAT, are V$ROLLNAME are still
available.
DBA_UNDO_EXTENTS shows when each extent in the undo tablespace was committed.
#
V$UNDOSTAT shows the undo usage for the last 24 hours. Each row records a ten
minute interval defined by START_TIME and END_TIME. The key field is
UNDO_BLOCKS.
--
Things You Can Do With Online Redefinition
Move a table or index to a new tablespace
Change a tableâs organization (partitioning, index-organized, etc.)
Add, remove, or rename columns in a table
Change the data type of a column in a table
Add new indexes to a table
Change constraint definitions on a table
--
The dbms_redefinition Package
Use the five procedures in this package to redefine an object online.
CAN_REDEF_TABLE
START_REDEF_TABLE
FINISH_REDEF_TABLE
ABORT_REDEF_TABLE
SYNC_INTERIM_TABLE
--
Other Enhancements
Index Monitoring Usage.
ALTER INDEX INDEX_NAME MONOITORING USAGE;
V$OBJECT_USAGE
Skip Scanning of Indexes.
Real Application Clusters (RAC).
6. Cache Fusion Block Transfer.
Oracle Managed Files (OMF)
DROP TABLESPACE TBS_01 INCLUDING CONTENTS AND DATAFILES;
Default temporary tablespace.
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP;
Constraints on Views.
Log Miner Enhancements.
CURSOR_SHARING=SIMILAR
--
More Enhancements
EXP TABLESPACES=()
DBMS_STATS.GATHER_SYSTEM_STATS.
RMAN Enhancements.
Data Guard (formerly Standby Database).
Log Transport Services.
LOG_ARCHIVE_DEST_n where n = 1-10.
ARCHIVE_LAG_TARGET
Workspace Manager.
Data versioning.
SVRMGR is Deprecated.
CONNECT INTERNAL
--