oracle 12c new features for developers

39
Oracle 12c New Features for Developers By Complete IT Professional www.completeitprofessional.com

Upload: completeitprofessional

Post on 14-Apr-2017

97 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Oracle 12c New Features for Developers

Oracle 12c New Features for Developers

By Complete IT Professional

www.completeitprofessional.com

Page 2: Oracle 12c New Features for Developers

Oracle 12c

• Released in 2013

• Contains a lot of new features

• Some are useful for DBAs, some are useful for developers, some for both

• As a developer, what do you need to know?

• I wrote an entire post on it:

http://www.completeitprofessional.com/oracle-12c-new-features-for-developers

• These slides explain all of those features

Page 3: Oracle 12c New Features for Developers

Increased column size limits

• VARCHAR2, NVARCHAR2, and RAW are larger than previous Oracle versions

Data Type Oracle 11g

Limit

Oracle 11g

PL/SQL Limit

Limit in

Oracle 12c

VARCHAR2 2K 4K 32K

NVARCHAR2 2K 4K 32K

RAW 2K 4K 32K

Page 4: Oracle 12c New Features for Developers

Increased column size limits

• How can you use the new sizes?

• Change the setting called MAX_STRING_SIZE within the init.orafile

• STANDARD – old sizes

• EXTENDED – new sizes

Page 5: Oracle 12c New Features for Developers

APPROX_COUNT_DISTINCT

• New function – APPROX_COUNT_DISTINCT

• Gives you an approximate count of records

• Faster than COUNT

• Not 100% accurate but pretty close

Page 6: Oracle 12c New Features for Developers

Row Limiting with Top N

• Getting the top N rows can be hard in Oracle

• In Oracle 12c, you can use new syntax

• FETCH FIRST 10 ROWS ONLY – shows only the first 10 rows

Page 7: Oracle 12c New Features for Developers

Row Limiting with Top N

SELECT first_name, last_name, date_of_birth

FROM student

ORDER BY date_of_birth

FETCH FIRST 10 ROWS ONLY;

Page 8: Oracle 12c New Features for Developers

Pattern Matching

• Pattern matching is easier in Oracle 12c

• Uses the MATCH_RECOGNIZE keyword

Page 9: Oracle 12c New Features for Developers

Pattern Matching Syntax

SELECT columns

FROM table

MATCH_RECOGNIZE (

PARTITION BY ...

ORDER BY ...

MEASURES ...

PATTERN...

DEFINE...

)

ORDER BY col1...

Page 10: Oracle 12c New Features for Developers

JSON in Database

• Oracle 12c now support JSON in database columns

• You can query directly inside the column data

Page 11: Oracle 12c New Features for Developers

JSON Example{

“businessName”:”Cars Galore”,

“address”:{

“streetNumber”:”14”,

“streetName”:”Main Street”,

“city”:”Denver”,

“state”:”Colorado”,

“country”:”USA”},

“businessIndustry”:”Automotive”

}

SELECT

b.document.businessName,

b.document.address.streetNumber,

b.document.address.streetName

FROM businesses b

Page 12: Oracle 12c New Features for Developers

Lateral Clause for Inline Views

• Normally you can’t refer to columns outside an inline view from within the inline view

• With a LATERAL clause, you can

Page 13: Oracle 12c New Features for Developers

Lateral Clause Example

SELECT first_name, last_name, school_name

FROM student s,

LATERAL (SELECT school_name

FROM school sc

WHERE sc.school_id = s.school_id)

Page 14: Oracle 12c New Features for Developers

CROSS APPLY Clause

• Similar to Lateral

• Variant of the CROSS JOIN

• Right side of the keyword can reference the column on the left

Page 15: Oracle 12c New Features for Developers

CROSS APPLY Example

SELECT first_name, last_name, school_id, school_name

FROM student s,

CROSS APPLY (SELECT school_name

FROM school sc

WHERE sc.school_id = s.school_id

AND sc.school_state = ‘California’)

Page 16: Oracle 12c New Features for Developers

OUTER APPLY Clause

• Similar to CROSS APPLY

• More like a LEFT OUTER JOIN

Page 17: Oracle 12c New Features for Developers

OUTER APPLY Example

SELECT first_name, last_name, school_id, school_name

FROM student s,

OUTER APPLY (SELECT school_name

FROM school sc

WHERE sc.school_id = s.school_id

AND sc.school_state = ‘California’)

Page 18: Oracle 12c New Features for Developers

Partial Join Evaluation

• New optimisation type

• Part of the optimisation process

• You might see it in the Explain Plan

• Partial Join Evaluation

• Also called PJE

Page 19: Oracle 12c New Features for Developers

Cascading Truncate

• Have you tried to TRUNCATE a table that had other records referring to it, and got an error about foreign keys?

• With Oracle 12c, you can run a TRUNCATE CASCADE

• This will skip this error and delete the rows that refer to it

• Only works if the foreign key is defined as ON DELETE CASCASE

Page 20: Oracle 12c New Features for Developers

Cascading Truncate Example

TRUNCATE TABLE parent_table_name CASCADE;

Page 21: Oracle 12c New Features for Developers

Pluggable Databases

• One of the main features in Oracle 12c

• A “root” database is created

• “Seed” database is a template for creating other databases

• “Pluggable databases” are where the data is stored

• All inside the root

Page 22: Oracle 12c New Features for Developers

Why pluggable databases?

• Easier maintenance

• Easier implementation of new databases – just copy the seed

• Easier to move to the cloud

Page 23: Oracle 12c New Features for Developers

Invisible Columns

• Columns that do not appear in the table definition or SELECT * statements

• Use the INVISIBLE keyword when defining a column

Page 24: Oracle 12c New Features for Developers

Invisible Indexes

• Allows more than one index on a column at one time

• Create index and add the INVISIBLE keyword

Page 25: Oracle 12c New Features for Developers

Identity Columns

• Set a column to automatically generate a value

• Similar to AUTO_INCREMENT in other databases

• Add GENERATED AS IDENTITY to column definition when creating a table

Page 26: Oracle 12c New Features for Developers

Default Values

• Simplify data entry

• Use sequences as the default values

• Or use default values only when a NULL is specified

Page 27: Oracle 12c New Features for Developers

Session Sequences

• Sequences currently keep their values for the database for all sessions

• Session sequences are new

• They let you retain the value only for the session

• Not very useful for primary keys, but there are other uses

Page 28: Oracle 12c New Features for Developers

Sequence KEEP and NOKEEP

• KEEP and NOKEEP are keywords for creating sequences

• KEEP retains the NEXTVALUE value for replays during Application Continuity

• NOKEEP will not retain the NEXTVALUE for these replays

• NOKEEP is the default

Page 29: Oracle 12c New Features for Developers

Data Redaction

• You can hide certain fields in certain ways

• Replace characters with spaces or numbers

• Or, change part of the information

• Good security feature

Page 30: Oracle 12c New Features for Developers

Grant Roles to PL/SQL Programs Only

• Previously, you had to grant user access to the PL/SQL program and the table

• Now, just grant user access to the PL/SQL program

• Program will still access the table

• Makes it more secure

Page 31: Oracle 12c New Features for Developers

UTL_CALL_STACK Package

• Improvements to the call stack

• Use the UTL_CALL_STACK package to get information about your call stack

Page 32: Oracle 12c New Features for Developers

PL/SQL ACCESSIBLE BY Clause

• Allows you to specify which packages can access other packages

• Helps with security

• Simplifies package definition if you want to implement this

• Add the words ACCESSIBLE BY to the package when defining

Page 33: Oracle 12c New Features for Developers

PL/SQL Table Operator

• Before 12c, you could only use the TABLE operator in some situations

• Now, you can use them with locally defined types

Page 34: Oracle 12c New Features for Developers

WITH Clause and PL/SQL Functions

• Now you can define PL/SQL functions and procedures inside a WITH clause

• Likely improves run time

• Object is not created and stored in the database

Page 35: Oracle 12c New Features for Developers

Online DDL Statements

• DDL normally locks tables

• Some statements can now be run in “online” mode, which does not impact any DML that is running

• Statements relate to indexes, constraints, and columns

Page 36: Oracle 12c New Features for Developers

DDL Logging

• You can enable DDL logging

• Many DDL statements are captured

• CREATE/ALTER/DROP/TRUNCATE TABLE

• CREATE/ALTER/DROP PACKAGE/FUNCTION/VIEW/SYNONYM/SEQUENCE

• DROP USER

Page 37: Oracle 12c New Features for Developers

Bequeath Option

• Allows you to specify which user’s privileges will be used when running a statement

• Specify either invoker’s or definer’s rights

• Invoker’s rights – the person running the statement

• Definer’s rights – the person who created the object

Page 38: Oracle 12c New Features for Developers

Period Definition

• Allows you to easily specify which records are valid at a particular date

• Use the PERIOD clause when creating a table

• You can then use the PERIOD clause in SELECT queries

Page 39: Oracle 12c New Features for Developers

Conclusion

• Many new features in Oracle 12c

• These are all of the features I think are helpful for new developers

• Find out more here:

http://www.completeitprofessional.com/oracle-12c-new-features-for-developers