This document discusses handling exceptions in PL/SQL. It explains that exceptions can be raised implicitly by the Oracle server or explicitly in a program. Exceptions can be handled by trapping them with an exception handler or propagating them to the calling environment. It provides details and examples of trapping predefined Oracle exceptions, user-defined exceptions, and non-predefined Oracle exceptions. It also discusses exception handling in calling environments like procedures.
This document provides an overview and introduction to advanced PL/SQL concepts. It covers fundamentals like data types, control structures, cursors, exceptions and error handling. It also discusses more advanced topics such as Oracle types and collections, interacting with Oracle databases using PL/SQL, creating subprograms and packages, and error handling. The document is presented by Vinay Kumar and intended to teach advanced PL/SQL concepts.
The document provides guidelines for optimizing SQL and PL/SQL code for performance. It discusses best practices for using indexes like creating them on frequently queried columns and avoiding functions on indexed columns. Other topics covered include using EXISTS instead of JOINs when possible, avoiding DISTINCT, and placing filters in the WHERE clause instead of HAVING. Modular code design, avoiding negatives and LIKE patterns, and letting the optimizer do its work are also recommended. The goal is to help programmers write efficient code by understanding query execution and tuning techniques.
PL/SQL is a programming language that combines the SQL operations of querying and manipulating data in an Oracle database with the procedural language constructs of variables, conditions, and loops. PL/SQL can be used for database-side programming as well as client-side application development. It provides advantages like better performance, portability, higher productivity, and integration with Oracle. PL/SQL supports various data types, control structures, exception handling, and object-oriented programming features. Cursors allow processing of multiple rows returned from a SQL statement and can be static, dynamic, or reference types. Procedures and functions are reusable program units that allow passing parameters and returning values.
This document provides an overview of context switching in PL/SQL and best practices for reducing context switches using bulk binding techniques like BULK COLLECT and FORALL. It discusses how context switching occurs between the PL/SQL and SQL engines and how to avoid SQL statements in loops. It then demonstrates the syntax for BULK COLLECT and FORALL and provides an example of their use to update multiple rows with one context switch. The document concludes with discussions on best practices like using LIMIT with BULK COLLECT and avoiding cursor attributes like %NOTFOUND.
The document provides an overview of advanced PL/SQL programming concepts including:
- Decision control structures like IF/THEN, IF/THEN/ELSE, and nested IF statements.
- Using SQL queries within PL/SQL programs.
- Implementing loops using LOOP/EXIT, WHILE, FOR, and cursor FOR loops.
- Retrieving and manipulating database data using implicit and explicit cursors.
- Handling runtime errors through the use of predefined, undefined, and user-defined exceptions.
This document discusses stored procedures and functions in Oracle. It begins by differentiating between anonymous blocks and subprograms, and then defines procedures and functions as named PL/SQL blocks. The key differences between anonymous blocks and subprograms are outlined. The document provides the syntax for creating procedures and functions, and includes examples of a simple procedure that inserts a row without parameters, a function that returns a Boolean value, and modifying the function to accept a parameter. It concludes with invoking the procedure and functions from anonymous blocks to demonstrate their usage.
PL/SQL is a combination of SQL and procedural languages that enhances SQL's capabilities. It allows processing of SQL statements as a block. A PL/SQL block consists of optional declaration, mandatory execution, and optional exception sections. Variables, constants, records can be declared in the declaration section and used in the execution section. The execution section contains the main program logic. Exceptions are handled in the exception section. PL/SQL supports programming constructs like conditional statements and loops.
PL/SQL is a standard and portable language for Oracle Database development. If you develop a program that executes on an Oracle Database, you can quickly move it to another compatible Oracle Database without any changes. PL/SQL is an embedded language. PL/SQL only can execute in an Oracle Database.
It consists of important different concepts related to PL/SQL that are covered like the Basic structure of PL/SQL block, Variables and Constants in PL/SQL, Control Structures i.e., Conditional, Iterative, and Sequential Control, Procedure and Function, Cursors and its Types, Applications of implicit and explicit cursors, Triggers and its Types and Exception Handling.
This document discusses new features in Java 8 including stream API, lambdas, default methods, optional values, date and time API, stamped locks, concurrent adders, improved annotations, new file operations, overflow operations, and the Nashorn JavaScript engine. It provides code examples and explanations of how to use these new features in Java 8.
This document discusses retrieving data in PL/SQL. It reviews that SQL statements like SELECT, INSERT, UPDATE and DELETE can be used directly in PL/SQL code. It also notes limitations around DDL and DCL statements. The key points covered include using the SELECT statement to retrieve data into PL/SQL variables, following naming convention guidelines for variables, and organizing code into blocks to improve readability.
This document discusses explicit cursors in PL/SQL. It begins by listing the objectives of the lesson, which include distinguishing between implicit and explicit cursors, describing when to use explicit cursors, listing guidelines for declaring and controlling explicit cursors, and demonstrating how to open a cursor, fetch data into variables, loop through multiple rows, and close a cursor. It then explains the purpose of explicit cursors when a SELECT statement may return multiple rows. It discusses context areas and cursors, the limitations of implicit cursors, and shows examples of declaring, opening, fetching from, and closing an explicit cursor.
The document discusses conditional control structures in PL/SQL, specifically IF statements. It describes the basic syntax of IF statements, including the use of IF-THEN, IF-THEN-ELSE, and IF-ELSIF-ELSE structures. Examples are provided to demonstrate how conditions are evaluated and how control flow works based on whether conditions evaluate to TRUE, FALSE, or NULL. The use of logical operators and handling of NULL values within IF statements is also covered.
The document discusses the Oracle query optimizer. It describes the key components and steps of the optimizer including the query transformer, query estimator, and plan generator. The query transformer rewrites queries for better performance through techniques like view merging, predicate pushing, and subquery unnesting. The query estimator calculates selectivity, cardinality, and cost to determine the overall cost of execution plans. The plan generator explores access paths, join methods, and join orders to select the lowest cost plan.
Default methods and static methods allow interfaces to define new methods without breaking existing implementations. The lambda expressions feature introduces functional programming to Java through functional interfaces like Consumer and Function. The streams API provides a functional-style way to process and analyze collections through parallelization, optional return values, and collectors.
1. The document describes how to create and use stored procedures in Oracle, including defining parameters, parameter passing modes, and developing procedures.
2. Key aspects of procedures are that they promote reusability and maintainability, are created using the CREATE PROCEDURE statement, and can accept parameters to communicate data between the calling environment and the procedure.
3. Parameters can be defined using modes like IN, OUT, and IN OUT to determine how data is passed into and out of a procedure.
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
Lambda expressions and streams are major new features in Java 8. Lambda expressions allow treating functionality as a method argument or variable. Streams provide a new way to process collections of objects in a declarative way using intermediate and terminal operations. The document provides examples of lambda expressions, method references, functional interfaces, default methods on interfaces, and stream operations like filter, map, and reduce.
User-defined functions in SAP HANA accept parameters, perform actions such as complex calculations, and return the results. There are two types of user-defined functions: scalar and table. Scalar functions return a single value and allow only expressions, while table functions always return a table, can accept table parameters, and are read-only. Table functions are defined using SQL Script and can only contain read-only statements.
This document provides an alphabetical overview of all SAP ABAP keywords and commands. It lists keywords such as ADD, CALL FUNCTION, CASE, CHECK, CLASS and more. For each keyword, it provides the syntax and a short description of its usage in 1-3 sentences. The document appears to be an exhaustive reference list for all ABAP language elements.
PL/pgSQL - An Introduction on Using Imperative Programming in PostgreSQLReactive.IO
When you start tackling complex high-volume data problems, SQL might not be enough. When your logic needs to be close to your data, PostgreSQL has a secret weapon, PL/pgSQL. An imperative language that extends SQL, PL/pgSQL lets you execute complex read and write logic directly on the database. The benefits include increased speed and concurrency, code reuse among many applications, strong consistency guarantees, and greater query flexibility.
This presentation will show you how PL/pgSQL functions can speed up your indexes, accelerate complex queries, activate custom triggers on data changes, and handle complex write situations. Afterwards, you will be able to take control of your data directly at the source, within PostgreSQL itself.
Key points discussed:
* PL/pgSQL: what it is and why it matters
* Volatility: living in an uncertain data world
* Upserts: a little update with a little insert
* Triggers: keeping data consistent
* Code Blocks: control when you need it
SQL examples given during the presentation are available here: http://www.reactive.io/academy/presentations/postgresql/plpgsql/plpgsql-examples.zip
This document discusses PL/SQL transactions and cursors. It defines a transaction as a series of related SQL statements that are treated as a logical unit by Oracle. Transactions are committed or rolled back. Cursors allow processing of multiple rows of data from a table. There are implicit cursors used by Oracle internally and explicit cursors that are declared and opened in a PL/SQL block to process data row by row. The document provides examples of using transactions with commit, rollback, and savepoints as well as examples of using implicit and explicit cursors.
Java applets allow Java programs to run in a web browser. Applets are downloaded and run similarly to web pages. When a web page containing an applet tag is loaded, the browser downloads the applet class file from the web server and executes it within the browser's context on the client host. Applets are subject to security restrictions that prevent them from accessing local files or making network connections except back to the host from which they were downloaded.
This document discusses various ways to set and check the optimizer mode in Oracle at both the parameter and session level. It also provides examples of using EXPLAIN PLAN to view execution plans for different types of queries, examples of query transformations Oracle can perform, and tips for SQL performance tuning such as using appropriate data types in comparisons and minimizing functions in joins.
SQLAlchemy is an object-relational mapper (ORM) for Python. It provides patterns for mapping database tables to objects and vice versa. The document discusses several ORM patterns from the book Patterns of Enterprise Application Architecture including:
- Unit of Work pattern which maintains a set of objects to save in a transaction. SQLAlchemy implements this with the Session object.
- Identity Map pattern which avoids duplicate objects for the same database record. SQLAlchemy implements this with its identity map.
- Lazy Load pattern which loads relationships and columns on demand to improve performance. SQLAlchemy uses lazy loading by default.
- Other patterns discussed include foreign key mapping, association table mapping, single/class table inheritance, and how different architectural patterns
The PLSQL Language offers great possibilities. Not only in handling vast amounts of data, but also Object Oriented possibilities are present. This short introduction uses a table-API example to get familiar with the PLSQL-OO structures within the language.
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)Mark Wilkinson
IMPORTANT CORRECTION TO THIS SLIDESHOW WAS MADE August 24, 2011. How to use the Protege SADI plugin to generate SADI-compliant semantic web services. Created for the 2011 DBCLS BioHackathon. Credits to Mark Wilkinson, Benjamin Vandervalk, Luke McCarthy, Edward Kawas.
PL/SQL is a combination of SQL and procedural languages that enhances SQL's capabilities. It allows processing of SQL statements as a block. A PL/SQL block consists of optional declaration, mandatory execution, and optional exception sections. Variables, constants, records can be declared in the declaration section and used in the execution section. The execution section contains the main program logic. Exceptions are handled in the exception section. PL/SQL supports programming constructs like conditional statements and loops.
PL/SQL is a standard and portable language for Oracle Database development. If you develop a program that executes on an Oracle Database, you can quickly move it to another compatible Oracle Database without any changes. PL/SQL is an embedded language. PL/SQL only can execute in an Oracle Database.
It consists of important different concepts related to PL/SQL that are covered like the Basic structure of PL/SQL block, Variables and Constants in PL/SQL, Control Structures i.e., Conditional, Iterative, and Sequential Control, Procedure and Function, Cursors and its Types, Applications of implicit and explicit cursors, Triggers and its Types and Exception Handling.
This document discusses new features in Java 8 including stream API, lambdas, default methods, optional values, date and time API, stamped locks, concurrent adders, improved annotations, new file operations, overflow operations, and the Nashorn JavaScript engine. It provides code examples and explanations of how to use these new features in Java 8.
This document discusses retrieving data in PL/SQL. It reviews that SQL statements like SELECT, INSERT, UPDATE and DELETE can be used directly in PL/SQL code. It also notes limitations around DDL and DCL statements. The key points covered include using the SELECT statement to retrieve data into PL/SQL variables, following naming convention guidelines for variables, and organizing code into blocks to improve readability.
This document discusses explicit cursors in PL/SQL. It begins by listing the objectives of the lesson, which include distinguishing between implicit and explicit cursors, describing when to use explicit cursors, listing guidelines for declaring and controlling explicit cursors, and demonstrating how to open a cursor, fetch data into variables, loop through multiple rows, and close a cursor. It then explains the purpose of explicit cursors when a SELECT statement may return multiple rows. It discusses context areas and cursors, the limitations of implicit cursors, and shows examples of declaring, opening, fetching from, and closing an explicit cursor.
The document discusses conditional control structures in PL/SQL, specifically IF statements. It describes the basic syntax of IF statements, including the use of IF-THEN, IF-THEN-ELSE, and IF-ELSIF-ELSE structures. Examples are provided to demonstrate how conditions are evaluated and how control flow works based on whether conditions evaluate to TRUE, FALSE, or NULL. The use of logical operators and handling of NULL values within IF statements is also covered.
The document discusses the Oracle query optimizer. It describes the key components and steps of the optimizer including the query transformer, query estimator, and plan generator. The query transformer rewrites queries for better performance through techniques like view merging, predicate pushing, and subquery unnesting. The query estimator calculates selectivity, cardinality, and cost to determine the overall cost of execution plans. The plan generator explores access paths, join methods, and join orders to select the lowest cost plan.
Default methods and static methods allow interfaces to define new methods without breaking existing implementations. The lambda expressions feature introduces functional programming to Java through functional interfaces like Consumer and Function. The streams API provides a functional-style way to process and analyze collections through parallelization, optional return values, and collectors.
1. The document describes how to create and use stored procedures in Oracle, including defining parameters, parameter passing modes, and developing procedures.
2. Key aspects of procedures are that they promote reusability and maintainability, are created using the CREATE PROCEDURE statement, and can accept parameters to communicate data between the calling environment and the procedure.
3. Parameters can be defined using modes like IN, OUT, and IN OUT to determine how data is passed into and out of a procedure.
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
Lambda expressions and streams are major new features in Java 8. Lambda expressions allow treating functionality as a method argument or variable. Streams provide a new way to process collections of objects in a declarative way using intermediate and terminal operations. The document provides examples of lambda expressions, method references, functional interfaces, default methods on interfaces, and stream operations like filter, map, and reduce.
User-defined functions in SAP HANA accept parameters, perform actions such as complex calculations, and return the results. There are two types of user-defined functions: scalar and table. Scalar functions return a single value and allow only expressions, while table functions always return a table, can accept table parameters, and are read-only. Table functions are defined using SQL Script and can only contain read-only statements.
This document provides an alphabetical overview of all SAP ABAP keywords and commands. It lists keywords such as ADD, CALL FUNCTION, CASE, CHECK, CLASS and more. For each keyword, it provides the syntax and a short description of its usage in 1-3 sentences. The document appears to be an exhaustive reference list for all ABAP language elements.
PL/pgSQL - An Introduction on Using Imperative Programming in PostgreSQLReactive.IO
When you start tackling complex high-volume data problems, SQL might not be enough. When your logic needs to be close to your data, PostgreSQL has a secret weapon, PL/pgSQL. An imperative language that extends SQL, PL/pgSQL lets you execute complex read and write logic directly on the database. The benefits include increased speed and concurrency, code reuse among many applications, strong consistency guarantees, and greater query flexibility.
This presentation will show you how PL/pgSQL functions can speed up your indexes, accelerate complex queries, activate custom triggers on data changes, and handle complex write situations. Afterwards, you will be able to take control of your data directly at the source, within PostgreSQL itself.
Key points discussed:
* PL/pgSQL: what it is and why it matters
* Volatility: living in an uncertain data world
* Upserts: a little update with a little insert
* Triggers: keeping data consistent
* Code Blocks: control when you need it
SQL examples given during the presentation are available here: http://www.reactive.io/academy/presentations/postgresql/plpgsql/plpgsql-examples.zip
This document discusses PL/SQL transactions and cursors. It defines a transaction as a series of related SQL statements that are treated as a logical unit by Oracle. Transactions are committed or rolled back. Cursors allow processing of multiple rows of data from a table. There are implicit cursors used by Oracle internally and explicit cursors that are declared and opened in a PL/SQL block to process data row by row. The document provides examples of using transactions with commit, rollback, and savepoints as well as examples of using implicit and explicit cursors.
Java applets allow Java programs to run in a web browser. Applets are downloaded and run similarly to web pages. When a web page containing an applet tag is loaded, the browser downloads the applet class file from the web server and executes it within the browser's context on the client host. Applets are subject to security restrictions that prevent them from accessing local files or making network connections except back to the host from which they were downloaded.
This document discusses various ways to set and check the optimizer mode in Oracle at both the parameter and session level. It also provides examples of using EXPLAIN PLAN to view execution plans for different types of queries, examples of query transformations Oracle can perform, and tips for SQL performance tuning such as using appropriate data types in comparisons and minimizing functions in joins.
SQLAlchemy is an object-relational mapper (ORM) for Python. It provides patterns for mapping database tables to objects and vice versa. The document discusses several ORM patterns from the book Patterns of Enterprise Application Architecture including:
- Unit of Work pattern which maintains a set of objects to save in a transaction. SQLAlchemy implements this with the Session object.
- Identity Map pattern which avoids duplicate objects for the same database record. SQLAlchemy implements this with its identity map.
- Lazy Load pattern which loads relationships and columns on demand to improve performance. SQLAlchemy uses lazy loading by default.
- Other patterns discussed include foreign key mapping, association table mapping, single/class table inheritance, and how different architectural patterns
The PLSQL Language offers great possibilities. Not only in handling vast amounts of data, but also Object Oriented possibilities are present. This short introduction uses a table-API example to get familiar with the PLSQL-OO structures within the language.
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)Mark Wilkinson
IMPORTANT CORRECTION TO THIS SLIDESHOW WAS MADE August 24, 2011. How to use the Protege SADI plugin to generate SADI-compliant semantic web services. Created for the 2011 DBCLS BioHackathon. Credits to Mark Wilkinson, Benjamin Vandervalk, Luke McCarthy, Edward Kawas.
You probably think that PL/SQL is dull and ordinary programming language. Not so! Parts of it can be downright WEIRD. In this presentation, Steven offers what he considers to be some of the stranger nooks and crannies of the PL/SQL language, perhaps in the process making them a little bit less weird.
This document summarizes a presentation about using Scala with the Spring framework. It discusses how Spring's core features like dependency injection, aspect oriented programming, and service abstraction can be used with Scala. It provides examples of implementing dependency injection with both XML configuration and annotations. It also discusses how to handle callbacks when using Spring's service abstraction in Scala. Some potential issues and areas for improvement are identified, such as better support for Scala collections and implicit conversions in Spring configuration.
Absolutely Typical - The whole story on Types and how they power PL/SQL Inter...Lucas Jellema
This document discusses types in Oracle databases and how they power PL/SQL interoperability. It covers the history of types, standard types, user-defined types, collections of types, and how types can be used for structured programming, SQL and PL/SQL interaction, and interacting with external systems. It provides examples of defining types and collections, and using types and collections for object-oriented programming techniques in Oracle databases.
Object-oriented Development with PL-SQLDonald Bales
This document discusses object-oriented development with PL/SQL. It begins with an introduction to object-oriented concepts like polymorphism, encapsulation, and inheritance. It then covers how to define object types and type bodies in PL/SQL, including attributes, methods, and inheritance. It provides examples of defining constructor, member, map, and static methods. It also discusses how to declare PL/SQL variables of an object type and access object attributes and methods.
Spring Day | Spring and Scala | Eberhard WolffJAX London
2011-10-31 | 09:45 AM - 10:30 AM
Spring is widely used in the Java world - but does it make any sense to combine it with Scala? This talk gives an answer and shows how and why Spring is useful in the Scala world. All areas of Spring such as Dependency Injection, Aspect-Oriented Programming and the Portable Service Abstraction as well as Spring MVC are covered.
This document discusses SQL objects and PL/SQL datatypes in Oracle. It provides an overview of PL/SQL as an extension to SQL that allows procedural logic. It describes PL/SQL-specific and SQL object datatypes, including records, collections, and pipelined functions. It also covers SQL collection operators and comparing collections in PL/SQL.
Architecture | Busy Java Developers Guide to NoSQL | Ted NewardJAX London
2011-11-02 | 03:45 PM - 04:35 PM |
The NoSQL movement has stormed onto the development scene, and it’s left a few developers scratching their heads, trying to figure out when to use a NoSQL database instead of a regular database, much less which NoSQL database to use. In this session, we’ll examine the NoSQL ecosystem, look at the major players, how the compare and contrast, and what sort of architectural implications they have for software systems in general.
The document provides an overview of PL/SQL and server-side database programming. It discusses:
1) What PL/SQL is and how it extends SQL with programming features like variables, loops, and conditionals to allow for procedural logic on the server-side.
2) The advantages of server-side programming using PL/SQL over client-side programming, including improved performance due to reduced network traffic and ability to reuse code.
3) Key PL/SQL concepts like blocks, data types, scope rules, operators, program flow control structures, exceptions, and subprograms like procedures and functions.
This document provides an introduction to object-oriented databases (OODBMS). It discusses key concepts like objects having an identity, structure and type constructor. An OODBMS allows for complex object structures, encapsulation of operations, inheritance and relationships between objects using object identifiers. It provides advantages over traditional databases for applications requiring complex data types and application-specific operations.
itle: Glorp Tutorial
Speaker: Niall Ross
Mon, August 18, 2:00pm – 3:30pm
Video Part1: https://www.youtube.com/watch?v=cPN1A4WQyiA
Video Part2: https://www.youtube.com/watch?v=25S6cSYgh34
Abstract:
The target audience for this hands-on tutorial is those with little or no Glorp experience (but more experienced people willing to pair-program with beginners are most welcome). The tutorial will help them to start using in Glorp in their own applications.
Participants will create a simple Glorp descriptor system for a domain model. They will generate a database from it, incorporating some existing legacy. They will write and read between the database and their domain model using Glorp commands. The issues of transactions, caching and refreshing will be addressed.
Solid and Sustainable Development in Scalascalaconfjp
Kazuhiro Sera introduced several of his Scala projects including ScalikeJDBC, Skinny Framework, and AWScala. He discussed some of his philosophies for solid and sustainable development in Scala including using simplified class-based OOP with immutable data structures, avoiding overkill abstraction, writing tests without question, keeping infrastructure lightweight, and ensuring projects have no surprises for newcomers. He welcomed questions during the upcoming AMA session.
The document provides an overview of Daniel Egan's professional experience including his roles as a Microsoft Regional Director, Microsoft MVP for ASP.Net, Chief Architect at Odyssey Consulting Group, author, instructor, and his involvement with various .Net user groups. It then outlines topics to be covered including object relational mappers, language enhancements in VB.Net and C# 3.0, LINQ and LINQ to SQL.
Introduction to Spark Datasets - Functional and relational together at lastHolden Karau
Spark Datasets are an evolution of Spark DataFrames which allow us to work with both functional and relational transformations on big data with the speed of Spark.
The document discusses PXB (Perl XML Binding), a module that generates Perl API classes from XML schemas, allowing XML documents to be easily mapped to and from Perl data structures. It outlines the motivations for PXB, describes its data model and how the API is built, and discusses features like SQL mapping, logging, and testing. Problems encountered include dependency failures and performance issues that are being addressed through optimizations and alternative parsing approaches.
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesCHOOSE
The document discusses various ways to map between different data models representing company structures, including:
- Serializing Java objects to an XML or binary format
- Using JAXB annotations to map between XML and Java classes
- Generating Java classes from an Ecore metamodel
- Specifying Hibernate mappings between Java classes and relational database tables
- Directly mapping between relational tables and Java classes with Hibernate
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesCHOOSE
Ad
Oracle Objects And Transactions
1. Oracle Objects and Transactional Systems Andrea Parrilli Oracle and Java Developer [email_address]
2. Topics - OID and Primary Key - REFs and Foreign Keys - Substitutability - Collections - Type evolution - Encapsulation - Inheritance - Polymorphism - Identity Objects for storage OOP in Oracle Objects as a developer tool - Casting - Static - References
3. OOP in Oracle - Not really available - Objects must be storable - Not exactly as column security GRANT … ON <table>(<list of fields>) … - Different scopes: “user scope” vs. “code scope” Who's asking (authorized user vs. unauthorized user) vs. Where are we (local vs. global context) Encapsulation - Single inheritance - No abstract types: just declare the type [NOT] INSTANTIBLE If a non implemented method is called then ORA-04067 - Extendability declared through [NOT] FINAL Inheritance
4. OOP in Oracle - Compile or Runtime - Overriding: Specialize subtypes methods - Overloading: Specialize methods on input parameters: available since the beginning in PL/SQL - Dynamic method dispatch: at runtime the right method is chosen depending on the object type Polymorphism Select case when T. shape is of ( MyCircleType ) then 'MyCircleType' when T. shape is of ( MyRectangleType ) then 'MyRectangleType' end SubType, T. shape . area () Area from MyShapeTab T SUBTYPE AREA --------------- ---------- MyCircleType 3,14 MyRectangleType 200
5. OOP in Oracle create or replace type MyShapeType as object ( Color varchar2(10), member function area return number ) not final instantiable; create or replace type MyCircleType under MyShapeType ( Radius number, Overriding member function area return number ) not final; create or replace type body MyCircleType is Overriding member function area return number is begin return 3.14*Radius*Radius; end; end; create or replace type MyRectangleType under MyShapeType( SideA number(8), SideB number(8), overriding member function area return number ) not final; create or replace type body MyRectangleType is overriding member function area return number is begin return SideA*SideB; end; end; create table MyShapeTab(shape MyShapeType); insert into MyShapeTab values(MyCircleType('blue', 1)); insert into MyShapeTab values(MyRectangleType('red', 10, 20)); commit;
6. OOP in Oracle Relational approach to represent many types - One table per type (too many tables, complex queries, difficult maintenance ) - One table to store type metadata, one or more tables to store instances' values (slow method, many joins, application can corrupt data) Object Relational approach to represent many types - One object relational table per type function (business related) - allows better performance than the “melting pot” approach, neater design - Accurate storage design (see substitutability) - More logic inside database objects - Less database objects to maintain
7. OOP in Oracle Reflection - First cited in 1982, B. C. Smith - Widely available in interpreted languages with easy interfaces - In databases since first design (dictionary) - DBMS_METADATA package, we can get XML representation of any DB object, then parsing is needed (still too complicated to be widespread tool) Identity - in OOP objects are always strong entities (every instance has its own pointer, cloning must be explicitly declared): always passed by reference. - in OOP programmers do not usually care to define a “primary key” - in DB entities are weak by default, can be made strong - to implement object identity and referencing Oracle provides OID (Object Identifier), and REFs. - this is tricky! In OOP when we want to compare two instances we can do it on an object level (comparing pointers) or on a value level (comparing attributes). Oracle uses only the pointers (the OID) to compare objects when replicating, so when updating an object we must take care not to substitute it but change the attributes values (see replication guidelines)
8. OOP in Oracle OID - Can be Oracle-managed - RAC-wide 16 bytes unique identifier - or Primary key based (uses as much space as the PK) REF - Unscoped REF: OID plus DB-object-id - Scoped: just the OID - Unscoped with ROWID: unscoped REF plus 10 bytes ROWID hint. This is a violation of the relational paradigm! Can lead to disrupted ROWIDs: ANALYZE … VALIDATE REF Referential integrity - REFs are not Foreign Keys: you have to define and enforce them by yourself, a disrupted reference is said to be “dangling” ANALYZE … UPDATE SET DANGLING TO NULL
9. Objects as a programming tool Object support is available in SQL and PL/SQL SQL: downcasting (narrowing) CREATE TABLE shapes OF MyShapeType; INSERT INTO shapes VALUES(mycircletype('red', 33)); INSERT INTO shapes VALUES(myrectangletype('blue', 11, 22)); SELECT TREAT(VALUE(s) AS MyCircleType).radius FROM shapes s ORDER BY 1 NULLS FIRST; TREAT(VALUE(S)ASMYCIRCLETYPE).RADIUS ------------------------------------ 33 TREAT will return null if the argument is not in the lineage of the destination type. In SQL method calls on nulls are null! Quite different from Java ... But in PL/SQL access into null exception is risen
10. Objects as a programming tool Object support is available in SQL and PL/SQL SQL: upcasting (widening) is implicit Note that when a field is not substitutable the insertion of a subtype, even upcasted, will generate an error! CREATE TABLE abstract_shapes OF MyShapeType NOT SUBSTITUTABLE AT ALL LEVELS; SQL> INSERT INTO abstract_shapes 2 SELECT TREAT(VALUE(s) AS MyShapeType) FROM shapes s; SELECT TREAT(VALUE(s) AS MyShapeType) FROM shapes s * ERROR at line 2: ORA-00932: inconsistent datatypes: expected - got UDT
11. Objects as a programming tool CREATE OR REPLACE TYPE superclass AS OBJECT ( sup NUMBER, CONSTRUCTOR FUNCTION superclass RETURN self AS RESULT, MEMBER PROCEDURE init_superclass(self IN OUT NOCOPY superclass), NOT FINAL MEMBER FUNCTION do_something RETURN NUMBER ) NOT FINAL INSTANTIABLE; PL/SQL: Example
12. Objects as a programming tool CREATE OR REPLACE TYPE BODY superclass IS CONSTRUCTOR FUNCTION superclass RETURN self AS RESULT IS BEGIN self.init_superclass(); RETURN; END superclass; MEMBER PROCEDURE init_superclass(self IN OUT NOCOPY superclass) IS BEGIN self.sup := 33; END; NOT FINAL MEMBER FUNCTION do_something RETURN NUMBER IS BEGIN return self.sup; END do_something; END;
13. Objects as a programming tool CREATE OR REPLACE TYPE subclass UNDER superclass ( sub NUMBER, CONSTRUCTOR FUNCTION subclass RETURN self AS RESULT, MEMBER PROCEDURE init_subclass(self IN OUT NOCOPY subclass), OVERRIDING MEMBER FUNCTION do_something RETURN NUMBER, MEMBER FUNCTION only_sub RETURN NUMBER ) FINAL INSTANTIABLE;
14. Objects as a programming tool CREATE OR REPLACE TYPE BODY subclass IS CONSTRUCTOR FUNCTION subclass RETURN self AS RESULT IS BEGIN self.init_superclass(); self.init_subclass(); RETURN; END subclass; MEMBER PROCEDURE init_subclass(self IN OUT NOCOPY subclass) IS BEGIN self.sub := 11; END init_subclass; OVERRIDING MEMBER FUNCTION do_something RETURN NUMBER IS BEGIN RETURN self.sub; END do_something; MEMBER FUNCTION only_sub RETURN NUMBER IS BEGIN RETURN 77; END only_sub; END;
15. Objects as a programming tool DECLARE o superclass := new subclass(); –- sub=11, sup=33 BEGIN -- this will genereate an error -- dbms_output.put_line('sub=' || o.sub); dbms_output.put_line('sub=' || TREAT(o AS subclass).sub); -- these will generate an error too -- dbms_output.put_line('only_sub(): ' || o.only_sub()); dbms_output.put_line('Overridden as superclass: ' || TREAT(o AS superclass).do_something()); dbms_output.put_line(o.do_something()); END; sub=33 Overridden as superclass: 33 33 PL/SQL procedure successfully completed.
16. Objects as a programming tool Static scope - Can define static methods, when the the object context is not needed, this slightly improves performance - Static properties are forbidden: objects must be storable Where to store static properties? The dictionary? What with old instances? Problems ... Application design should be very accurate on how to manage them. Although something like “VOLATILE” property, not stored but used in internal mechanisms of the class could be useful, for example to use PL/SQL types, and from that to STATIC VOLATILE, there is not this much distance When a static scope is needed use a package, they very look like singletons of purely static classes.
17. Objects as a programming tool REF in PL/SQL DECLARE R REF MyClass; S MyClass := new MyClass(33, 11); BEGIN R := REF(S); … This simply won't work: a REF is not a pointer in memory or an object id as in PHP or Java. It rather is a pointer to the storage area where the object - is held. How do I share the same object between two classes? As far as I know you can't: - NOCOPY is just an hint; - even if it was always applied we miss something like RETURN NOCOPY - default is cloning, copying
18. Objects as a programming tool How to build a session-scoped service class? Instead of storing the service classes (can be very complicated and will introduce many nested tables and object tables just to hold few instances, or just one) and getting a REF to it, may be advisable to use packages in the way the Oracle framework ( DBMS_* , UTL_* , etc.) is programmed. - Get a service id from the package: this correspond to getting an instance of the service class through a Factory. To program this in PL/SQL is easy: every instance property becomes a TABLE OF <that_property_type> INDEX BY PLS_INTEGER , the latter is the service id and even if said property is itself a table, it would work anyway, because a table is a valid base type for a PL/SQL table. - In every service call include the service id: in an OO language this is done by the compiler when you invoke a method on an instance: obj.method(param) -> method_proc(&obj, param); - Share the service id with all the components needing it as you would share an instance of the class; - Upon termination release the resources!
19. Objects as a programming tool How to build a instance -scoped service class? Business Delegate pattern - One session runs the service (server, BusinessService) - Others access this service by means of a stub, the BusinessDelegate, which in turn exposes all the relevant business methods, and instead of executing their logic locally, simply invoke the server’s methods over a link. - The only logic needed in the business delegate is the use of LookupService to get the link to forward the messages to the server and get back the response. On single instances Pipes (DBMS_PIPE) are an excellent link and Lookup. All the logic can be coded in just one package!
20. Objects as a programming tool Object Types are tensors (as opposed to scalars) and as such they do not have a predefined ordering in their dominion. To provide this ordering we may define an ORDER or MAP method (not both) in the type to provide ordering: the first performs the comparison in the method body itself returning 1, 0 -1 depending on the comparison outcome (>, =, <) and this opacity implies the optimizer has limited freedom of organizing the sort process other than nested looping on the entries; the second method, instead, maps the object to a scalar value allowing for hash sorts. Thus it is recommended to define, when possible, a MAP method rather than an ORDER. Ordering Objects
21. Object Storage Two kinds of table in Oracle: Relational and Object Relational (OR) CREATE TABLE object_relational OF <some_type> (R) CREATE TABLE relational (some_type <some_type>) OID and PK CREATE TABLE Person OF Person_o ( CONSTRAINT person_pk PRIMARY KEY (tax_id) … ) OBJECT IDENTIFIER IS PRIMARY KEY; Indeed even if a primary key is defined, you can keep the generated OID as object identifier. This could be the case when your primary key is bigger than 16 bytes. But design consideration could require the usage of a PK anyway, as OIDs are opaque.
22. Object Storage REFs and scoping One Experiment is lead by a Scientist which is in turn a Person. Also Technician-s and Employee-s are Person-s. Rather than store all the Person type instances in a Person OR table, we choose to store them separately, in Technician, Employee and Scientist Entities CREATE TABLE Experiment OF Experiment_o ( sci_leader SCOPE IS Scientist … ); CREATE TABLE Experiment OF Experiment_o ( sci_leader WITH ROWID … ); Note the fields are defined in the type while the storage properties are specified in the corresponding OR tables. This REF is efficiently stored and uses the fastest indexes SCOPED WITH ROWID is not supported. Note none of the two ways is enforcing referential integrity
23. Object Storage REFs and Foreign Keys CREATE TABLE Experiment OF Experiment_o ( sci_leader SCOPE IS Scientist … CONSTRAINT experiment_sci_leader_fk FOREIGN KEY sci_leader REFERENCES Scientist ... ); Triggers and Check Constraints - Triggers on Object Relational tables work in the same way they do on Relational tables - Cannot define a trigger on a Nested Table - DEREF is forbidden in Check Constraints
24. Object Storage SQL> desc myshapetab Name Null? Type -------------------------- -------- ---------------------------- SHAPE MYSHAPETYPE SQL> set describe depth all SQL> desc myshapetab Name Null? Type -------------------------- -------- ---------------------------- SHAPE MYSHAPETYPE MYSHAPETYPE is NOT FINAL COLOR VARCHAR2(10) METHOD ------ MEMBER FUNCTION AREA RETURNS NUMBER Getting Information on Types
25. Object Storage select name, length, precision# from sys.col$ where obj# = (select object_id from user_objects where object_name = 'MYSHAPETAB'); NAME LENGTH PRECISION# ------------------------------ ---------- ---------- SHAPE 256 SYS_NC00002$ 16 SYS_NC00003$ 10 SYS_NC00004$ 22 SYS_NC00005$ 22 8 SYS_NC00006$ 22 8 How is Oracle storing Objects? (1) - A virtual column; - 16 bytes OID of the object; - 10 bytes for the color field in the base class MyShapeType; - 22 bytes for the unconstrained number MyCircleType.radius; - 2x22 bytes for the constrained sides of MyRectangleType; - Not shown here are also a small amount of space (usually one bit from v10 on) to represent the nullity of an Object (as opposed to an Object with all null attributes) and the TYPE_ID hidden column, varying from 1 to 4 bytes, to record the actual subtype stored.
26. Object Storage How is Oracle storing Objects? (2) If we do not specify otherwise Oracle is representing the whole type hierarchy originating from the base type of the table in the table itself so that it can accommodate indifferently objects of all the types into it. Every sibling in the hierarchy is using a projection of the table, ignoring its siblings' properties
27. Object Storage Oracle offers an option to restrict the substitutability on one object column to one specific type via the predicates [NOT] SUBSTITUTABLE AT ALL LEVELS and IS OF (ONLY <type>). Controlling Object Storage create table MyShapeNotSubs of MyShapeType not substitutable at all levels; insert into myshapenotsubs values (mycircletype('INDIGO', 22)) * ERROR at line 1: ORA-00932: inconsistent datatypes: expected - got UDT select name, length, precision# from sys.col$ where obj# = (select object_id from user_objects where object_name = 'MYSHAPENOTSUBS'); NAME LENGTH PRECISION# ------------------------------ ---------- ---------- SYS_NC_OID$ 16 SYS_NC_ROWINFO$ 1 COLOR 10
28. Object Storage The importance of substitutability derives also by the fact that whenever a subtype is added to the hierarchy, all the tables having substitutable columns of the supertype's type are altered to accommodate the new subtype's attributes. Also when a subtype is dropped, the VALIDATE option removes the subtype's column from all the relevant tables. This can be accomplished after type evolution by the use of ALTER TABLE ... UPGRADE Notes on Object Storage Table-wide substitutability clauses are incompatible with more fine grained COLUMN <column> IS OF … And for object tables turning off all substitutability means even object aggregated under the table type are not substitutable. See next page
29. Object Storage CREATE TYPE aggregated AS OBJECT (shape myshapetype) NOT FINAL INSTANTIABLE; CREATE Type aggregated_sub UNDER aggregated (circle mycircletype) FINAL INSTANTIABLE; CREATE TABLE aggregate_sub_t OF aggregated_sub NOT SUBSTITUTABLE AT ALL LEVELS; SQL> insert into aggregate_sub_t values ( 2 myshapetype('RED'), mycircletype('BLUE', 33)); 1 row created. Notes on Global Substitutability SQL> insert into aggregate_sub_t values ( 2 mycircletype('RED', 44), mycircletype('BLUE', 33)); mycircletype('RED', 44), mycircletype('BLUE', 33)) * ERROR at line 2: ORA-00932: inconsistent datatypes: expected MONDO.MYSHAPETYPE got MONDO.MYCIRCLETYPE
30. Object Storage They model a Weak Entity. Have you ever seen one? If you have information in your DB then you are going to query it. Nested tables and Varrays - nested tables have no theoretical upper bound while varrays are fixed length lists; - nested tables are stored in another table than the one using them, thus implicitly generating a JOIN operation at query time. Varrays are stored inline (if they fit the maximum atomic column length of 4000 bytes) as raw value or, if bigger, as LOBs (beware if using clustered tables, LOBs are not supported) with less overhead than nested tables. Their manipulation, on the contrary, is more heavy since their update involves the substitution of the entire collection with the updated one, while nested tables are manipulated row by row. - Nested tables can be manipulated by SQL while varrays can't. You can ask a varray if it contains a value but you cannot add one without a little PL/SQL (working with types this isn't such a big deal); - Ordering: nested tables do not define any intrinsic ordering, while varrays are inherently ordered collections; Differences
31. Object Storage - Nested tables add a 16 bytes unique RAW key to the parent table, key which is stored on the nested table to perform joins, called NESTED_TABLE_ID. Beware, Oracle does not create an index on the storage table for the NESTED_TABLE_ID! - - Every nested table in a table adds its own unique key, which is a waste of space - Nested tables cannot be directly referenced by Queries (without tricks) - You cannot define foreign keys or triggers on them Nested Tables Cons Nested Tables Pros - Optimization hint: RETURN AS VALUE/LOCATOR. In the first case the nested table data is fetched and sent along with the query data, in the second only a pointer to that data is sent to the application, and the access to that data triggers the fetch of the actual content (like a REF CURSOR, or a LOB with RETURN AS LOCATOR). - Can be made IOT: after all their use case is navigation from parent to children ...
32. Object Storage Once an Type has a dependency it is no more replaceable. This is because Objects must be storable, thus dropping and recompiling would mean leaving all the tables with old instances without a definition. They can be altered like a table with same attributes and the substitutability, extendability and instantiability can be modified. Methods and constructors signatures can be modified. All method implementations (the type body) are freely modifiable Type Evolution - Unlike OO languages classes, changing a type is way more difficult than just recompiling the class! - Changing a type has potential effects on many tables: must be done carefully. This latter problem is not really a problem if seeing the question from the data model point of view. If you need a new attribute to describe an entity then you have to add it whenever the entity appears. In an OR design you can do it by changing the type definition, while in a pure Relational design you have to manually change all the occurrences of that type.
33. Conclusions - In PL/SQL units, as a support tool to define PL/SQL tables - In tables to optimize navigation: REF WITH ROWID - In tables to neatly define your data model - In tables to support common mechanisms for auditing, historical queries, ... When/where to use Objects? - To program frameworks or services - To implement a full OR schema using nested tables - Nested tables are bad. Use standard tables instead or varrays if they fit and updates are infrequent It is true OR database design is nearer to the applications' way of representing and manipulating data, but applications change over time, data stands (T. Kyte) When/where to use Objects? When/where NOT to use Objects?
#3: Glossary and Abbreviations: Type (Class): the “description”, of a functional unit loosely coupled to other functional units which includes attributes describing its state and methods changing that state. If the “building instruction” aren’t detailed enough to allow someone to actually build and use the type, then it is said to be an abstract type . Instance of a Type (Object): one example of the type, a concrete object built following the instructions given in the type definition. Member: if talking of a specific type instance then a member is any of its attributes or methods, if talking of a type as a set, then members are instances of that type. R: concerning the relational tables. OR: Object relational, concerning the representation of objects by means of a relational database.
#4: Encapsulation A feature that hides the complexities of a type from the user’s point of view. Ex. The user is usually interested in driving a car, not to detail how pushing the brake pedal is increasing the pressure on the brake primary oil circuit, which moves a membrane in a servo-mechanism, which multiplies the exertion etc. In Oracle this feature is not available, and for a reason, I guess: object must be storable as they are and encapsulation would imply the inaccessibility from the “ouside of the object” of some properties, but for this purpose there is already the column based security: GRANT … ON <table>(<list of fields>) … which is way more fine grained than the access modifiers in common OO languages (except, for example, the C++ family which has the concept of “friend” types), and yet is lacking the concept of local vs. global context opposition: the gobal context is seeing the type from the outside, which is the standard point of view of a User in Oracle, so it ignores protected and private members, while the local context is the one of a method executing on the type, which exists only inside the type methods. Unless another kind of privilege (local_context?) is created there would be no way to access the local information. Thus all attributes and methods are implicitly public. Inheritance Inheritance is the property of classes which allow them to be specified at different levels of abstraction, from the most abstract level to most practical one. Ex. A MeanOfTransportation is an abstract type for sails, trains, planes, cars, … the next level may be “Vehicle” which includes cars, TIRs, Trikes, …, then we have the Car (Audi, Fiat, VW, …) which includes all the specifics of any single model, then we have MyCar, which is able to refuse to start when it’s too cold and reproduces the characteristic shrieks whenever the doors are open. Here we do not discuss the multiple inheritance (as is in C++, for example) because in the database technology it has more downsides than benefits and as such it is luckily not present in Oracle’s implementation. In Oracle there is full support for Inheritance but for what concerns abstract types as they are called in OOP there is a catch: Oracle calls Abstract Data Type (Objects, available from version 8i) the ability to create a type (as in OOP) without methods. This is not compliant with OOP, as Abstract Types in that context are types in which at least one method is only specified by signature, and are by default not instantiable. Yet it is possible to declare “incomplete types” in Oracle just declaring the type specification, with the method’s signatures and making them INSTANTIABLE . You can instantiate an object of that type, create object tables of it but you cannot call the unimplemented methods (ORA-04067). This is quite a different concept of Abstractness, but it’s compatible with the old ADTs without hindering the usage of this features by programmers. Inheritance is achieved by the use of the keyword UNDER for types which are NOT FINAL . The meaning of FINAL is the same as in Java, it means “not extendable” thus you cannot derive a subclass from a FINAL type.
#5: Polymorphism Polymorphism is a wide and polymorphic concept. It refers to the ability of referring to some logic leaving to the internal mechanism of the language the actual implementation executed. Usually two different kinds of polymorphism are recognized: overriding and overloading , both can be available at runtime or compile time (with the first widely more useful than the second). Overriding allows one subtype to redefine a NOT FINAL method of one of its superclasses (through the use of OVERRIDING ), thus allowing the programmer to specialize the logic for the specific subclass. Overloading instead allows to have the same logic implemented in different ways for different input parameters. One example is the ability of operators like ‘+’ to sum up integers and floating point numbers. These concepts are often associated with the Dynamic Dispatch mechanism in which it is the object, at runtime, who chooses the fitting method to execute in a call. Following we see an example of overriding (Oracle developers already know very well the overloading, as procedures and packages allow a great deal of it) in the implementation of the method area() in the subclasses of MyShapeType .
#6: see http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1545206281987 ) drop table MyShapeTab ; drop type MyCircleType; drop type MyRectangleType; drop type MyShapeType; create or replace type MyShapeType as object ( Color varchar2 ( 10 ), member function area return number ) not final instantiable; / create or replace type MyCircleType under MyShapeType ( Radius number , overriding member function area return number ) not final; / create or replace type body MyCircleType is overriding member function area return number is begin return 3.14 *Radius*Radius; end; end; / create or replace type MyRectangleType under MyShapeType( SideA number(8) , SideB number(8) , overriding member function area return number ) not final; / create or replace type body MyRectangleType is overriding member function area return number is begin return SideA*SideB; end; end; create table MyShapeTab (shape MyShapeType); insert into MyShapeTab values(MyCircleType( 'blue' , 1 )); insert into MyShapeTab values(MyRectangleType( 'red' , 10 , 20 )); commit; select case when T.shape is of (MyCircleType) then 'MyCircleType' when T.shape is of ( MyRectangleType ) then 'MyRectangleType' end SubType, T.shape.area() Area from MyShapeTab T SUBTYPE AREA --------------- ---------- MyCircleType 3,14 MyRectangleType 200
#7: The given example could be easily extended to represent hundreds of different shapes without changing (at least, changing explicitly) the storage structure of data. With a traditional Relational approach, the standard to represent different types is to create one table per type and then unite them as needed in every query. The query to find which shapes are of a given color would be, for example, very lengthy and would require to be changed every time a new type of shape is introduced. Without considering the problem of indexing: in that case the query would access one index for every type, instead with the OR (Object Relational) we have only one index. About this topic we see the syntactic difference between Relational and Object Relational tables. If we want to create said index on the shape’s color we have to be coherent with the point of view we choose: in our example create index shape_color_idx on MyShapeTab(color); would return, as expected, ORA-00904: &quot;COLOR&quot;: invalid identifier . That’s because we created MyShapeTab as Relational table with an Objects as column, so the right way would be create index shape_color_idx on MyShapeTab(shape.color); If we stick to OR model we would have created the table like this: create table MyShapeTab2 of MyShapeType; so that the first create index would have worked.
#8: Identity This is again an aspect of OOP too often overlooked as it’s available since the beginning of information technology: Objects are, to use the Relational jargon, Strong entities, that means they are uniquely identifiable, they are individuals, when they are manipulated it is a single place where the changes take place. In databases technology there is big behavioral difference between strong and weak entities, which is the existence of a primary key, but more generally speaking it is always possible to treat a strong entity as it was week (just disable the PK), on the contrary not always it is possible to make strong a weak entity. This translates in current programming languages to the difference between “by value” and “by reference” parameter passing, or an object and a pointer to that object. The importance of strong entities is so high that many of the most common programming languages nowadays do have only references to objects and the occurrence of “weakification” is usually marked by some special construct signaling the occurrence of a cloning operation. As stated before databases know very well this mechanism, but since the introduction of ADT the granularity of this composition relations changed, if before it went down from the Entity itself (Strong or weak depending on the presence of a PK) to one primitive type (weak), now it can stop in the middle, at a level which aggregates many columns together. Of course Primary Keys can be the answer, but it is not common in OOP to identify, or even to care for that, identity and uniqueness are given as tool from the very foundations of the metamodel. To provide such identity in an OR way Oracle has the REF. The REF is build upon the OID (Object IDentifier) which in turn can be generated and maintained by the engine or PK-based. In the first case the OID is a 16 bytes raw value uniquely generated and accurately kept unique through distributed or replicated environments (replicated environments are especially vulnerable to object “failures”, there are a set of guidelines on how to work on objects to make replication work correctly – we won’t talk about this), in the second case (pkOID) it has the same properties as the PK.
#9: There are essentially three kinds of REFs: Scoped : the REF is pointing to an object on a specific table. It occupies as much as the OID does. Example: you have person objects references somewhere, but on the base you use them to represent both users and managers . You can leave it unspecified, and let the REF itself carry the information about which table is storing the object (unscoped REF), or specify in the definition of the REF which table stores the referenced object. Unscoped : the REF has two parts, the OID of the referenced objet and the OID of the object in which it is stored, another 16 bytes. Oracle recommends to use scoped REFs whenever possible, because they are stored more efficiently and guarantee a little better performance. Unscoped with ROWID hint : to the standard unscoped REF the ROWID of the referenced object is added, another 10 bytes. So in the worst of situations and unscoped with rowid ref will be 36 bytes long. In the relational theory the concept of a “pointer” is forbidden for the reason that the relational schema must be independent of the underlying physical organization of data, instead primary keys (the logic part) and indexes (taking care of the connection between model and physical layer) are provided. The presence of the ROWID can improve object navigation at the expense of more space utilization but is prone to disrupt the integrity of data when rows migrate, for whatever reasons, and as with any composition relation, if not enforced by constrains, the REF itself can be dangling, i.e. referring to a non-existent object on the referenced object table. For what concerns the ROWID hint, Oracle always checks if the ROWID points to the OID it has on the REF and if not it reverts to the OID index, for dangling REFs instead, there is nothing to do except the good practice of defining and enforcing a foreign key. To maintain REFs Oracle supplies the command ANALYZE … VALIDATE REF UPDATE SET DANGLING TO NULL, where the first part fixes the ROWID hints where needed.
#15: Note: we include as the first parameter an instance of the same class by reference (NOCOPY), this is because the engine is by default applying the methods on a copy which is then returned back. The self keyword is like this in C++-like languages, and it has nothing to do with PHP’s self static scope qualifier.
#16: Upcasting is automatic, downcasting to access subclass' methods behaves as expected, but upcasting doesn't work on overridden methods! I've tested this on Windows, 10.2.0.1.0 and 11.1.0.6.0.
#17: Static You can declare static methods and call them prefixing the type name. They follow the same rules as static methods in all the other OO languages. Static properties are forbidden instead, as they pose a number of logic problems, in facts they are class’ properties as opposed to instance’ properties. Thus they should be stored in the dictionary along with the structure of the class. But what then about already stored instances when these static properties change? Imagine what to do when you retrieve two instances with two different values ... When static properties are needed then you may consider using a package to hold them. Indeed packages have the same properties as OOP classes with all static methods and fields.
#18: Note: we include as the first parameter an instance of the same class by reference (NOCOPY), this is because the engine is by default applying the methods on a copy which is then returned back. The self keyword is like this in C++-like languages, and it has nothing to do with PHP’s self static scope qualifier.
#22: Essentially there are two kinds of table in Oracle: Relational and Object Relational. (OR) CREATE TABLE object_relational AS TABLE OF <some_type> (R) CREATE TABLE relational (some_type <some_type>) When you define an OR table there are some important aspects to keep in mind. OID and Primary Keys Every object must have a unique identifier and if the developer does not specify it then Oracle assigns one 16 bytes long of its choosing. You can specify yourself which primary key constitutes the Object ID (called pkOID) and save some space on the table and on the OID indexes. CREATE TABLE Person OF Person_o ( CONSTRAINT person_pk PRIMARY KEY (tax_id) … ) OBJECT IDENTIFIER IS PRIMARY KEY; Indeed even if a primary key is defined, you can keep the generated OID as object identifier. This could be the case when your primary key is bigger than 16bytes.
#23: When you need to store a REF or pkREF you should always scope it unless the scattering of references on many entities is really a feature of your model. Ex: one Experiment is lead by Scientist which is in turn a Person. Also Technician-s and Employee-s are Person-s. Rather than store all the Person type instances in a Person OR table, we choose to store them separately, in Technician, Employee and Scientist Entities. The Experiment table, OR table for Experiment_o types, for the sci_leader field should look like CREATE TABLE Experiment OF Experiment_o ( sci_leader SCOPE IS Scientist … ); given Experiment_o type has a field sci_leader of type Person. If facts there is no purpose allowing references to Person-s which are not scientists. Note the fields are defined in the type while the storage properties are specified in the corresponding OR tables. This REF is efficiently stored and uses the fastest indexes. If conditions suggest those indexes won't be fast enough, you can choose CREATE TABLE Experiment OF Experiment_o ( sci_leader WITH ROWID … );
#24: Check Constraints and Triggers There is full freedom of declaring constraints on object properties on OR tables as we do on R tables. The only limit on Check Constraints is they cannot use DEREF (the action of getting the actual object from its REF) or any nested table construct (plus standard limitations on check constraints). Triggers can be defined on object tables as well, but not on the storage table for nested tables.
#26: The type_id, when queries are frequently considering this field (through the use of IS OF predicate), can be indexes, and being usually at very low cardinality is an excellent candidate for a bitmap index. Given an object its type_id is accessible through the SYS_TYPEID() function.
#27: Imagine a real world hierarchy and the storage structure generated by such a metamodel! That would be a disaster, ending up with just one huge table per root type. This originates from the OO metamodel that considers inheritance an “is of” relation, so that a subtype is always substitutable in place of a supertype because the subtype is also all its supertypes. The way oracle represent hierarchies is not the only way, but is one simple and fast enough to be practical; another approach could be one table per type-slice, that is all the successive descendants properties of a type find place in a separate table. This produces smaller tables overall and smaller storage, but needs a number of joins to retrieve just one object. Impractical. Another approach is the LOB or XML approach in which the object is rendered through some middleman language (XML). This last approach would be really interesting to test in Oracle due to all its XML oriented features.
#32: Nested tables add a 16 bytes unique RAW key to the parent table, key which is stored on the nested table to perform joins, called NESTED_TABLE_ID. Beware, Oracle does not create an index on the storage table for the NESTED_TABLE_ID! Every nested table in a table adds its own unique key, which is a waste of space, but it has an optimization hint: RETURN AS VALUE/LOCATOR. In the first case the nested table data is fetched and sent along with the query data, in the second only a pointer to that data is sent to the application, and the access to that data triggers the fetch of the actual content. Nested tables, being tables, do have all the possible creation options of any table, for example they can be made Index Organized. If you consider the kind of model in which a nested table is used, a parent-child relation, in which the direction of navigation is from parent to child, we see that we are by design fetching for every parent row all the child rows on the nested table. If we can suppose the nested table has “short” rows, then this is pretty much the use case for IOT A limitation is that you cannot define foreign keys on nested table, or query directly from them (without using dirty tricks), although you can create indexes on them.
#33: Type Evolution (Altering Types) The OR paradigm imposes many constraints on the horizon of possibilities, mainly because it follows a strict logic around type hierarchies. For example, once a type (its specification only! The body is totally encapsulated inside the type) has a dependent object it is non-droppable and non-replaceable. It is alterable though. In general you can (from v.9 on): add and drop attributes and methods: when adding an attribute to a type with subtypes consider that all the default constructors of the subtype will suffer a parameter shifting due to the implicit ordering of arguments because the superclass' attribute always precede the subclass' – another good reason to add user defined constructors. enlarge an attribute; modify final and instantiable predicates; modify nested collections' properties. But consider that as well as with tables types do have dependencies and before evolving a type is a good idea to apprehend its dependencies. This is usually the reason scaring DBAs from allowing OR features in their DB. Some operations are in facts more complicated and involve more steps, at first glance, than standard relational table maintenance. But if you consider the relations of data from the business point of view the amount of effort to change the model is the same, the only difference is that using the OR metamodel a greater part of that logic is transferred to the data model itself, thus making its change a bit more complex. Please refer to Database Application Developer's Guide - Object-Relational Features, c. 7 for an introduction on the topic.