Oracle 11g and Oracle 18c are versions of Oracle's database management
system, and each comes with a range of features and improvements
tailored to the technological needs of its time. Below is a comparison of
the two versions, focusing on key differences:
1. General Overview
Oracle 11g:
o Released in 2007.
o Focused on enhancing database manageability, performance,
and scalability.
o Introduced features like Real Application Testing and Active
Data Guard.
Oracle 18c:
o Released in 2018 as part of Oracle's annual release model.
o Marketed as a "fully autonomous database."
o Introduced more cloud-oriented features and machine-learning
capabilities.
2. Key Features and Innovations
Oracle 11g:
o Automatic Memory Management (AMM): Simplified
database memory tuning.
o Real Application Testing: Captured workloads for replay and
analysis.
o Active Data Guard: Provided real-time query offloading to
standby databases.
o Advanced Compression: Optimized storage and data
compression.
o PL/SQL Enhancements: Included features like function result
caching.
o Enhanced Diagnostics and Tuning: Tools like SQL
Performance Analyzer.
Oracle 18c:
o Autonomous Database Capabilities: Features like self-
tuning, self-repairing, and self-securing.
o In-Memory Optimizations: Extended in-memory column
store features.
o Sharding: Native sharding support for horizontally scaling
applications.
o JSON Enhancements: Better support for JSON-based
applications.
o Multi-Tenant Architecture Enhancements: Improved
pluggable database (PDB) capabilities.
o Partitioning Improvements: Advanced hybrid partitioning.
o Machine Learning Integration: Built-in algorithms for
predictive analytics.
3. Cloud Orientation
Oracle 11g:
o Primarily on-premises-focused, with some support for
virtualization and limited cloud integration.
Oracle 18c:
o Designed for both on-premises and cloud deployments.
o Tight integration with Oracle Cloud Infrastructure (OCI).
o Introduced features optimized for hybrid cloud models.
4. Performance Improvements
Oracle 11g:
o Focused on query optimization and adaptive execution plans.
o Added index and storage improvements, including better
compression techniques.
Oracle 18c:
o Significant performance gains via in-memory enhancements
and automated indexing.
o Improved SQL performance tuning and machine-learning-
driven query optimization.
5. Multi-Tenant Architecture
Oracle 11g:
o Does not natively support the multi-tenant architecture
introduced in Oracle 12c.
Oracle 18c:
o Supports multi-tenancy with improved pluggable database
management.
o Ideal for consolidating databases while maintaining isolation.
6. Security Enhancements
Oracle 11g:
o Introduced features like Transparent Data Encryption (TDE)
and Database Vault.
Oracle 18c:
o Enhanced TDE with more encryption algorithms.
o Unified auditing for easier compliance.
o New features like GDPR compliance tools and advanced user
activity monitoring.
7. Licensing Model
Oracle 11g:
o Traditional licensing model with enterprise and standard
editions.
Oracle 18c:
o Same traditional licensing, but also heavily oriented towards
Oracle Cloud subscriptions and hybrid models.
8. End of Support
Oracle 11g:
o Premier support ended in January 2015.
o Extended support ended in December 2020.
Oracle 18c:
o Premier support ended in June 2023.
o Extended support timelines depend on Oracle’s policies and
customer needs.
Summary
Oracle 18c represents a significant evolution over Oracle 11g, particularly
in terms of automation, cloud-readiness, and multi-tenant architecture.
Oracle 11g remains a strong option for legacy systems, but Oracle 18c is
better suited for modern applications that demand advanced analytics,
high scalability, and integration with cloud services.
Certainly! Oracle 18c introduces several new functions, data types, and
enhancements to existing features compared to Oracle 11g. Below is a
detailed comparison focusing on specific functions, data types, and how
they evolved.
1. New Data Types
Oracle 11g:
o Introduced basic data types like BINARY_FLOAT,
BINARY_DOUBLE, and enhanced support for LOB data types.
o Limited JSON support, requiring custom handling for JSON data
as it was not natively supported.
Oracle 18c:
o Native JSON Support: Introduced the JSON data type,
allowing efficient storage and querying of JSON documents. It
also provided functions like:
JSON_TABLE: Convert JSON data to a relational format.
JSON_VALUE: Extract a specific value from a JSON
document.
JSON_OBJECT and JSON_ARRAY: Construct JSON
documents.
o Polymorphic Table Functions (PTFs): Allow custom SQL
functions to work with any data type, making them highly
flexible.
o Enhanced support for the XMLTYPE data type with improved
performance for XML queries.
2. New and Enhanced SQL Functions
Oracle 11g:
o Introduced functions like LISTAGG (to concatenate strings
within a group) and advanced analytic functions like
PERCENTILE_CONT and PERCENTILE_DISC.
o Support for regular expressions in functions such as
REGEXP_LIKE, REGEXP_SUBSTR, REGEXP_REPLACE, and
REGEXP_INSTR.
Oracle 18c:
o SQL Macros: A new feature that allows users to define
reusable expressions or table constructs as macros for simpler
and faster SQL.
o LISTAGG Enhancements: Introduced LISTAGG with the ON
OVERFLOW clause to handle long concatenated results
gracefully.
o APPROX_ Functions*: Oracle 18c introduced approximate query
functions for fast aggregation over massive datasets, such as:
APPROX_COUNT_DISTINCT
APPROX_SUM
APPROX_RANK
o INMEMORY_ Functions*: Functions like INMEMORY_JOIN_GROUP
were added to optimize in-memory join operations.
o Improved handling for regular expressions with better
performance and syntax flexibility.
3. Evolution of PL/SQL Features
Oracle 11g:
o Added new PL/SQL features like:
Function result caching (RESULT_CACHE) for improving
query performance.
Compound triggers to simplify complex trigger logic.
Fine-grained access control using DBMS_RLS.
Oracle 18c:
o Enhanced PL/SQL with:
PL/SQL-Defined Functions in SQL: Allowed more
efficient invocation of PL/SQL functions within SQL
queries.
Private Temporary Tables: Temporary tables scoped
only to a session or transaction, enhancing session
isolation.
Enhanced dynamic SQL features, including better
support for native dynamic SQL (EXECUTE IMMEDIATE)
with bind variable capabilities.
More robust error handling and propagation options with
UTL_CALL_STACK.
4. Partitioning Enhancements
Oracle 11g:
o Basic partitioning strategies like range, list, and hash
partitioning.
o Limited subpartitioning capabilities.
Oracle 18c:
o Hybrid Partitioning: Supported combining partitioning
strategies, such as range-list or range-hash partitioning.
o Automatic Partitioning: Improved partition creation and
management automation.
o Partitioning by Internal Virtual Columns: Allowed virtual
columns to be used in partition keys, which was not possible in
Oracle 11g.
5. Machine Learning and Advanced Analytics
Oracle 11g:
o Basic support for Oracle Data Mining, including algorithms like
classification, clustering, and association.
Oracle 18c:
o Integrated machine learning algorithms natively within the
database, accessible through SQL and PL/SQL.
o Enhanced support for predictive analytics, with SQL functions
like:
PREDICTION_PROBABILITY
PREDICTION_COST
o Built-in algorithms for clustering, regression, anomaly
detection, and time-series analysis.
6. Security Features
Oracle 11g:
o Introduced features like Transparent Data Encryption (TDE),
Database Vault, and improved auditing with Fine-Grained
Auditing.
Oracle 18c:
o Unified Auditing Enhancements: Simplified auditing
configuration and reporting.
o TDE Enhancements: Expanded encryption algorithms and
better integration with Oracle Key Vault.
o Private Temporary Tables: Helped improve security by
isolating sensitive temporary data within a session.
o Schema-Only Accounts: Allowed schemas without
associated database accounts for better security.
7. Performance Enhancements
Oracle 11g:
o Adaptive Cursor Sharing: Improved execution plan reusability.
o SQL Plan Management: Maintained plan baselines to ensure
stability.
Oracle 18c:
o Automatic Indexing: Automatically creates, drops, and
maintains indexes based on query workloads.
o In-Memory Column Store Enhancements: Improved
analytics performance by enabling hybrid columnar storage.
o Optimized parallel query processing and better resource
management for mixed workloads.
8. Advanced Features for Developers
Oracle 11g:
o Focused primarily on traditional development workflows with
PL/SQL and SQL.
Oracle 18c:
o Sharding: Enabled horizontal scaling by partitioning data
across multiple databases.
o REST APIs for Database Services: Simplified application
integration via RESTful web services.
o Polymorphic Table Functions (PTFs): Supported functions
that adapt to the input data shape.
Summary of Evolution
Oracle 18c introduces a wide range of new data types, functions, and
enhancements designed to improve performance, scalability, and ease of
use for both developers and administrators. It also incorporates modern
technologies like JSON support, machine learning, and automation, making
it a significant step forward from Oracle 11g.
1. Native JSON Data Type and Functions in Oracle 18c
Oracle 18c introduced native JSON support, allowing efficient storage and
querying of JSON data. Below are examples demonstrating how to use
JSON data types and associated functions.
Example: Storing JSON Data in a Table
CREATE TABLE employees (
id NUMBER PRIMARY KEY,
name VARCHAR2(100),
details JSON -- Native JSON data type
);
-- Insert JSON data
INSERT INTO employees (id, name, details)
VALUES (
1,
'Alice',
'{"age": 30, "department": "HR", "skills": ["communication",
"recruitment"]}'
);
INSERT INTO employees (id, name, details)
VALUES (
2,
'Bob',
'{"age": 40, "department": "IT", "skills": ["programming", "databases"]}'
);
Example: Querying JSON Data
Extract a Specific Value (JSON_VALUE)
SELECT name, JSON_VALUE(details, '$.department') AS department
FROM employees;
Filter Records Based on JSON Value
SELECT name
FROM employees
WHERE JSON_VALUE(details, '$.age') > 35;
Convert JSON Array to Rows (JSON_TABLE)
SELECT e.name, jt.skill
FROM employees e,
JSON_TABLE(details, '$.skills[*]'
COLUMNS (
skill VARCHAR2(50) PATH '$'
) jt;
Example: Generating JSON Data
Construct JSON Objects
SELECT JSON_OBJECT('name' VALUE name, 'department' VALUE
JSON_VALUE(details, '$.department')) AS employee_json
FROM employees;
Construct JSON Arrays
SELECT JSON_ARRAY('HR', 'IT', 'Finance') AS departments
FROM DUAL;
2. Polymorphic Table Functions (PTFs)
Polymorphic Table Functions (PTFs) in Oracle 18c allow you to create
flexible, reusable SQL functions that operate on input tables, regardless of
the structure of the input data. They adapt their behavior to the columns
and data types provided.
Example: Creating a Polymorphic Table Function
This example implements a PTF that adds a calculated column to any input
table.
Step 1: Create a PTF Package
CREATE OR REPLACE PACKAGE add_computed_column_pkg IS
FUNCTION describe(tab IN OUT DBMS_TF.TABLE_T)
RETURN DBMS_TF.DESCRIBE_T;
PROCEDURE fetch_rows(tab IN OUT DBMS_TF.TABLE_T);
END add_computed_column_pkg;
Step 2: Implement the PTF Package Body
CREATE OR REPLACE PACKAGE BODY add_computed_column_pkg IS
FUNCTION describe(tab IN OUT DBMS_TF.TABLE_T)
RETURN DBMS_TF.DESCRIBE_T IS
BEGIN
-- Add a new column to the output table
DBMS_TF.ADD_COLUMN(tab, 'COMPUTED_VALUE',
DBMS_TF.TYPE_NUMBER);
RETURN NULL;
END describe;
PROCEDURE fetch_rows(tab IN OUT DBMS_TF.TABLE_T) IS
input_column DBMS_TF.COLUMN_DATA_T;
computed_column DBMS_TF.COLUMN_DATA_T;
BEGIN
input_column := DBMS_TF.GET_COLUMN(tab, 1); -- Assuming first
column is numeric
computed_column := DBMS_TF.GET_COLUMN(tab,
'COMPUTED_VALUE');
FOR i IN 1 .. input_column.COUNT LOOP
computed_column(i) := input_column(i) * 2; -- Simple calculation
END LOOP;
END fetch_rows;
END add_computed_column_pkg;
Step 3: Use the Polymorphic Table Function
CREATE OR REPLACE FUNCTION add_computed_column RETURN
DBMS_TF.TABLE_T PIPELINED
USING add_computed_column_pkg;
-- Example table
CREATE TABLE numbers (id NUMBER, value NUMBER);
INSERT INTO numbers VALUES (1, 10);
INSERT INTO numbers VALUES (2, 20);
-- Apply the PTF
SELECT *
FROM add_computed_column(numbers);
Output:
I VALU COMPUTED_VAL
D E UE
1 10 20
2 20 40
Summary
JSON Functions: Oracle 18c simplifies JSON handling with native
JSON types and functions like JSON_VALUE, JSON_TABLE,
JSON_OBJECT, and JSON_ARRAY.
Polymorphic Table Functions (PTFs): Provide dynamic, adaptable
SQL functions that are reusable across various table structures,
making them a powerful tool for developers.
These features exemplify Oracle 18c's focus on flexibility, ease of use, and
performance improvements.
Certainly! Below are detailed examples of SQL Macros, LISTAGG with
ON OVERFLOW, APPROX_ Functions, and INMEMORY_ Functions, all
introduced or enhanced in Oracle 18c.
1. SQL Macros
SQL Macros allow reusable SQL expressions or table constructs, simplifying
queries and improving maintainability. They can return either a SCALAR
expression or a TABLE expression.
Example: Scalar SQL Macro
CREATE OR REPLACE FUNCTION add_vat(price NUMBER)
RETURN VARCHAR2 SQL_MACRO (SCALAR) IS
BEGIN
RETURN 'price * 1.20'; -- Adds 20% VAT
END add_vat;
-- Usage
SELECT product_name, add_vat(price) AS price_with_vat
FROM products;
Explanation:
The add_vat macro substitutes price * 1.20 directly in the SQL query,
ensuring high performance.
Example: Table SQL Macro
CREATE OR REPLACE FUNCTION filter_active(table_name VARCHAR2)
RETURN VARCHAR2 SQL_MACRO (TABLE) IS
BEGIN
RETURN 'SELECT * FROM ' || table_name || ' WHERE status = ''ACTIVE''';
END filter_active;
-- Usage
SELECT * FROM filter_active('employees');
Explanation:
The macro dynamically constructs and executes a query filtering
rows based on a condition.
2. LISTAGG with ON OVERFLOW Clause
The LISTAGG function concatenates strings within a group. In Oracle 18c,
the ON OVERFLOW clause gracefully handles cases where the
concatenated result exceeds the size limit.
Example: Using LISTAGG with ON OVERFLOW
SELECT department_id,
LISTAGG(employee_name, ', ') WITHIN GROUP (ORDER BY
employee_name)
ON OVERFLOW TRUNCATE '... (truncated)' AS employee_list
FROM employees
GROUP BY department_id;
Explanation:
If the result exceeds the maximum size, it truncates the output and
appends the text ... (truncated).
3. APPROX_ Functions
The APPROX_ functions provide approximate results for aggregate
operations, offering significant performance improvements over exact
computations for massive datasets.
Example: APPROX_COUNT_DISTINCT
SELECT department_id, APPROX_COUNT_DISTINCT(employee_id) AS
unique_employees
FROM employees
GROUP BY department_id;
Explanation:
APPROX_COUNT_DISTINCT provides an estimated count of unique
employees per department. It is faster and uses less memory
compared to COUNT(DISTINCT ...).
Example: APPROX_RANK
SELECT APPROX_RANK(0.9) WITHIN GROUP (ORDER BY salary) AS
percentile_90
FROM employees;
Explanation:
Calculates the 90th percentile salary using an approximate ranking,
making it efficient for large datasets.
4. INMEMORY_ Functions
The INMEMORY_ functions are designed for databases utilizing Oracle's In-
Memory Column Store (IMCS), significantly boosting performance for
analytical queries.
Example: INMEMORY_PRUNING
INMEMORY_PRUNING identifies segments pruned during query execution in
an In-Memory-enabled table.
SELECT /*+ INMEMORY */ emp_id, department_id
FROM employees
WHERE department_id = 10;
To verify pruning:
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL, NULL, 'ADVANCED'));
Explanation:
In-memory pruning ensures only relevant partitions or segments are
accessed, improving query performance.
Example: INMEMORY_JOIN_GROUP
The INMEMORY_JOIN_GROUP function optimizes join performance for
specific sets of columns.
ALTER TABLE employees INMEMORY;
ALTER TABLE departments INMEMORY;
-- Join optimization
SELECT e.emp_id, d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id
AND INMEMORY_JOIN_GROUP(e.department_id, d.department_id);
Explanation:
INMEMORY_JOIN_GROUP optimizes joins between the specified
columns by leveraging in-memory structures.
Summary of Features
SQL Macros: Simplify complex expressions or queries and improve
maintainability.
LISTAGG with ON OVERFLOW: Prevents errors from oversized
concatenated results by truncating with custom messages.
APPROX_ Functions: Deliver fast, memory-efficient approximations
for common aggregation operations, suitable for large-scale
datasets.
INMEMORY_ Functions: Enhance query performance by leveraging
Oracle's In-Memory Column Store and pruning strategies.
These features make Oracle 18c an excellent choice for modern data
processing needs, balancing performance and usability.
Enhanced PL/SQL Features in Oracle 18c
Oracle 18c introduced several enhancements to PL/SQL, making it more
powerful, efficient, and developer-friendly. Here's a detailed explanation
with examples:
1. PL/SQL-Defined Functions in SQL
Oracle 18c allows PL/SQL functions to be invoked directly in SQL
statements without significant performance overhead. These are compiled
into a SQL expression at runtime for better execution speed.
Example: PL/SQL-Defined Function in SQL
-- Create a PL/SQL function
CREATE OR REPLACE FUNCTION calculate_bonus(salary NUMBER) RETURN
NUMBER IS
BEGIN
RETURN salary * 0.10; -- Calculate 10% bonus
END calculate_bonus;
-- Use the function in a SQL query
SELECT employee_id, salary, calculate_bonus(salary) AS bonus
FROM employees;
Key Benefits:
The function is treated as a SQL expression, avoiding unnecessary
context switching between SQL and PL/SQL engines.
Ideal for reusable business logic within queries.
2. Private Temporary Tables
Private Temporary Tables (PTTs) are a new type of temporary table
introduced in Oracle 18c. They are visible only to the session or
transaction that creates them, providing better isolation and security.
Features of Private Temporary Tables:
Scoped to a session or transaction.
Automatically dropped at the end of the session/transaction.
Data is private and cannot be shared with other sessions.
Example: Creating and Using Private Temporary Tables
-- Create a Private Temporary Table scoped to the session
CREATE PRIVATE TEMPORARY TABLE ora$ptt_employees
ON COMMIT PRESERVE DEFINITION
AS SELECT * FROM employees WHERE department_id = 10;
-- Insert data into the Private Temporary Table
INSERT INTO ora$ptt_employees VALUES (999, 'John Doe', 5000, 10);
-- Query the Private Temporary Table
SELECT * FROM ora$ptt_employees;
-- Table automatically dropped at the end of the session
Key Benefits:
Eliminates manual cleanup of temporary tables.
Enhances session isolation and ensures data security.
3. Enhanced Dynamic SQL
Dynamic SQL in Oracle 18c gained new features, particularly in EXECUTE
IMMEDIATE, making it more powerful and versatile.
Improvements:
Enhanced support for bind variables in dynamic SQL.
Simplified handling of variable lists and result sets.
Example: Using EXECUTE IMMEDIATE with Bind Variables
DECLARE
sql_stmt VARCHAR2(200);
dept_id NUMBER := 10;
result_count NUMBER;
BEGIN
sql_stmt := 'SELECT COUNT(*) FROM employees WHERE department_id
= :1';
EXECUTE IMMEDIATE sql_stmt INTO result_count USING dept_id;
DBMS_OUTPUT.PUT_LINE('Number of employees in department ' ||
dept_id || ': ' || result_count);
END;
Key Benefits:
Reduces the risk of SQL injection by using bind variables.
Makes dynamic SQL more concise and readable.
4. Enhanced Error Handling with UTL_CALL_STACK
Oracle 18c introduced the UTL_CALL_STACK package, which provides
detailed information about the execution stack during error handling. It
replaces and extends the older DBMS_UTILITY.FORMAT_CALL_STACK.
Features of UTL_CALL_STACK:
Provides information about the current PL/SQL call stack, such as:
o Program unit names.
o Line numbers of errors.
o Ownership of the program unit.
Enables detailed error diagnostics.
Example: Using UTL_CALL_STACK for Debugging
DECLARE
v_divide_by_zero NUMBER;
BEGIN
v_divide_by_zero := 10 / 0; -- Will raise an error
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error occurred!');
DBMS_OUTPUT.PUT_LINE('Error Depth: ' || UTL_CALL_STACK.DEPTH);
DBMS_OUTPUT.PUT_LINE('Topmost Error: ' ||
UTL_CALL_STACK.TOP_LEVEL_CALL);
DBMS_OUTPUT.PUT_LINE('Error Backtrace: ' ||
DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
END;
Output:
Error occurred!
Error Depth: 2
Topmost Error: MySchema.MY_PACKAGE
Error Backtrace: ORA-01476: divisor is equal to zero at line 4
Key Benefits:
Offers granular insights into error locations and causes.
Simplifies debugging and maintenance of complex PL/SQL code.
Summary of Benefits
Feature Key Advantage
Improves performance by reducing context
PL/SQL-Defined
switching and allows efficient use of reusable logic
Functions in SQL
within queries.
Enhances data isolation and security by ensuring
Private Temporary
temporary data is scoped to the session or
Tables
transaction and cleaned up automatically.
Simplifies the use of bind variables, making dynamic
Enhanced Dynamic
SQL safer and more efficient, especially for handling
SQL
variable input and output.
Provides detailed error diagnostics, making
UTL_CALL_STACK debugging easier and improving the maintainability
of PL/SQL code.
These features empower developers and administrators to write more
efficient, secure, and maintainable code, addressing both performance and
usability.
Oracle 18c introduced powerful partitioning enhancements, including
Hybrid Partitioning, Automatic Partitioning, and Partitioning by
Internal Virtual Columns. These features improve data management,
scalability, and performance for partitioned tables.
1. Hybrid Partitioning
Hybrid Partitioning allows combining traditional database-managed
partitions with external partitions, such as files stored in Oracle Big Data
SQL or Oracle Cloud Object Storage.
Key Features:
Enables seamless querying across database and external partitions.
Useful for managing large data volumes efficiently.
Example: Hybrid Partitioning
-- Create a table with hybrid partitioning
CREATE TABLE sales (
sale_id NUMBER,
sale_date DATE,
amount NUMBER
PARTITION BY RANGE (sale_date)
PARTITION q1_2025 VALUES LESS THAN (TO_DATE('2025-04-01', 'YYYY-
MM-DD')),
PARTITION q2_2025 VALUES LESS THAN (TO_DATE('2025-07-01', 'YYYY-
MM-DD')),
PARTITION ext_partition LOCATION ('/bigdata/sales/external_partition') --
External partition
);
Explanation:
The ext_partition stores data in external storage, reducing storage
costs for less frequently accessed data.
Oracle queries this table seamlessly, combining internal and external
partitions.
2. Automatic Partitioning
Automatic Partitioning simplifies partition management by automatically
creating partitions as needed based on the data being inserted.
Key Features:
Eliminates the need for manual partition management.
Reduces administrative overhead.
Example: Automatic Partitioning
-- Enable automatic list partitioning
CREATE TABLE employees (
emp_id NUMBER,
department VARCHAR2(100),
hire_date DATE
PARTITION BY LIST (department)
AUTOMATIC (PARTITION department_partition DEFAULT);
-- Insert data into the table
INSERT INTO employees VALUES (1, 'HR', SYSDATE); -- Creates "HR"
partition
INSERT INTO employees VALUES (2, 'IT', SYSDATE); -- Creates "IT" partition
INSERT INTO employees VALUES (3, 'HR', SYSDATE); -- Uses existing "HR"
partition
Explanation:
Oracle creates partitions dynamically for unique values of the
department column.
Reduces the risk of ORA-14400 errors (partition key not found).
3. Partitioning by Internal Virtual Columns
Internal Virtual Column Partitioning allows you to define partitions based
on derived columns that are not physically stored in the table.
Key Features:
Partitions data based on computed values.
Simplifies partitioning logic for derived attributes.
Example: Partitioning by Internal Virtual Columns
-- Create a table using a virtual column for partitioning
CREATE TABLE orders (
order_id NUMBER,
order_date DATE,
year_month GENERATED ALWAYS AS (TO_CHAR(order_date, 'YYYY-MM'))
VIRTUAL
PARTITION BY LIST (year_month)
PARTITION p_2025_01 VALUES ('2025-01'),
PARTITION p_2025_02 VALUES ('2025-02'),
PARTITION p_default VALUES (DEFAULT)
);
-- Insert data
INSERT INTO orders (order_id, order_date) VALUES (1, TO_DATE('2025-01-
15', 'YYYY-MM-DD'));
INSERT INTO orders (order_id, order_date) VALUES (2, TO_DATE('2025-02-
20', 'YYYY-MM-DD'));
Explanation:
The year_month virtual column is used as the partition key.
Automatically routes data to the appropriate partition based on the
derived year_month value.
Summary of Features and Use Cases
Feature Use Case Key Benefit
Combining database and Reduces storage costs
Hybrid
external data (e.g., archival while ensuring seamless
Partitioning
data in external storage). access to all partitions.
Managing dynamically Eliminates manual
Automatic changing datasets (e.g., real- partition management,
Partitioning time applications with new reducing administrative
categories). effort.
Simplifying partitioning logic Enables dynamic, logical
Partitioning
based on computed or derived partitioning without
by Virtual
attributes (e.g., year/month- additional storage
Columns
based). overhead.
These features make partitioning more flexible and efficient, addressing a
wide range of data management challenges in modern applications.
Virtual Columns in Oracle
A virtual column in Oracle is a column in a table whose value is derived
from an expression or computation based on other columns in the same
table. The data for a virtual column is not physically stored, but its
value is computed at query time, saving storage and enabling dynamic
behavior.
Key Features of Virtual Columns:
1. Dynamic Calculation: Values are derived from a deterministic
expression.
2. Indexing Support: Virtual columns can be indexed for better
performance.
3. Querying and Filtering: Virtual columns can be used like regular
columns in SELECT, WHERE, GROUP BY, and other clauses.
4. Partitioning: Virtual columns can be used as partition keys.
5. No Storage Overhead: Since values are not stored, only the
expression is maintained.
Example: Creating and Using Virtual Columns
1. Creating a Table with Virtual Columns
CREATE TABLE employees (
emp_id NUMBER,
first_name VARCHAR2(50),
last_name VARCHAR2(50),
full_name GENERATED ALWAYS AS (first_name || ' ' || last_name)
VIRTUAL,
hire_date DATE,
years_of_service GENERATED ALWAYS AS
(FLOOR(MONTHS_BETWEEN(SYSDATE, hire_date) / 12)) VIRTUAL
);
-- Insert Data
INSERT INTO employees (emp_id, first_name, last_name, hire_date)
VALUES (1, 'Alice', 'Smith', TO_DATE('2015-03-15', 'YYYY-MM-DD'));
INSERT INTO employees (emp_id, first_name, last_name, hire_date)
VALUES (2, 'Bob', 'Johnson', TO_DATE('2018-06-20', 'YYYY-MM-DD'));
2. Querying Virtual Columns
Selecting Virtual Columns
SELECT emp_id, full_name, years_of_service
FROM employees;
Output:
EMP_I FULL_NA YEARS_OF_SERV
D ME ICE
Alice
1 9
Smith
Bob
2 6
Johnson
Filtering Using Virtual Columns
SELECT emp_id, full_name
FROM employees
WHERE years_of_service > 7;
Output:
EMP_I FULL_NA
D ME
1 Alice Smith
3. Indexing Virtual Columns
To improve query performance, you can create an index on a virtual
column:
CREATE INDEX idx_full_name ON employees (full_name);
Benefit: Queries that filter or sort based on the full_name virtual column
can now use the index.
4. Using Virtual Columns in Partitioning
Virtual columns are often used for partitioning tables dynamically without
storing derived values.
Example: Partitioning by Year-Month
CREATE TABLE orders (
order_id NUMBER,
order_date DATE,
year_month GENERATED ALWAYS AS (TO_CHAR(order_date, 'YYYY-MM'))
VIRTUAL
PARTITION BY RANGE (year_month) (
PARTITION p_2025_01 VALUES LESS THAN ('2025-02'),
PARTITION p_2025_02 VALUES LESS THAN ('2025-03')
);
-- Insert Data
INSERT INTO orders (order_id, order_date) VALUES (1, TO_DATE('2025-01-
15', 'YYYY-MM-DD'));
INSERT INTO orders (order_id, order_date) VALUES (2, TO_DATE('2025-02-
20', 'YYYY-MM-DD'));
-- Query Data
SELECT * FROM orders WHERE year_month = '2025-01';
Advantages of Virtual Columns
1. Storage Savings: No additional space is consumed, as the column
values are computed dynamically.
2. Performance Optimization: Can be indexed and used for
partitioning, enabling efficient data access.
3. Simplifies Queries: Derived values can be referenced directly,
reducing query complexity.
4. Flexibility: Allows dynamic calculations that automatically reflect
changes in the base data.
Limitations
1. Read-Only: Virtual columns cannot be directly updated or inserted.
2. Performance Cost: For complex calculations, the dynamic
computation can introduce some overhead (mitigated by indexing).
3. Deterministic Expressions Only: The expression must produce
the same result each time it is evaluated with the same input.
Summary
Virtual columns are an excellent feature for dynamically derived values,
enabling:
Efficient querying and filtering.
Flexible partitioning strategies.
Storage-efficient designs without duplicating data.
By indexing and leveraging virtual columns in partitioning, you can
achieve a balance between dynamic behavior and performance.
Here’s a detailed explanation of the requested features introduced in
Oracle 18c, with examples for clarity:
1. Unified Auditing Enhancements
Unified Auditing consolidates all auditing functionality into a single
repository, making it easier to manage and query auditing data.
Key Enhancements:
Improved Performance: Unified Auditing now uses Oracle’s fast in-
memory processing for audit records.
Role-Based Auditing: Assign audit policies directly to database
roles.
Audit Policy Contexts: Dynamic conditions can be applied to
auditing.
Separation of Duties: Audit records are stored in a secure location,
ensuring the integrity of auditing data.
Example: Unified Auditing Setup
1. Enable Unified Auditing: Unified Auditing must be enabled if not
already active. In Oracle 18c, it's typically enabled by default.
2. SELECT VALUE FROM V$OPTION WHERE PARAMETER = 'Unified
Auditing';
3. Create an Audit Policy:
4. CREATE AUDIT POLICY login_policy
5. ACTIONS LOGON
6. WHEN 'USER != ''SYS''';
Explanation:
o The login_policy audits all logins except those from the SYS
user.
7. Apply the Policy to a Role:
8. AUDIT POLICY login_policy BY ROLE DBA;
9. Query Audit Data: Audit records are stored in the
UNIFIED_AUDIT_TRAIL view.
10. SELECT event_timestamp, action_name, userhost, username
11. FROM unified_audit_trail
12. WHERE action_name = 'LOGON';
2. Transparent Data Encryption (TDE) Enhancements
Oracle 18c introduced several enhancements to TDE, ensuring better
security and performance.
Key Enhancements:
TDE Tablespace Encryption Performance: Improved with
hardware acceleration and encryption key caching.
Support for Keystore Migration: Simplified migration of TDE
keystores between environments.
Offline Tablespace Encryption: Encrypt existing tablespaces
offline, reducing application impact.
Support for Encrypting External Tables: Extend TDE to external
tables stored outside the database.
Example: Encrypting a Tablespace
1. Set Up the Keystore:
2. ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY
my_password;
3. Create an Encrypted Tablespace:
4. CREATE TABLESPACE secure_data
5. DATAFILE '/u01/oracle/secure_data01.dbf' SIZE 100M
6. ENCRYPTION USING 'AES256'
7. DEFAULT STORAGE(ENCRYPT);
8. Encrypt an Existing Tablespace Offline:
9. ALTER TABLESPACE users ENCRYPTION OFFLINE ENCRYPT;
3. Private Temporary Tables
Private Temporary Tables (PTTs) are temporary tables that are scoped to a
session or transaction, providing greater control over temporary data.
Key Features:
Automatically dropped at the end of the session/transaction.
Improve session-level isolation and simplify temporary table
management.
Example: Using Private Temporary Tables
1. Create a Session-Scoped Private Temporary Table:
2. CREATE PRIVATE TEMPORARY TABLE ora$ptt_sales
3. ON COMMIT PRESERVE DEFINITION
4. AS SELECT * FROM sales WHERE ROWNUM <= 10;
Explanation:
o ON COMMIT PRESERVE DEFINITION: Keeps the table structure
intact after each commit.
5. Insert Data:
6. INSERT INTO ora$ptt_sales VALUES (999, 'Product X', 100);
7. Query Data:
8. SELECT * FROM ora$ptt_sales;
Note: The table is dropped automatically at the end of the session.
4. Schema-Only Accounts
Schema-only accounts allow the creation of schemas without associated
passwords, improving security for schemas used only for object ownership.
Key Features:
Prevents direct login to the schema, reducing attack surface.
Useful for application schemas and object ownership without user
authentication.
Example: Creating a Schema-Only Account
1. Create a Schema-Only Account:
2. CREATE USER app_schema NO AUTHENTICATION;
Explanation:
o The NO AUTHENTICATION clause ensures the account has no
password and cannot be used to log in.
3. Grant Privileges:
4. GRANT CONNECT, RESOURCE TO app_schema;
5. Assign Objects to the Schema:
6. CREATE TABLE app_schema.orders (
7. order_id NUMBER PRIMARY KEY,
8. order_date DATE,
9. customer_name VARCHAR2(100)
10. );
Note: The account is used only for object ownership, not for direct
database access.
Summary of Benefits
Feature Key Benefit
Simplifies auditing, improves performance, and
Unified Auditing
ensures secure audit records.
TDE Enhances encryption flexibility and performance,
Enhancements supporting offline encryption and external data.
Private
Provides session or transaction-level isolation for
Temporary
temporary data, reducing cleanup overhead.
Tables
Schema-Only Enhances security by limiting schema access to
Accounts application or DBA use cases.
These features collectively provide better security, scalability, and ease of
administration in Oracle 18c.
1. Automatic Indexing
Oracle 19c introduced Automatic Indexing, but its evolution began with
enhancements in Oracle 18c to simplify index management and improve
query performance automatically.
Key Features of Automatic Indexing:
Automated Index Management:
o Automatically creates, monitors, and drops indexes based on
the query workload.
AI-Driven Decisions:
o Uses machine learning to analyze workload patterns.
Real-Time Performance:
o Continuously evaluates index effectiveness, modifying indexes
when necessary.
Validation Process:
o Indexes are created in an invisible state initially, tested for
performance benefits, and made visible if effective.
Integration with SQL Plan Management:
o Ensures indexes are used only when they improve query
execution plans.
Example: Enabling Automatic Indexing
1. Enable Automatic Indexing:
2. ALTER SYSTEM SET AUTO_INDEXING = TRUE;
3. Monitor Automatic Indexing Activity:
4. SELECT * FROM DBA_AUTO_INDEX_EXECUTIONS;
5. View Automatically Created Indexes:
6. SELECT index_name, status
7. FROM DBA_INDEXES
8. WHERE AUTO = 'YES';
Key Tables for Monitoring:
DBA_AUTO_INDEX_CONFIG: Configuration details.
DBA_AUTO_INDEX_EXECUTIONS: Execution history.
DBA_AUTO_INDEX_REPORTS: Performance reports.
Benefits:
Reduced Manual Effort: Database administrators no longer need
to manually create and manage indexes.
Performance Gains: Automatically optimizes the workload with
minimal intervention.
Continuous Learning: Adapts to workload changes over time.
2. In-Memory Column Store Enhancements
Oracle In-Memory Column Store (IMCS) allows data to be stored in a
columnar format in memory, improving analytic query performance.
Oracle 18c introduced several enhancements to the In-Memory Column
Store.
Key Enhancements:
In-Memory External Tables:
o Query external data sources with in-memory columnar format,
improving performance.
Automatic In-Memory (AIM):
o Automatically prioritizes and manages which objects are
loaded into the IMCS based on usage patterns.
Support for LOBs (Large Objects):
o Query LOB data efficiently in the column store.
In-Memory Joins:
o Enhancements to improve join performance between in-
memory tables.
Example: Using the In-Memory Column Store
1. Enable In-Memory on a Table:
2. ALTER TABLE sales INMEMORY;
3. Query with In-Memory Optimization:
4. SELECT SUM(revenue)
5. FROM sales
6. WHERE region = 'North America';
7. Monitor In-Memory Usage:
8. SELECT table_name, in_memory_size
9. FROM V$IM_SEGMENTS;
10. Enable In-Memory External Tables:
11. CREATE TABLE external_sales
12. ORGANIZATION EXTERNAL (
13. TYPE ORACLE_LOADER
14. DEFAULT DIRECTORY ext_dir
15. ACCESS PARAMETERS (
16. FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
17. )
18. LOCATION ('external_sales.csv')
19. )
20. INMEMORY;
Benefits:
Faster Query Performance: Analytic queries benefit from the
columnar format and in-memory acceleration.
LOB Support: Brings large objects into analytical workflows.
Automatic Management: Reduces administrative overhead with
automatic in-memory management.
3. Summary of Benefits
Feature Description Key Benefit
Automatically creates and Reduces manual index
Automatic
manages indexes based on management, improves query
Indexing
workload. performance.
Enhances query
In-Memory Optimized analytics, faster
performance using
Column query execution, and reduced
columnar storage in
Store latency.
memory.
In-Memory Allows external data to Seamless integration of
External benefit from in-memory external data with high-
Tables processing. performance queries.
Extends in-memory benefits to
LOB Support Enables efficient querying
unstructured or semi-structured
in IMCS of large objects in memory.
data like XML or JSON.
Dynamically prioritizes Ensures high-priority objects
Automatic
objects for in-memory are always optimized for
In-Memory
storage based on access performance without manual
(AIM)
patterns. intervention.
These enhancements together simplify database administration and
deliver exceptional performance for analytic and mixed workloads.