Oracle 19c SELECT Features You Need to Know
Oracle Database 19c represents the culmination of years of innovation in the Oracle 12c product line, delivering a suite of enhancements that elevate the humble SELECT statement from a straightforward data retrieval mechanism into an intelligent, self-optimizing, and JSON-aware powerhouse. In this deep-dive blog post, we’ll explore each of these advancements in detail, illustrate them with real-world examples, and reveal how they can transform your SQL into more expressive, performant, and resilient queries.
1. Enhanced String Aggregation with LISTAGG DISTINCT
Prior to 19c, LISTAGG would concatenate duplicate values as-is, forcing you to nest subqueries or use ROW_NUMBER() workarounds to eliminate duplicates. Oracle 19c introduces DISTINCT within LISTAGG, streamlining your code and improving readability.
-- Oracle 12c approach (requires a subquery)
SELECT department_id,
LISTAGG(dept_name, ',') WITHIN GROUP (ORDER BY dept_name) AS all_departments
FROM (
SELECT DISTINCT department_id, dept_name
FROM hr.departments
) t
GROUP BY department_id;
-- Oracle 19c approach
SELECT department_id,
LISTAGG(DISTINCT dept_name, ',') WITHIN GROUP (ORDER BY dept_name) AS unique_departments
FROM hr.departments
GROUP BY department_id;
Why it matters:
- Simplicity: Eliminates nested queries and redundant sorting logic.
- Maintainability: Makes intent explicit, reducing risk when schema evolves.
2. High-Performance Approximate Distinct Counts
When dealing with massive datasets, exact COUNT(DISTINCT ...) can be resource-intensive. Oracle 19c introduces the BITMAP_BASED_COUNT_DISTINCT(expr) function, which uses bitmap sketches for fast, approximate cardinality estimates, trading minimal accuracy for dramatic performance gains.
-- Exact distinct count (potentially slow on large tables)
SELECT COUNT(DISTINCT session_id) AS exact_sessions
FROM web_clicks;
-- Approximate distinct count (blazing fast)
SELECT BITMAP_BASED_COUNT_DISTINCT(session_id) AS approx_sessions
FROM web_clicks;
Practical impact:
- Enable real-time reporting dashboards on billions of rows.
- Free up CPU cycles for critical workloads by accepting <1% error margin.
3. Native JSON Processing in SQL
Oracle 19c continues the journey toward “JSON-first” database capabilities, adding SQL syntax sugar and performance optimizations that make querying and updating JSON documents as natural as relational data:
- JSON_EXISTS Enhancements
- Simplified path expressions and new
RELAXEDmode for better predicate push-down.
- Simplified path expressions and new
- JSON_TRANSFORM
- In-place modification of JSON columns without PL/SQL wrapper.
- JSON_SERIALIZE and GeoJSON Support
- Export relational or object-type data into standard JSON or GeoJSON, enabling seamless integration with web services and GIS applications.
- Materialized Views over JSON_TABLE
- Accelerate analytics by precomputing expensive JSON path transformations.
-- Querying JSON more concisely
SELECT customer_id,
jt.order_total
FROM customer_orders co,
JSON_TABLE(
co.order_data,
'$.orders[*]'
COLUMNS (
order_id VARCHAR2(50) PATH '$.id',
order_total NUMBER PATH '$.total'
)
) jt
WHERE jt.order_total > 1000;
-- Transforming JSON in-place
UPDATE customer_orders
SET order_data = JSON_TRANSFORM(
order_data,
SET '$.status' = 'SHIPPED',
INSERT '$.shipped_date' = SYS_DATE
)
WHERE customer_id = 12345;
Business benefit:
- Foster a unified data model for applications that straddle relational and document paradigms.
- Reduce ETL complexity by eliminating JSON shredding pipelines.
4. Real-Time Optimizer Statistics
Select queries hinge on accurate cardinality estimates. Oracle 19c dynamically gathers “real-time” statistics at parse time, ensuring that even long-running workloads benefit from up-to-the-moment data distribution profiles:
- Automatic Mid-day Stats Gathering
- Large tables and partitions refresh statistics more frequently, reducing plan drift.
- Adaptive Plan Evolution
- The optimizer refines execution plans in flight as new bind values or data patterns emerge.
-- No change to SELECT syntax; enable at database level
ALTER SYSTEM SET OPTIMIZER_REAL_TIME_STATISTICS = TRUE SCOPE=BOTH;
Outcome:
- Dramatic reduction in suboptimal plans for highly volatile data.
- Less manual intervention in plan baselines or hints.
5. Hybrid Partitioned Tables (HPT)
Oracle 19c allows a single table to span both internal and external partitions—erasing the friction between on-premise and data lake storage:
CREATE TABLE sales_hpt (
sale_id NUMBER,
region VARCHAR2(30),
sale_amount NUMBER,
sale_date DATE
)
PARTITION BY RANGE (sale_date)
INTERVAL (NUMTODSINTERVAL(1, 'MONTH'))
(
PARTITION p0 VALUES LESS THAN (TO_DATE('2020-01-01','YYYY-MM-DD'))
)
EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY ext_dir
ACCESS PARAMETERS (...)
LOCATION ('legacy_sales.csv')
);
Value proposition:
- Simplify archive strategies by co-locating recent data in Oracle and legacy data in external files.
- Write queries once—no
UNION ALLor external table shims required.
6. SQL Quarantine for Resilient Operations
In mission-critical environments, errant or runaway SELECT statements can jeopardize overall performance. Oracle 19c introduces SQL Quarantine, which automatically blocks queries that exceed predefined resource thresholds, protecting your SLA-bound workloads.
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(
plan => 'DEFAULT_PLAN',
group_or_subplan => 'OTHER_GROUP',
comment => 'Block runaway queries',
switch_time => 1,
switch_for_logging => TRUE
);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(
plan => 'DEFAULT_PLAN',
group_or_subplan => 'OTHER_GROUP',
comment => 'Quarantine queries over 5 minutes',
max_est_exec_time => 300,
switch_time => 0,
switch_for_quarantine => TRUE
);
END;
/
Guardrails advantage:
- Automatically isolate problematic queries for post-mortem analysis.
- Maintain consistent throughput for high-priority transactions.
Oracle 19c’s evolution of the SELECT statement weaves together corporate elegance and technical virtuosity. From richer aggregation to JSON fluency, real-time intelligence, and built-in resilience, these enhancements empower database professionals to craft queries that are not merely functional but poetic in their expressiveness and performance. Embrace these capabilities to unlock new heights of insight, efficiency, and reliability in your data ecosystem.
No Comments