36
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle Database 12c & 18c Oracle PL/SQL New Features + Steven Feuerstein Oracle Developer Advocate for PL/SQL Oracle Corporation Email: [email protected] Twitter: @sfonplsql Blog: stevenfeuersteinonplsql.blogspot.com YouTube: Practically Perfect PL/SQL

Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Oracle Database 12c & 18c Oracle PL/SQL New Features +

Steven Feuerstein Oracle Developer Advocate for PL/SQL

Oracle Corporation

Email: [email protected] Twitter: @sfonplsql

Blog: stevenfeuersteinonplsql.blogspot.com YouTube: Practically Perfect PL/SQL

Page 2: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

In the Approaching Age of Autonomous Database

• The infrastructure managing your data goes invisible.

• The focus will shift even more decisively to application development and developers.

• Database features that aid in application development will be key.

• Tools that are data-aware and data-centric will offer key advantages for many, perhaps most, appdev projects.

Page 3: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

In the Approaching Age of Autonomous Database

• (and PL/SQL)

May the Best SQL Win!

Page 4: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Development Services

Cloud to On-Premise, Clustering,

Microservices, Sharding, Security,

High Availability, Isolation,

Zero Data Loss, Administration

Data Support

Node.js, Python, .NET, Java,

PHP, Ruby, PL/SQL, C, C++,

Perl, Go, EBR, REST Services,

Advanded Queuing,

APEX, SODA, Docker Relational, JSON, XML, Spatial, Graph, RDF, Text, Binary. Object Stores, HDFS, Kafka, NoSQL Stores

Platform Services

Analytical Services

SQL, R, Columnar In-Memory, Advanced Analytics, Machine Learning, AI

Oracle Database as a Data and Appdev Platform

Infrastructure Services

Public Cloud, Cloud at Customer, Exadata, BDA, ZDLRA

Page 5: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 5

Introducing the RAD Stack

Page 6: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Oracle RAD Stack

6

• REST • Declaratively build REST Data Access APIs from APEX

• Facilitates Integration and Micro Services

• Easily consumed by all languages

• Application Expression - APEX • Low Code Application Development

• IT Professionals, and citizen developers

• LOB Point Solutions, SaaS Extensions

• Differentiated, Low Code, Strong Community

• Database • SQL popularity continues to grow

• PL/SQL implements data APIs and tight security

• SQL Dev and SQL Dev web provide easy access Full Stack Solution for data driven business apps

Page 7: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 7

• Oracle Standard • Auto REST on Objects • SQL Dev Web*

• Custom REST • Swagger / Open API • WLS and Tomcat

• SQL over REST • Pagination • Virus Scanner

• APEX Listener • Embedded Jetty • Jersey*

R Oracle REST Data Services (ORDS)

Page 8: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 8

• APEX 18 now available • Declarative • Database Encapsulated • No cost feature of Oracle

• Native SQL Integration • SQL Workshop • REST Workshop • Portable

• Page Designer • REST Enabled • Forms on Tables • Dynamic Actions

• Interactive Reports • Jet Charts + JET • Interactive Grids • Universal Theme

Oracle APEX A

Page 9: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 9

Oracle Database

• Proven • Large Install Base • Activity Community • Hardened • SQL • Analytics

• Standards Based • JSON and XML • PL/SQL • In Memory • Flashback • Text

• Engineered systems • Pluggable Databases • Scalable • Highly Available • MVRC • Spatial

• Autonomous* • Diagnosable • Portability • RAC • Sharding • Analytic Views

D

Page 10: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 10

• Opportunistic Apps / Point Solutions

• SaaS / EBS Extensions

• Oracle Forms Modernization

• AppDev as a Service

• External Data Sharing

• Datamart Reporting

• Built-in Point Solutions

• Spreadsheet Replacement

• Enterprise Applications

Oracle APEX / RAD Stack Use Cases

Page 11: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved. 11

What differentiates RAD Stack? • Empowering (even managers can create beautiful apps)

• Full Stack Solution (simply provide infrastructure)

• Browser based application development

• Data (and SQL) centric: tightly tied to database

• Supports no-code, low-code and full-code development styles

• Enthusiastic community filled with experts eager to share their expertise

• Portable: it runs wherever Oracle database runs

• Free hosted service at apex.oracle.com

• No cost solution (with XE, it's all FREE!)

Page 12: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

We Offer More Than Just Great Products

• Free resources to help you fully leverage the database

Page 13: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Free Q&A, Training, Workouts, Classes, Scripts!

• Oracle AskTOM – https://asktom.oracle.com –Q&A site, Office Hours with database experts, and much more

• Oracle Dev Gym – https://devgym.oracle.com –Quizzes, workouts and classes for an active learning experience

• Oracle LiveSQL – https://livesql.oracle.com –24x7 access to the latest release of Oracle Database, plus a script

library and tutorials

Page 14: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

The Latest, Greatest Ask TOM

• Tom Kyte's retired but the famous Q&A site is going strong.

– Expanded answer team, modernized UI

• Now it's "Ask The Oracle Masters"

• And we recently added a program designed specifically for our customers: AskTOM Office Hours

Page 15: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Ask TOM – Fantastic Answer Repository

• Level of activity on AskTOM is comparable to the Oracle Database-related activity on StackOverflow.

– No small achievement!

• Constant enhancements to the Q&A

• Write those LiveSQL test cases!

• Don't just copy-paste code!

Page 16: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Ask TOM Office Hours

• Monthly, live, FREE sessions with Oracle Database experts

– Product managers, evangelists, developers

• Sessions range from mini-lessons to full-on trainings to "ask me anything" Q&A.

• Subscribe to receive reminders of upcoming sessions.

• Sessions recorded for later viewing

Page 17: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

LiveSQL: SQL and PL/SQL Script Library + More

• 24x7 access to the latest Oracle Database release

• Script library for personal use or sharing with community

• Great "scratchpad" for trying out and improving your SQL and PL/SQL skills

• Tutorials on growing number of Oracle Database topics

Page 18: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

The Oracle Dev Gym: Quizzes, Workouts, Classes

• An "active learning" site that utilizes quizzes to deepen user knowledge and expertise

• Workouts combine videos and articles with related quizzes

• Classes offer a "mini-MOOC", low-barrier learning experience

• Tournament quizzes for those who want to compete

Page 19: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Move beyond copy-paste for your expertise!

• Too many developers these days rely on Internet searches for all the answers to their programming questions.

– Copy and paste your way to a solution? Maybe....

• The Oracle Database team offers a set of community-oriented sites that offer useful resources and guidance.

• Take advantage of all we have built for you!

asktom.oracle.com devgym.oracle.com livesql.oracle.com

Page 20: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

A Roundup of New PL/SQL Features

• 18c Qualified expressions for collections and records

• Whitelisting with the ACCESSIBLE_BY Clause

• More PL/SQL-Only Data Types Cross PL/SQL-to-SQL Interface

• Optimizing Function Execution in SQL

• The UTL_CALL_STACK Package

• Privileges/Access Management for Program Units

• Static Expressions In Place of Literals

Part 1

Page 21: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

A Roundup of New Features

• Marking elements for deprecation

• PL/Scope now includes SQL statements in its analysis

• Support for JSON in PL/SQL via new object types

• Block code coverage

• Improvements to DBMS_HPROF, the hierarchical profiler

• DBMS_SQL support for PL/SQL types

Part 2

Page 22: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Qualified Expressions (Constructors) for Associative Arrays and Records

• In-line assignment of values to our user-defined types!

Nice improvement in developer productivity and code simplicity

DECLARE TYPE ints_t IS TABLE OF INTEGER INDEX BY PLS_INTEGER; l_ints ints_t := ints_t ( 1 => 55, 2 => 555, 3 => 5555); BEGIN ... END;

DECLARE TYPE ints_t IS TABLE OF INTEGER INDEX BY PLS_INTEGER; l_ints; BEGIN l_ints (1) := 55; l_ints (2) := 555; l_ints (3) := 5555; ... END;

Page 23: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

PL/Scope: powerful code analysis tool

• This compiler-driven tool collects information about identifiers and statements, and stores it in data dictionary views.

– As of 12.2, this includes analysis of SQL statements inside your PL/SQL code.

• Use PL/Scope to answer questions like:

– Where is a variable assigned a value in a program?

– Which subprograms call another subprogram?

– Which SQL statements appear more than once in my application?

– Where do inserts, updates, deletes occur against a specific table?

Page 24: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

The ACCESSIBLE_BY Clause 12.1

• ACCESSIBLE_BY extends the concept of "privacy" for package subprograms.

• Use it to define a "whitelist" of program units that can invoke a package's subprograms.

When that public procedure really shouldn’t be used

12c_accessible_by.sql

PACKAGE private_pkg ACCESSIBLE BY (public_pkg) IS PROCEDURE do_this; PROCEDURE do_that; END;

PACKAGE BODY public_pkg IS PROCEDURE do_only_this IS BEGIN private_pkg.do_this; private_pkg.do_that; END; END;

Page 25: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

More PL/SQL-Only Data Types Cross PL/SQL-to-SQL Interface

• Prior to 12c, PL/SQL-only datatypes could not be bound in dynamic SQL statements, restricted what functions could be called in SQL, etc.

• Now, those constraints are greatly relaxed.

– Bind records and associative arrays

– Use TABLE operator with associative arrays

– Can bind Booleans with dynamic PL/SQL, but you cannot bind Booleans into SQL statements.

TABLE with associative arrays!

12c_table*.sql 12c_bind*.sql

Page 26: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Optimizing Function Execution in SQL

• That seems like an awfully good idea!

• Two methods:

– WITH clause that defines a function

– UDF pragma that gives more options to the compiler

• WITH FUNCTION: define a function directly within your SQL statement. – Say goodbye to nasty context switch!

For all those user-defined functions

12c_with_function*.sql 12c_udf*.sql

Page 27: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

The UTL_CALL_STACK Package

• Prior to 12c, you could obtain several kinds of "stacks" through individual function calls:

– DBMS_UTILITY.FORMAT_CALL_STACK - "How did I get here?"

– DBMS_UTILITY.FORMAT_ERROR_STACK - "What is the error message/stack?"

– DBMS_UTILITY.FORMAT_ERROR_BACKTRACE - "On what line was my error raised?"

• Now, the UTL_CALL_STACK package supports all that and a much better API to the info in the stack.

Improved execution stack granularity and more

12c_utl_call_stack*.sql

Page 28: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Static Expressions In Place of Literals

• Static PL/SQL expressions are allowed where only literals were allowed.

• You no longer have to hard-code maximum lengths for VARCHAR2 variables and other data types.

• You can even use the built-in ORA_MAX_NAME_LEN for the new extended name lengths.

No more VARCHAR2(32767)!

IS my_big_var VARCHAR2 (ORA_MAX_NAME_LEN + 2); my_qualified_var VARCHAR2 (2 * (ORA_MAX_NAME_LEN +2) + 1); BEGIN my_big_var := '"Table_Name"; my_qualified_var := "Schema_Name"."Table_Name";

122_expressions.sql

Page 29: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Goodbye, "Tiny" Name Lengths!

• Instead of 30 bytes you can now go all the way up to 128.

• But this doesn't mean you should.

• Most beneficial for:

– Migrations from other databases to Oracle

– Multi-byte character sets

– Being able to squeak just over that 30 character barrier and no longer having to compromise readability

Now your identifiers can go on_and_on_and_on_and_on_and_on_and_on_...

122_long_identifiers.sql

Page 30: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Goodbye, Tiny SQL VARCHAR2!

• It sure has been irritating that PL/SQL supports VARCHAR2s up to 32K in size (after which , you must switch over to CLOBs), while in SQL, the maximum was 4000.

• Now, SQL's VARCHAR2 and NVARCHAR2 have been extended to 32K as well!

• Note: SQL has these maximum sizes only if the MAX_STRING_SIZE initialization parameter is set to EXTENDED.

And one more impedance between PL/SQL and SQL

12c_sql_varchar2.sql

Page 31: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Kill Off that Old, Dead (should be Zombie) Code.

• In 12.2, you can now document via a pragma code that has been deprecated.

• You can then use compile-time warnings to:

– identify usages of deprecated code

– make it impossible to compile program units that use deprecated code

• But don't make PLW-06019 an error. That simply documents the use of the pragma.

But how do you find it?

CREATE OR REPLACE PACKAGE old_pkg AUTHID DEFINER AS PRAGMA DEPRECATE (old_pkg, 'Use new_pkg instead!'); PROCEDURE proc; END;

Page 32: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

Grant Roles to Program Units (back to 12.1)

• Grant roles to program units, so you fine-tune the privileges available to the invoker of a program unit.

– Helpful when you don't want the invoker to inherit all of the definer's privileges.

• Roles granted to a program unit do not affect compilation.

– Instead, they affect the privilege checking of SQL statements that the unit issues at run time.

– Unit executes with privileges of both its own roles and any other currently enabled roles.

Nice usability enhancement

12c_grant_role_units.sql 12c_roles_for_program_units.sql

Most helpful when unit executing dynamic SQL

Page 33: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

BEQUEATH CURRENT_USER for Views

• Prior to 12.1, if your view executed a function, it would always be run under the privileges of the view's owner, and not that of the function.

– Even if the function was defined with AUTHID CURRENT_USER

• Add the BEQUEATH CURRENT_USER clause and then the invoker right's mode of the function will be "honored."

Tying up a loose end

12c_bequeath.sql

Page 34: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

INHERIT PRIVILEGES and INHERIT ANY PRIVILEGES

• More fine-tuning for privilege management!

• You can override AUTHID and BEQUEATH settings by revoking INHERIT PRIVILEGES.

– On a schema-level basis

• You can say, in effect: "All schemas but SCOTT can use my privileges when running X."

• After upgrade, all works as before.

– INHERT PRIVILEGES granted to all schemas

Yes, there’s more!

12c_inherit_privileges.sql

Page 35: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

And is that it?

• Support for JSON in PL/SQL via new pre-defined JSON types

• Block code coverage

• Improvements to DBMS_HPROF, the hierarchical profiler

• DBMS_SQL support for PL/SQL types

No, there's more, but there's no more time.

Page 36: Oracle Database 12c & 18c Oracle PL/SQL New …...•In-line assignment of values to our user-defined types! Nice improvement in developer productivity and code simplicity DECLARE

Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

It's All About the App – And Their Users

• So take full advantage of everything Oracle offers to make your development a success!

….and underneath it all is data