Welcome to the first course in the
Introduction to Oracle Certification Series, Extensions for SQL.
As the name implies, this series focuses on preparing you for certification in Oracle.
- Course Goals
This course covers extensions to SQL. This means that the course is especially designed to show you how to use Oracle's own SQL extensions within queries and other SQL commands. By the end of this course, you will know how to:
- Use advanced SQL query structures such as correlated sub-queries
- Use Oracle's extensions to SQL
- Write SQL to create Oracle tables, views, and indexes and the parameters used to create those structures in Oracle
- Use SQL to modify or remove existing table structures and constraints
- Write SQL to add, change, or delete rows in tables
- Use SQL*Plus (Oracle's SQL programming environment) to create SQL command files, including commands to set titles, page breaks, and customized column headings for your queries
During the dotcom era, Oracle 8 introduced several extensions to the SQL standard, enhancing its functionality beyond what was available in the base SQL implementations at the time. These extensions were key in making Oracle 8 more powerful, especially in handling advanced database requirements. Some of the main extensions included:
- Object-Relational Features: Oracle 8 added object-oriented capabilities to SQL, which were not part of the SQL-92 standard at the time. This included support for user-defined types (UDTs), object references, and collections (arrays and nested tables). These allowed users to model real-world entities directly in the database.
- PL/SQL Enhancements: Oracle extended SQL through its proprietary procedural language, PL/SQL. This enabled developers to write procedures, functions, and triggers, providing more control over database transactions and improving SQL’s basic procedural limitations.
- Partitioning: Oracle 8 introduced table partitioning, which allowed very large tables to be broken down into smaller, more manageable pieces. This feature provided extensions to SQL for managing and querying these partitions.
- Advanced SQL Joins: While the SQL-92 standard supported basic join operations, Oracle 8 introduced enhancements such as outer joins (using the `(+ )` operator) to simplify more complex queries. This extension helped users handle scenarios like retrieving unmatched rows in a more concise manner than the SQL standard required.
- Hierarchical Queries: Oracle 8 provided SQL extensions like `CONNECT BY` and `START WITH` to support hierarchical queries, which allowed users to retrieve data in a tree structure. These were non-standard SQL extensions at the time but became key in managing data with parent-child relationships.
- Index-Organized Tables (IOTs): This was a performance-related extension, where Oracle allowed tables to be stored as indexes, making query lookups faster. This feature extended the typical SQL table storage model.
- Materialized Views: Oracle 8 introduced materialized views, allowing users to store the results of complex queries physically. This extended the SQL capability for improving performance by precomputing and storing query results, especially in data warehousing applications.
- Sequences and Synonyms: Oracle extended SQL with the use of `SEQUENCE` objects to generate unique values, typically for primary keys. `SYNONYMS` were also introduced to create aliases for database objects, making it easier to access them without needing to reference the full schema path.
These extensions were key in differentiating Oracle’s database offering during the highly competitive dotcom era, addressing complex business requirements that standard SQL alone could not handle.
The information covered in this series helps you get started on the Oracle Certified Database Administrator and/or Certified Application Developer tracks. Another important goal of this series is to enable you
- to create advanced SQL queries,
- write intermediate PL/SQL blocks, and
- familiarize you with Oracle's unique SQL extensions.
Oracle SQL Extensions enhance the capabilities of Standard SQL by providing additional features, functions, and optimizations tailored to Oracle Database environments. These extensions differentiate themselves from Standard SQL in several key ways:
-
Proprietary Functions and Operators
- Oracle SQL includes proprietary functions and operators that are not part of the SQL standard.
-
Examples:
NVL()
: Returns a default value if a column is NULL
.
DECODE()
: Provides conditional logic similar to a CASE
statement but with a more compact syntax.
TO_DATE()
, TO_CHAR()
, TO_NUMBER()
: Functions for explicit data type conversion.
ROWNUM
: A pseudo-column that assigns a unique number to each row returned by a query.
CONNECT BY
: Used for hierarchical queries (e.g., tree structures).
-
Advanced Data Types
- Oracle supports advanced data types that go beyond the standard SQL data types.
-
Examples:
CLOB
, BLOB
, NCLOB
: For storing large text or binary data.
RAW
, LONG RAW
: For storing binary data.
ROWID
, UROWID
: Unique identifiers for rows in a table.
XMLType
: For storing and querying XML data.
JSON
: Native support for JSON data with functions like JSON_VALUE
, JSON_QUERY
, and JSON_TABLE
.
-
PL/SQL Integration
- Oracle SQL is tightly integrated with PL/SQL, Oracle's procedural extension to SQL.
-
Features:
- Stored procedures, functions, and triggers written in PL/SQL can be called directly from SQL queries.
- PL/SQL provides procedural constructs like loops, conditionals, and exception handling, which are not available in Standard SQL.
-
Analytical and Window Functions
- Oracle SQL provides advanced analytical functions for complex data analysis.
-
Examples:
ROW_NUMBER()
, RANK()
, DENSE_RANK()
: For ranking rows within a result set.
LAG()
, LEAD()
: For accessing data from previous or subsequent rows.
FIRST_VALUE()
, LAST_VALUE()
: For retrieving the first or last value in a window.
PARTITION BY
: For dividing data into partitions for window functions.
-
Hierarchical Queries
-
Flashback Queries
- Oracle SQL includes flashback features to query historical data.
-
Examples:
AS OF TIMESTAMP
: Query data as it existed at a specific point in time.
VERSIONS BETWEEN
: Retrieve all versions of rows between two points in time.
- These features are useful for auditing and recovering data.
-
Materialized Views
-
Database Links and Distributed Queries
-
Optimizer Hints
- Oracle SQL provides optimizer hints to influence the execution plan of queries.
-
Examples:
/*+ INDEX(table_name index_name) */
: Forces the use of a specific index.
/*+ FULL(table_name) */
: Forces a full table scan.
/*+ PARALLEL(table_name, degree) */
: Enables parallel execution.
-
Advanced Partitioning
- Oracle SQL supports advanced table partitioning strategies for managing large datasets.
-
Partition Types:
- Range partitioning
- List partitioning
- Hash partitioning
- Composite partitioning
-
Example:
CREATE TABLE sales (
sale_id NUMBER,
sale_date DATE,
amount NUMBER
)
PARTITION BY RANGE (sale_date) (
PARTITION p1 VALUES LESS THAN (TO_DATE('2023-01-01', 'YYYY-MM-DD')),
PARTITION p2 VALUES LESS THAN (TO_DATE('2024-01-01', 'YYYY-MM-DD'))
);
-
Object-Relational Features
- Oracle SQL supports object-relational features, allowing the creation of user-defined types, methods, and object tables.
-
Example:
CREATE TYPE address_type AS OBJECT (
street VARCHAR2(100),
city VARCHAR2(50),
state VARCHAR2(50),
zip_code VARCHAR2(10)
);
CREATE TABLE customers (
customer_id NUMBER,
name VARCHAR2(100),
address address_type
);
-
Enhanced Security Features
- Oracle SQL includes advanced security features not found in Standard SQL.
-
Examples:
- Virtual Private Database (VPD): Row-level security.
- Transparent Data Encryption (TDE): Encrypts data at rest.
- Data Redaction: Masks sensitive data in query results.
Summary: These extensions make Oracle SQL a powerful tool for enterprise-level database management and application development.
- Increased functionality: Oracle SQL Extensions provide additional functionality that is not available in Standard SQL. This can make it possible to write more efficient and concise code.
- Improved performance: Oracle SQL Extensions can be used to optimize the performance of queries and other database operations.
- Portability: Oracle SQL Extensions are supported by other Oracle products, such as Oracle Real Application Clusters (RAC) and Oracle Exadata.
However, it is important to note that Oracle SQL Extensions are not portable to other database vendors. Therefore, if you are developing applications that need to be portable to other database platforms, you should avoid using Oracle SQL Extensions. To identify the use of Oracle extensions to Entry SQL-92 in your embedded SQL programs, you can use Oracle's FIPS Flagger. The FIPS Flagger is part of the Oracle precompilers and the SQL*Module compiler. The FIPS Flagger can also be enabled in SQL*Plus by using ALTER SESSION SET FLAGGER = ENTRY .