Лекции.Орг


Поиск:




Категории:

Астрономия
Биология
География
Другие языки
Интернет
Информатика
История
Культура
Литература
Логика
Математика
Медицина
Механика
Охрана труда
Педагогика
Политика
Право
Психология
Религия
Риторика
Социология
Спорт
Строительство
Технология
Транспорт
Физика
Философия
Финансы
Химия
Экология
Экономика
Электроника

 

 

 

 


Inheritance for object types




Oracle first introduced the object type (the closest that Oracle comes to a "class" in the, ahem, classical sense of object orientation) in Oracle8, but it was plagued by a severe lack of standard object functionality, most notably inheritance.

In Oracle9i, you can now define a hierarchy of object types in which the attributes and methods of a supertype are inherited or overwritten by the subtype. The following three object type specification definitions offer a simple example of such a hierarchy (in which food is the root, desserts are types of food, and cakes are types of desserts).

CREATE TYPE food_t AS OBJECT (name VARCHAR2(100), food_group VARCHAR2 (100), grown_in VARCHAR2 (100), MEMBER FUNCTION price RETURN NUMBER) NOT FINAL;/CREATE TYPE dessert_t UNDER food_t (contains_chocolate CHAR(1), year_created NUMBER(4), OVERRIDING MEMBER FUNCTION price RETURN NUMBER) NOT FINAL;/CREATE TYPE cake_t UNDER dessert_t (diameter NUMBER, inscription VARCHAR2(200) -- The cake_t type has no distinct pricing calculator.);/

Notice that the dessert_t type overrides the root's price function, but the cake_t type inherits the price function from dessert_t.

With inheritance, there is now a much more compelling reason to give object types a serious evaluation for use in your applications. You can find out more about object types and inheritance in Chapter 21.

1.4.2.5 Enhancements to PL/SQL collections

PL/SQL collections are array-like structures that allow you to maintain lists of information. These lists can be of simple data, such as strings, or more complex structures, such as records. In Oracle9i, Oracle extends the features of collections with two major enhancements:

· Support for multiple-level collections (i.e., collections within collections).

· The ability to index the contents of one type of collection (associative arrays, previously known as index-by tables) by strings as well as integers.

Here is an example of using strings for the index values or row numbers in a collection:

DECLARE TYPE population_t IS TABLE OF NUMBER INDEX BY VARCHAR2(64); country_population population_t; continent_population population_t; howmany NUMBER; row_id VARCHAR2(64);BEGIN country_population('Colymphia'):= 100000; country_population('Ribalizia'):= 750000; howmany:= country_population('Colymphia'); row_id:= continent_population.FIRST; DBMS_OUTPUT.PUT_LINE (continent_population(row_id));END;/

Multi-level collections allow us to emulate N-dimensional arrays and, more generally, model arbitrarily complex data. For more information about these new collection features, check out Chapter 11.

1.4.2.6 Native compilation of PL/SQL code

Prior to Oracle9i, compilation of PL/SQL source code always results in a representation (usually referred to as bytecode) that is stored in the database and is interpreted at runtime by a virtual machine implemented within Oracle that, in turn, runs natively on the given platform. Oracle9i introduces a new approach. PL/SQL source code may optionally be compiled into native object code that is linked into Oracle. Native compilation can result in significant improvement in overall application performance. (Its impact is felt in compute-intensive programs, but will not affect SQL performance.)

For instructions on how to take advantage of native compilation, see Chapter 19.

1.4.3 Working with Multiple Versions of PL/SQL

You need to be aware of the version ofOracle you are running in order to know which features are available for your use. You may sometimes even have to write PL/SQL programs that can run on different versions of Oracle. In this case, you have two options:

· Avoid relying on any "advanced" features of PL/SQL—that is, features that appear in a later version of the language, but not in a version that you must write for. This can be termed the "lowest common denominator" approach.

· Maintain multiple versions of your programs for each of the different versions of Oracle (assuming that there are features you want, or need to take advantage of, in later versions). It is hard to maintain code using this approach. If you are in this situation, you might want to take a look at the oneversion.sql script available on the O'Reilly site. This script shows how you can determine the Oracle version from the data dictionary and then use SQL*Plus substitution variables to turn portions of your program on or off, as appropriate for a particular version.

1.5 Resources for PL/SQL Developers

O'Reilly & Associates published the first edition of this book back in 1995. At that time, Oracle PL/SQL Programming made quite a splash. It was the first independent (i.e., not emanating from Oracle) book on PL/SQL, and it fulfilled a clear and intensely felt need of developers around the world. Since that time, resources—books, development environments, utilities, and web sites—for PL/SQL programmers have proliferated. (Of course, this book is still by far the most important and valuable of these resources!)

The following sections describe very briefly many of these resources. By taking full advantage of these resources, many of which are available either free or at a relatively low cost, you will greatly improve your development experience (and resulting code).

1.5.1 The O'Reilly PL/SQL Series

Over the years, the Oracle PL/SQL series from O'Reilly & Associates has grown to include quite a long list of books. We've summarized the whole set below. Please check out the Oracle area of the O'Reilly web site (http://oracle.oreilly.com) for much more complete information.

 

Oracle PL/SQL Programming, by Steven Feuerstein with Bill Pribyl

The thousand-page tome you are reading now. The desk-side companion of a great many professional PL/SQL programmers, this book is designed to cover every feature in the core PL/SQL language. The second edition covered Oracle versions through Oracle8, but this third edition covers all PL/SQL versions through Oracle9i.

 

Learning Oracle PL/SQL, by Bill Pribyl with Steven Feuerstein

A comparatively gentle introduction to the language, ideal for new programmers and those who know a language other than PL/SQL.

 

Oracle PL/SQL Best Practices, by Steven Feuerstein

A relatively short book that describes more than 100 best practices that will help you produce high-quality PL/SQL code. Having this book is kind of like having a "lessons learned" document written by an in-house PL/SQL expert. Current through Oracle8i.

 

Oracle PL/SQL Developer's Workbook, by Steven Feuerstein with Andrew Odewahn

Contains a series of questions and answers intended to help the PL/SQL programmer develop and test his or her understanding of the language. Current through Oracle8i.

 

Oracle PL/SQL Language Pocket Reference, by Steven Feuerstein, Bill Pribyl, and Chip Dawes (covers Oracle 8i)

 

Oracle PL/SQL Built-ins Pocket Reference, by Steven Feuerstein, John Beresniewicz, and Chip Dawes (covers Oracle 8)

Two tiny "quick reference" books that might actually fit in your coat pocket.

 

Oracle Built-in Packages, by Steven Feuerstein, Charles Dye, and John Beresniewicz

A reference guide to all of the prebuilt packages that Oracle supplies with the core database server. The use of these packages can sometimes simplify the difficult and tame the impossible. Current through Oracle8.

 

Oracle PL/SQL Programming: Guide to Oracle8i Features, by Steven Feuerstein

A companion to the Oracle PL/SQL Programming book that presents an overview of the great new PL/SQL features that appeared in Oracle8i.

 

Advanced Oracle PL/SQL Programming with Packages, by Steven Feuerstein

A book designed to communicate the rationale and means of improving your programs by writing your own PL/SQL packages. Covers Oracle7.

 

Oracle Web Applications: PL/SQL Developer's Introduction, by Andrew Odewahn

A good book to get Oracle developers started building database-driven web applications. Includes some introductory material on both PL/SQL and programming for the Web. Current through Oracle8i.

 

Oracle PL/SQL CD Bookshelf

Contains an electronic version of most of the above books, plus a hardcopy version of the Guide to Oracle8i Features. Current through Oracle8i.





Поделиться с друзьями:


Дата добавления: 2015-10-01; Мы поможем в написании ваших работ!; просмотров: 474 | Нарушение авторских прав


Поиск на сайте:

Лучшие изречения:

Настоящая ответственность бывает только личной. © Фазиль Искандер
==> читать все изречения...

2310 - | 2034 -


© 2015-2024 lektsii.org - Контакты - Последнее добавление

Ген: 0.008 с.