Oracle Database 12.1.0.2 New Features
Deiby Gómez Oracle Database Consultant
Alex Zaballa Oracle DBA
Deiby Gómez
oraclefromguatemala.com.gt
@hdeiby
• President of Guatemala Oracle Users Group
• Youngest ACE in the World (23 years old)
• Youngest OCM 11g in Latin America (24 years old)
• Youngest ACE Director in the World (25 years old)
• Some Certs (Exadata, RAC, Linux, SOA)
• Consultant at Pythian
Alex Zaballa
http://alexzaballa.blogspot.com/
@alexzaballa
145 and counting…
Oracle Database 12.1.0.2 New Features
Deiby Gómez
Approximate Count Distinct
COUNT(DISTINCT expression)
Cost
6
Full Database Caching
DB size > Buffer Cache
Little tables:
• Allocated in memory If the table size < 2% of the Buffer Cache size
Medium tables:
• Allocated in memory if table size [2%,10%] of Buffer Cache size (No official
information)
• Oracle analyze the date when the table was used last time
• Free space in Buffer Cache
• Etc
Big Tables
• Big tables are not allocated in Buffer Cache
• Use "KEEP” to advice Oracle to allocate a big table in Buffer Cache
7
Full Database Caching
Buffer Cache > DB size
Little tables:
• Allocated in memory If the table size < 2% of the Buffer Cache size
Medium tables:
• Allocated in memory if table size [2%,10%] of Buffer Cache size (No official
information)
• Oracle analyze the date when the table was used last time
• Free space in Buffer Cache
• Etc
Big Tables
• Big tables are not allocated in Buffer Cache
• Use "KEEP” to advice Oracle to allocate a big table in Buffer Cache
© 2014 Pythian Confidential 8
Full Database Caching
Buffer Cache > DB size
What about if I enable it but Buffer Cache !> DB Size?
• Algorithms to allocate small, medium and large tables are not used.
• More Objects Deallocation
• New object scanned, blocks deallocated.
© 2014 Pythian Confidential 9
PDB CONTAINERS Clause
SELECT ename
FROM CONTAINERS(scott.emp)
WHERE CON_ID IN (11, 13);
PDB File Placement in OMF
• FILE_NAME_CONVERT clause of CREATE PLUGGABLE DATABASE
• CREATE_FILE_DEST clause of CREATE PLUGGABLE DATABASE
• DB_CREATE_FILE_DEST (root level)
• PDB_FILE_NAME_CONVERT initialization parameter
PDB Logging Clause
• Table Level – Logging
• Index Level – Logging
• Tablespace Level – Logging
• Tablespace Level - Force Logging
• PDB Level – Logging
• PDB Level - Force No logging
• CDB - Force Logging
PDB Metadata Clone
NO DATA clause of the CREATE PLUGGABLE DATABASE
“This clause is useful for quickly creating clones of a PDB with
only the object definitions and no data.”
© 2014 Pythian Confidential 13
PDB Remote Clone
IN SOURCE DB:
**alter pluggable database pdbsource open read only;
create user C##dgomez identified by manager1;
grant create session to C##dgomez;
© 2014 Pythian Confidential 14
PDB Remote Clone
IN TARGET DB:
create user C##dgomez identified by manager1;
grant create session, create database link, create pluggable
database to C##dgomez;
PDBSOURCE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = db12102.oraworld.com)(PORT =
1521))
(CONNECT_DATA =
(SERVER = DEDICATED)(SERVICE_NAME = pdbsource)
))
create database link dblinktosource connect to C##dgomez identified
by manager1 using 'PDBSOURCE';
create pluggable database pdbtarget3 from pdbsource@dblinktosource;
© 2014 Pythian Confidential 15
PDB Remote Clone
Target: 12.1.0.2
Source: 12.1.0.1
SQL> create pluggable database pdbtarget from
pdbsource@dblinktosource;
*
ERROR at line 1:
ORA-17627: ORA-00600: internal error code, arguments:
[ksrpcsexec_1], [158],
[20], [], [], [], [], [], [], [], [], []
ORA-17627: ORA-00600: internal error code, arguments:
[ksrpcsexec_1], [158],
[20], [], [], [], [], [], [], [], [], []
© 2014 Pythian Confidential 16
PDB Remote Clone
Target: 12.1.0.1
Source: 12.1.0.1
SQL> create pluggable database pdbtarget from
sourcepdb@dblinktosource
*
ERROR at line 1:
ORA-17628: Oracle error 19505 returned by remote Oracle server
ORA-19505: failed to identify file ""
© 2014 Pythian Confidential 17
PDB Remote Clone
Target: 12.1.0.2
Source: 12.1.0.2
SQL> create pluggable database pdbtarget from
pdbsource@dblinktosource;
Pluggable database created.
© 2014 Pythian Confidential 18
PDB STANDBYS Clause
PDB1
PDB2
PDB3
PDB1
PDB2
PDB3
Primary Standby
• Datafiles Offline
• Unnamed
© 2014 Pythian Confidential 19
PDB STANDBYS Clause
“The STANDBYS clause of the CREATE PLUGGABLE DATABASE statement specifies
whether the new PDB is included in standby CDBs”
 STANDBYS=ALL includes the new PDB in all of the standby CDBs
.
 STANDBYS=NONE excludes the new PDB from all of the standby CDBs.
© 2014 Pythian Confidential 20
PDB STANDBYS Clause
“It is possible to enable a PDB on a standby CDB after it was excluded
on that standby CDB.”
 PDB data files need to be copied to the standby database from the primary
database
 The control file needs to be updated to reflect their paths
 Execute ALTER PLUGGABLE DATABASE ENABLE RECOVERY
 It automatically onlines all of the data files belonging to the PDB.
© 2014 Pythian Confidential 21
PDB State Management Across
CDB Restart
Source: "Oracle Database 12c: New Features for Administrators” by Oracle University
12.1.0.1
© 2014 Pythian Confidential 22
PDB State Management Across
CDB Restart
1. Set the PDB at the State you want to save.
1. SQL> alter pluggable database pdb1 save state;
Pluggable database altered.
or
SQL> alter pluggable database pdb1 discard state;
Pluggable database altered.
12.1.0.2
© 2014 Pythian Confidential 23
PDB State Management Across
CDB Restart
SQL> ALTER PLUGGABLE DATABASE ALL EXCEPT PDB1 SAVE STATE;
Pluggable database altered.
SQL> ALTER PLUGGABLE DATABASE ALL SAVE STATE;
Pluggable database altered.
12.1.0.2
© 2014 Pythian Confidential 24
PDB Subset Cloning
“The USER_TABLESPACES clause of the CREATE PLUGGABLE DATABASE statement
specifies which tablespaces are available in the new PDB”
o List one or more tablespaces to include.
o Specify ALL, the default, to include all of the tablespaces.
o Specify ALL EXCEPT to include all of the tablespaces, except for the
tablespaces listed.
o Specify NONE to exclude all of the tablespaces.
Database Source
© 2014 Pythian Confidential 25
PDB Subset Cloning
Tablespace 1
Tablespace 2
Tablespace 3
PDB 1
Tablespace 1
PDB 2
Tablespace 2
PDB 3
Tablespace 3
More Oracle Database 12.1.0.2 New Features
Alex Zaballa
JSON
OTN Article by Alex Zaballa
http://www.oracle.com/technetwork/pt/articles
/sql/json-oracle-database-12c-2378776-
ptb.html
JSON
• Oracle Database 12.1.0.2 has now native
support for JSON.
• “JSON (JavaScript Object Notation) is a
lightweight data-interchange format. It is easy
for humans to read and write. It is easy for
machines to parse and generate.”
Source: http://json.org/
JSON
JSON
Data Redaction
OTN Article in English by Alex Zaballa
http://www.oracle.com/technetwork/articles/d
atabase/data-redaction-odb12c-2331480.html
Data Redaction
• One of the new features introduced in Oracle
Database 12c
• Part of the Advanced Security option
• Enables the protection of data shown to the
user in real time, without requiring changes to
the application
Data Redaction
Data Redaction
SQL Query Row Limits
and Offsets
SQL Query Row Limits
and Offsets
create table tabela_teste (codigo number, nome varchar2(20), salario
number);
insert into tabela_teste values (1,'Alex' ,100);
insert into tabela_teste values (2,'Joao' ,200);
insert into tabela_teste values (3,'Maria' ,300);
insert into tabela_teste values (4,'Pedro',400);
insert into tabela_teste values (5,'Paulo',500);
insert into tabela_teste values (6,'Fernando',600);
insert into tabela_teste values (7,'Rafael',700);
insert into tabela_teste values (8,'Samuel',700);
insert into tabela_teste values (9,'Daniel',800);
insert into tabela_teste values (10,'Luciano',1000);
SQL Query Row Limits
and Offsets
Top-N Queries – Pré 12c
select * from ( select codigo, nome, salario
from tabela_teste
order by salario desc)
where rownum <= 5
SQL Query Row Limits
and Offsets
select codigo, nome, salario
from tabela_teste
order by salario desc
FETCH FIRST 5 ROWS ONLY
SQL Query Row Limits
and Offsets
select codigo, nome, salario
from tabela_teste
order by salario
FETCH FIRST 30 PERCENT ROWS ONLY
SQL Query Row Limits
and Offsets
select codigo, nome, salario
from tabela_teste
order by salario desc
OFFSET 2 ROWS FETCH NEXT 2 ROWS ONLY;
Invisible Columns
CREATE TABLE tabela_teste
(
coluna1 NUMBER,
coluna2 NUMBER,
coluna3 NUMBER INVISIBLE,
coluna4 NUMBER
);
SQL> desc tabela_teste
Name
-----------------------------------------
COLUNA1 NUMBER
COLUNA2 NUMBER
COLUNA4 NUMBER
Invisible Columns
INSERT INTO tabela_teste
(coluna1,coluna2,coluna3,coluna4) VALUES
(1,2,3,4);
INSERT INTO tabela_teste VALUES (1,2,4);
Invisible Columns
SET COLINVISIBLE ON
SQL> desc tabela_teste
Name
-----------------------------------------
COLUNA1 NUMBER
COLUNA2 NUMBER
COLUNA4 NUMBER
COLUNA3 (INVISIBLE) NUMBER
Invisible Columns
ALTER TABLE tabela_teste MODIFY coluna3 VISIBLE;
SQL Text Expansion
SQL> variable retorno clob
SQL> begin
dbms_utility.expand_sql_text( input_sql_text
=> 'select * from emp', output_sql_text=>
:retorno );
end;
SQL Text Expansion
• Views
• VPDs
PL/SQL From SQL
with
function Is_Number
(x in varchar2) return varchar2 is
Plsql_Num_Error exception;
pragma exception_init(Plsql_Num_Error, -06502);
begin
if (To_Number(x) is NOT null) then
return 'Y';
else
return '';
end if;
exception
when Plsql_Num_Error then
return 'N';
end Is_Number;
select rownum, x, is_number(x) is_num from t;
Session Level Sequences
Session level sequences are used to produce
unique values in a session. Once the session
ends, the sequence is reset.
Generating Primary Keys for a Global Temporary
Table would be a field where those kinds of
sequences could be used.
Session Level Sequences
CREATE SEQUENCE sequence_teste
START WITH 1
INCREMENT BY 1
SESSION
/
Session Level Sequences
ALTER SEQUENCE sequence_teste
SESSION;
ALTER SEQUENCE sequence_teste
GLOBAL;
Extended Data Types
SQL> create table tabela_teste(campo01
varchar2(4001));
*
ERROR at line 1:
ORA-00910: specified length too long for its
datatype
Extended Data Types
- VARCHAR2 : 32767 bytes
- NVARCHAR2 : 32767 bytes
- RAW : 32767 bytes
Extended Data Types
SHUTDOWN IMMEDIATE;
STARTUP UPGRADE;
ALTER SYSTEM SET max_string_size=extended;
@?/rdbms/admin/utl32k.sql
SHUTDOWN IMMEDIATE;
STARTUP;
**Once you switch to extended data types you can't switch back
Multiple Indexes on the
same set of Columns
Pre 12c:
ORA-01408: such column list already indexed
error.
Multiple Indexes on the
same set of Columns
Is the ability to create more than one index on
the same set of columns in 12c.
**Only one of these indexes can be visible at a
time
Multiple Indexes on the
same set of Columns
Why would you want to do that?
• Unique versus nonunique
• B-tree versus bitmap
• Different partitioning strategies
READ Object Privilege and
READ ANY TABLE System Privilege
What is the difference to SELECT and SELECT
ANY TABLE?
READ Object Privilege and
READ ANY TABLE System Privilege
SELECT and SELECT ANY TABLE provides the
ability to lock rows:
LOCK TABLE table_name IN EXCLUSIVE MODE;
SELECT ... FROM table_name FOR UPDATE;
READ Object Privilege and
READ ANY TABLE System Privilege
SQL> grant select on scott.emp to teste;
Grant succeeded.
SQL> lock table scott.emp in exclusive mode;
Table(s) Locked.
READ Object Privilege and
READ ANY TABLE System Privilege
SQL> grant read on scott.emp to teste;
Grant succeeded.
SQL> lock table scott.emp in exclusive mode;
lock table scott.emp in exclusive mode
*
ERROR at line 1:
ORA-01031: insufficient privileges
Truncate Cascade
SQL> truncate table scott.dept;
truncate table scott.dept
*
ERROR at line 1:
ORA-02266: unique/primary keys in table
referenced by enabled foreign keys
Truncate Cascade
SQL> truncate table scott.dept cascade;
Table truncated.
The constraint should be ON DELETE CASCADE.
DDL LOGGING
DDL LOGGING
/u01/app/oracle/diag/rdbms/orcl/orcl/log/ddl/log.xml
Direct SQL statement
execution in RMAN
Pre - 12c:
RMAN> SQL ‘SELECT sysdate FROM dual’;
12c:
RMAN> SELECT sysdate FROM dual;
RMAN Table Recovery in 12c
RMAN enables you to recover one or more
tables or table partitions to a specified point in
time.
RMAN Table Recovery in 12c
RMAN> RECOVER TABLE HR.REGIONS
UNTIL TIME "TO_DATE('01/10/2013
09:33:39','DD/MM/RRRR HH24:MI:SS')"
AUXILIARY DESTINATION '/tmp/backups'
Statistics During Loads
The ability to gather statistics automatically
during bulk loads:
- CREATE TABLE AS SELECT
- INSERT INTO ... SELECT into an empty table
using a direct path insert
Partial Indexes for Partitioned Table
• You can create local and global indexes on a
subset of the partitions of a table, enabling
more flexibility in index creation.
• This feature is not supported for unique
indexes, or for indexes used for enforcing
unique constraints.
Partial Indexes for Partitioned Table
In-Database Archiving
SQL> create table tabela_teste(coluna1 number)
row archival;
insert into tabela_teste values(1);
insert into tabela_teste values(2);
insert into tabela_teste values(3);
In-Database Archiving
In-Database Archiving
update tabela_teste
set ora_archive_state=DBMS_ILM.ARCHIVESTATENAME(1)
where coluna1=3;
In-Database Archiving
alter session set row archival visibility=all;
SQL*Loader Express
• You don't need to to write and test a
SQL*Loader control file.
• The benefit main is the savings for time and
effort.
SQL*Loader Express
[oracle@oracle01 tmp]$ cat EMPRESA.dat
1,Empresa 1
2,Empresa 2
3,Empresa 3
4,Empresa 4
5,Empresa 5
6,Empresa 6
7,Empresa 7
8,Empresa 8
9,Empresa 9
SQL*Loader Express
[oracle@oracle01 tmp]$ sqlldr teste/teste TABLE=EMPRESA
SQL*Loader: Release 12.1.0.1.0 - Production on Sat Jan 11 12:16:28 2014
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
Express Mode Load, Table: EMPRESA
Path used: External Table, DEGREE_OF_PARALLELISM=AUTO
Table EMPRESA:
9 Rows successfully loaded.
Check the log files:
EMPRESA.log
EMPRESA_%p.log_xt
for more information about the load.
Identity Columns
CREATE TABLE tabela_teste (
id NUMBER GENERATED ALWAYS AS IDENTITY,
coluna1 VARCHAR2(30)
);
Identity Columns
CREATE TABLE tabela_teste (
id NUMBER GENERATED BY DEFAULT AS IDENTITY,
coluna1 VARCHAR2(30)
);
Identity Columns
CREATE TABLE tabela_teste (
id NUMBER GENERATED BY DEFAULT ON NULL AS
IDENTITY,
coluna1 VARCHAR2(30)
);
Thank You

Oracle Database 12.1.0.2 New Features

  • 1.
    Oracle Database 12.1.0.2New Features Deiby Gómez Oracle Database Consultant Alex Zaballa Oracle DBA
  • 2.
    Deiby Gómez oraclefromguatemala.com.gt @hdeiby • Presidentof Guatemala Oracle Users Group • Youngest ACE in the World (23 years old) • Youngest OCM 11g in Latin America (24 years old) • Youngest ACE Director in the World (25 years old) • Some Certs (Exadata, RAC, Linux, SOA) • Consultant at Pythian
  • 3.
  • 4.
    Oracle Database 12.1.0.2New Features Deiby Gómez
  • 5.
  • 6.
    6 Full Database Caching DBsize > Buffer Cache Little tables: • Allocated in memory If the table size < 2% of the Buffer Cache size Medium tables: • Allocated in memory if table size [2%,10%] of Buffer Cache size (No official information) • Oracle analyze the date when the table was used last time • Free space in Buffer Cache • Etc Big Tables • Big tables are not allocated in Buffer Cache • Use "KEEP” to advice Oracle to allocate a big table in Buffer Cache
  • 7.
    7 Full Database Caching BufferCache > DB size Little tables: • Allocated in memory If the table size < 2% of the Buffer Cache size Medium tables: • Allocated in memory if table size [2%,10%] of Buffer Cache size (No official information) • Oracle analyze the date when the table was used last time • Free space in Buffer Cache • Etc Big Tables • Big tables are not allocated in Buffer Cache • Use "KEEP” to advice Oracle to allocate a big table in Buffer Cache
  • 8.
    © 2014 PythianConfidential 8 Full Database Caching Buffer Cache > DB size What about if I enable it but Buffer Cache !> DB Size? • Algorithms to allocate small, medium and large tables are not used. • More Objects Deallocation • New object scanned, blocks deallocated.
  • 9.
    © 2014 PythianConfidential 9 PDB CONTAINERS Clause SELECT ename FROM CONTAINERS(scott.emp) WHERE CON_ID IN (11, 13);
  • 10.
    PDB File Placementin OMF • FILE_NAME_CONVERT clause of CREATE PLUGGABLE DATABASE • CREATE_FILE_DEST clause of CREATE PLUGGABLE DATABASE • DB_CREATE_FILE_DEST (root level) • PDB_FILE_NAME_CONVERT initialization parameter
  • 11.
    PDB Logging Clause •Table Level – Logging • Index Level – Logging • Tablespace Level – Logging • Tablespace Level - Force Logging • PDB Level – Logging • PDB Level - Force No logging • CDB - Force Logging
  • 12.
    PDB Metadata Clone NODATA clause of the CREATE PLUGGABLE DATABASE “This clause is useful for quickly creating clones of a PDB with only the object definitions and no data.”
  • 13.
    © 2014 PythianConfidential 13 PDB Remote Clone IN SOURCE DB: **alter pluggable database pdbsource open read only; create user C##dgomez identified by manager1; grant create session to C##dgomez;
  • 14.
    © 2014 PythianConfidential 14 PDB Remote Clone IN TARGET DB: create user C##dgomez identified by manager1; grant create session, create database link, create pluggable database to C##dgomez; PDBSOURCE = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = db12102.oraworld.com)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = pdbsource) )) create database link dblinktosource connect to C##dgomez identified by manager1 using 'PDBSOURCE'; create pluggable database pdbtarget3 from pdbsource@dblinktosource;
  • 15.
    © 2014 PythianConfidential 15 PDB Remote Clone Target: 12.1.0.2 Source: 12.1.0.1 SQL> create pluggable database pdbtarget from pdbsource@dblinktosource; * ERROR at line 1: ORA-17627: ORA-00600: internal error code, arguments: [ksrpcsexec_1], [158], [20], [], [], [], [], [], [], [], [], [] ORA-17627: ORA-00600: internal error code, arguments: [ksrpcsexec_1], [158], [20], [], [], [], [], [], [], [], [], []
  • 16.
    © 2014 PythianConfidential 16 PDB Remote Clone Target: 12.1.0.1 Source: 12.1.0.1 SQL> create pluggable database pdbtarget from sourcepdb@dblinktosource * ERROR at line 1: ORA-17628: Oracle error 19505 returned by remote Oracle server ORA-19505: failed to identify file ""
  • 17.
    © 2014 PythianConfidential 17 PDB Remote Clone Target: 12.1.0.2 Source: 12.1.0.2 SQL> create pluggable database pdbtarget from pdbsource@dblinktosource; Pluggable database created.
  • 18.
    © 2014 PythianConfidential 18 PDB STANDBYS Clause PDB1 PDB2 PDB3 PDB1 PDB2 PDB3 Primary Standby • Datafiles Offline • Unnamed
  • 19.
    © 2014 PythianConfidential 19 PDB STANDBYS Clause “The STANDBYS clause of the CREATE PLUGGABLE DATABASE statement specifies whether the new PDB is included in standby CDBs”  STANDBYS=ALL includes the new PDB in all of the standby CDBs .  STANDBYS=NONE excludes the new PDB from all of the standby CDBs.
  • 20.
    © 2014 PythianConfidential 20 PDB STANDBYS Clause “It is possible to enable a PDB on a standby CDB after it was excluded on that standby CDB.”  PDB data files need to be copied to the standby database from the primary database  The control file needs to be updated to reflect their paths  Execute ALTER PLUGGABLE DATABASE ENABLE RECOVERY  It automatically onlines all of the data files belonging to the PDB.
  • 21.
    © 2014 PythianConfidential 21 PDB State Management Across CDB Restart Source: "Oracle Database 12c: New Features for Administrators” by Oracle University 12.1.0.1
  • 22.
    © 2014 PythianConfidential 22 PDB State Management Across CDB Restart 1. Set the PDB at the State you want to save. 1. SQL> alter pluggable database pdb1 save state; Pluggable database altered. or SQL> alter pluggable database pdb1 discard state; Pluggable database altered. 12.1.0.2
  • 23.
    © 2014 PythianConfidential 23 PDB State Management Across CDB Restart SQL> ALTER PLUGGABLE DATABASE ALL EXCEPT PDB1 SAVE STATE; Pluggable database altered. SQL> ALTER PLUGGABLE DATABASE ALL SAVE STATE; Pluggable database altered. 12.1.0.2
  • 24.
    © 2014 PythianConfidential 24 PDB Subset Cloning “The USER_TABLESPACES clause of the CREATE PLUGGABLE DATABASE statement specifies which tablespaces are available in the new PDB” o List one or more tablespaces to include. o Specify ALL, the default, to include all of the tablespaces. o Specify ALL EXCEPT to include all of the tablespaces, except for the tablespaces listed. o Specify NONE to exclude all of the tablespaces.
  • 25.
    Database Source © 2014Pythian Confidential 25 PDB Subset Cloning Tablespace 1 Tablespace 2 Tablespace 3 PDB 1 Tablespace 1 PDB 2 Tablespace 2 PDB 3 Tablespace 3
  • 26.
    More Oracle Database12.1.0.2 New Features Alex Zaballa
  • 27.
    JSON OTN Article byAlex Zaballa http://www.oracle.com/technetwork/pt/articles /sql/json-oracle-database-12c-2378776- ptb.html
  • 28.
    JSON • Oracle Database12.1.0.2 has now native support for JSON. • “JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.” Source: http://json.org/
  • 29.
  • 30.
  • 31.
    Data Redaction OTN Articlein English by Alex Zaballa http://www.oracle.com/technetwork/articles/d atabase/data-redaction-odb12c-2331480.html
  • 32.
    Data Redaction • Oneof the new features introduced in Oracle Database 12c • Part of the Advanced Security option • Enables the protection of data shown to the user in real time, without requiring changes to the application
  • 33.
  • 34.
  • 35.
    SQL Query RowLimits and Offsets
  • 36.
    SQL Query RowLimits and Offsets create table tabela_teste (codigo number, nome varchar2(20), salario number); insert into tabela_teste values (1,'Alex' ,100); insert into tabela_teste values (2,'Joao' ,200); insert into tabela_teste values (3,'Maria' ,300); insert into tabela_teste values (4,'Pedro',400); insert into tabela_teste values (5,'Paulo',500); insert into tabela_teste values (6,'Fernando',600); insert into tabela_teste values (7,'Rafael',700); insert into tabela_teste values (8,'Samuel',700); insert into tabela_teste values (9,'Daniel',800); insert into tabela_teste values (10,'Luciano',1000);
  • 37.
    SQL Query RowLimits and Offsets Top-N Queries – Pré 12c select * from ( select codigo, nome, salario from tabela_teste order by salario desc) where rownum <= 5
  • 38.
    SQL Query RowLimits and Offsets select codigo, nome, salario from tabela_teste order by salario desc FETCH FIRST 5 ROWS ONLY
  • 39.
    SQL Query RowLimits and Offsets select codigo, nome, salario from tabela_teste order by salario FETCH FIRST 30 PERCENT ROWS ONLY
  • 40.
    SQL Query RowLimits and Offsets select codigo, nome, salario from tabela_teste order by salario desc OFFSET 2 ROWS FETCH NEXT 2 ROWS ONLY;
  • 41.
    Invisible Columns CREATE TABLEtabela_teste ( coluna1 NUMBER, coluna2 NUMBER, coluna3 NUMBER INVISIBLE, coluna4 NUMBER ); SQL> desc tabela_teste Name ----------------------------------------- COLUNA1 NUMBER COLUNA2 NUMBER COLUNA4 NUMBER
  • 42.
    Invisible Columns INSERT INTOtabela_teste (coluna1,coluna2,coluna3,coluna4) VALUES (1,2,3,4); INSERT INTO tabela_teste VALUES (1,2,4);
  • 43.
    Invisible Columns SET COLINVISIBLEON SQL> desc tabela_teste Name ----------------------------------------- COLUNA1 NUMBER COLUNA2 NUMBER COLUNA4 NUMBER COLUNA3 (INVISIBLE) NUMBER
  • 44.
    Invisible Columns ALTER TABLEtabela_teste MODIFY coluna3 VISIBLE;
  • 45.
    SQL Text Expansion SQL>variable retorno clob SQL> begin dbms_utility.expand_sql_text( input_sql_text => 'select * from emp', output_sql_text=> :retorno ); end;
  • 46.
    SQL Text Expansion •Views • VPDs
  • 47.
    PL/SQL From SQL with functionIs_Number (x in varchar2) return varchar2 is Plsql_Num_Error exception; pragma exception_init(Plsql_Num_Error, -06502); begin if (To_Number(x) is NOT null) then return 'Y'; else return ''; end if; exception when Plsql_Num_Error then return 'N'; end Is_Number; select rownum, x, is_number(x) is_num from t;
  • 48.
    Session Level Sequences Sessionlevel sequences are used to produce unique values in a session. Once the session ends, the sequence is reset. Generating Primary Keys for a Global Temporary Table would be a field where those kinds of sequences could be used.
  • 49.
    Session Level Sequences CREATESEQUENCE sequence_teste START WITH 1 INCREMENT BY 1 SESSION /
  • 50.
    Session Level Sequences ALTERSEQUENCE sequence_teste SESSION; ALTER SEQUENCE sequence_teste GLOBAL;
  • 51.
    Extended Data Types SQL>create table tabela_teste(campo01 varchar2(4001)); * ERROR at line 1: ORA-00910: specified length too long for its datatype
  • 52.
    Extended Data Types -VARCHAR2 : 32767 bytes - NVARCHAR2 : 32767 bytes - RAW : 32767 bytes
  • 53.
    Extended Data Types SHUTDOWNIMMEDIATE; STARTUP UPGRADE; ALTER SYSTEM SET max_string_size=extended; @?/rdbms/admin/utl32k.sql SHUTDOWN IMMEDIATE; STARTUP; **Once you switch to extended data types you can't switch back
  • 54.
    Multiple Indexes onthe same set of Columns Pre 12c: ORA-01408: such column list already indexed error.
  • 55.
    Multiple Indexes onthe same set of Columns Is the ability to create more than one index on the same set of columns in 12c. **Only one of these indexes can be visible at a time
  • 56.
    Multiple Indexes onthe same set of Columns Why would you want to do that? • Unique versus nonunique • B-tree versus bitmap • Different partitioning strategies
  • 57.
    READ Object Privilegeand READ ANY TABLE System Privilege What is the difference to SELECT and SELECT ANY TABLE?
  • 58.
    READ Object Privilegeand READ ANY TABLE System Privilege SELECT and SELECT ANY TABLE provides the ability to lock rows: LOCK TABLE table_name IN EXCLUSIVE MODE; SELECT ... FROM table_name FOR UPDATE;
  • 59.
    READ Object Privilegeand READ ANY TABLE System Privilege SQL> grant select on scott.emp to teste; Grant succeeded. SQL> lock table scott.emp in exclusive mode; Table(s) Locked.
  • 60.
    READ Object Privilegeand READ ANY TABLE System Privilege SQL> grant read on scott.emp to teste; Grant succeeded. SQL> lock table scott.emp in exclusive mode; lock table scott.emp in exclusive mode * ERROR at line 1: ORA-01031: insufficient privileges
  • 61.
    Truncate Cascade SQL> truncatetable scott.dept; truncate table scott.dept * ERROR at line 1: ORA-02266: unique/primary keys in table referenced by enabled foreign keys
  • 62.
    Truncate Cascade SQL> truncatetable scott.dept cascade; Table truncated. The constraint should be ON DELETE CASCADE.
  • 63.
  • 64.
  • 65.
    Direct SQL statement executionin RMAN Pre - 12c: RMAN> SQL ‘SELECT sysdate FROM dual’; 12c: RMAN> SELECT sysdate FROM dual;
  • 66.
    RMAN Table Recoveryin 12c RMAN enables you to recover one or more tables or table partitions to a specified point in time.
  • 67.
    RMAN Table Recoveryin 12c RMAN> RECOVER TABLE HR.REGIONS UNTIL TIME "TO_DATE('01/10/2013 09:33:39','DD/MM/RRRR HH24:MI:SS')" AUXILIARY DESTINATION '/tmp/backups'
  • 68.
    Statistics During Loads Theability to gather statistics automatically during bulk loads: - CREATE TABLE AS SELECT - INSERT INTO ... SELECT into an empty table using a direct path insert
  • 69.
    Partial Indexes forPartitioned Table • You can create local and global indexes on a subset of the partitions of a table, enabling more flexibility in index creation. • This feature is not supported for unique indexes, or for indexes used for enforcing unique constraints.
  • 70.
    Partial Indexes forPartitioned Table
  • 71.
    In-Database Archiving SQL> createtable tabela_teste(coluna1 number) row archival; insert into tabela_teste values(1); insert into tabela_teste values(2); insert into tabela_teste values(3);
  • 72.
  • 73.
    In-Database Archiving update tabela_teste setora_archive_state=DBMS_ILM.ARCHIVESTATENAME(1) where coluna1=3;
  • 74.
    In-Database Archiving alter sessionset row archival visibility=all;
  • 75.
    SQL*Loader Express • Youdon't need to to write and test a SQL*Loader control file. • The benefit main is the savings for time and effort.
  • 76.
    SQL*Loader Express [oracle@oracle01 tmp]$cat EMPRESA.dat 1,Empresa 1 2,Empresa 2 3,Empresa 3 4,Empresa 4 5,Empresa 5 6,Empresa 6 7,Empresa 7 8,Empresa 8 9,Empresa 9
  • 77.
    SQL*Loader Express [oracle@oracle01 tmp]$sqlldr teste/teste TABLE=EMPRESA SQL*Loader: Release 12.1.0.1.0 - Production on Sat Jan 11 12:16:28 2014 Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved. Express Mode Load, Table: EMPRESA Path used: External Table, DEGREE_OF_PARALLELISM=AUTO Table EMPRESA: 9 Rows successfully loaded. Check the log files: EMPRESA.log EMPRESA_%p.log_xt for more information about the load.
  • 78.
    Identity Columns CREATE TABLEtabela_teste ( id NUMBER GENERATED ALWAYS AS IDENTITY, coluna1 VARCHAR2(30) );
  • 79.
    Identity Columns CREATE TABLEtabela_teste ( id NUMBER GENERATED BY DEFAULT AS IDENTITY, coluna1 VARCHAR2(30) );
  • 80.
    Identity Columns CREATE TABLEtabela_teste ( id NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY, coluna1 VARCHAR2(30) );
  • 82.