SQLDaily
sqldaily.bsky.social
SQLDaily
@sqldaily.bsky.social
Daily Oracle SQL tips from the Oracle Developer Advocates for SQL
Want to find the Nth highest value in a table?

e.g. the 3rd highest salary/department?

Number the values with

DENSE_RANK () OVER ( PARTITION BY ... ORDER BY ... DESC )

Then filter where the output of this is 3

Manish Sharma demos
What's The BEST Way to Find the 3rd HIGHEST Salary in SQL?
Find nth highest salary interview questions are some of the trickiest SQL challenges you’ll face. In this video, I’ll show you how to solve the 3rd highest salary problem with NULL handling, a real…
buff.ly
November 21, 2025 at 12:03 PM
How do the data types of join columns affect query performance?

@danischnider.bsky.social compares using

Hashes as CHAR(32) and RAW(16)
Sequences as NUMBER

And finds in Oracle #SQL

NUMBER is faster than RAW
RAW is faster than CHAR
Data Types of Join Columns
The data type of primary key and foreign key columns has an impact on the query performance. This should be considered in the design decision of keys in a Data Vault schema.
buff.ly
November 20, 2025 at 12:01 PM
Triggered by traumatic DML errors?

@antikyte.bsky.social shows how to recover in Oracle AI Database when you accidentally remove data with

FLASHBACK TABLE ... TO
BEFORE DROP => restore a dropped table
TIMESTAMP => revert to a point in time
Fixing data faux pas with flashback table #JoelKallmanDay
Triggered by traumatic DML errors ? Well, here’s one flashback you won’t mind having…
buff.ly
November 19, 2025 at 12:02 PM
Triggers are a common way to audit DML changes

But writing these can be fiddly

To help you with this, @zorantica.bsky.social has built

Data JAM for Oracle (Journaling & Auditing Module)

An #orclAPEX app to automate audt tables and triggers

Get it at
GitHub - zorantica/data-jam: Zoran's Auditing Module
Zoran's Auditing Module. Contribute to zorantica/data-jam development by creating an account on GitHub.
buff.ly
November 18, 2025 at 12:02 PM
In PL/SQL

EXCEPTION WHEN OTHERS THEN

Catches all errors

Filling your code with this without reraising the error hides unexpected issues

So the compiler raises PLW-6009 to warn you

If you reraise in custom logging procedures use

PRAGMA SUPPRESSES_WARNING_6009

To skip this warning
November 17, 2025 at 12:02 PM
Get free access to Oracle AI Database at freesql.com

This browser-based tool enables you to run and share #SQL statements

Even better, you can now connect to your schema from clients on your machine using SQL*Net

So you can run SQL from your favourite IDE
November 14, 2025 at 12:01 PM
Oracle Virtual Private Database enables you to transparently add WHERE clauses to restrict what users can see

See what was added with DBMS_UTILITY.EXPAND_SQL_TEXT

But this may expose sensitive values!

@connormcd.bsky.social shows how to hide them with contexts
Security predicates exposed #JoelKallmanDay
Since way back in version 8.1 of the database, there has been a cool feature in Oracle called Virtual Private Database (VPD), which essentially lets you force predicates into SQL statements run by …
buff.ly
November 13, 2025 at 12:02 PM
Want to find the fastest-growing tables or LOBs in Oracle AI Database?

@viniciusdba.com.br has built a script that analyzes AWR data to show

The 20 segments with the largest total size increases
A breakdown of the increase per month for each

Get it at
dba_scripts/seggrowth.sql at master · vinidba/dba_scripts
Some Scripts that I use on my daily basis. Contribute to vinidba/dba_scripts development by creating an account on GitHub.
buff.ly
November 12, 2025 at 12:01 PM
Poorly written #SQL can lead to slow, hard-to-maintain queries

@jordangoodman.bsky.social covers common anti-patterns you should avoid, including

Case expressions instead of tables
Functions on indexed columns
Overusing DISTINCT to “fix” duplicates
SQL Anti-Patterns You Should Avoid
Introduction
buff.ly
November 11, 2025 at 12:01 PM
Macros in Oracle #SQL enable you to define expression templates as text

At parse time the database merges these with the parent query, replacing parameters with the actual values passed

Macros come in two types

Scalar - use in SELECT, WHERE, ORDER BY, etc.
Table - use in FROM
November 10, 2025 at 12:02 PM
Oracle wins the multilingual text-to-SQL Archer Challenge by combining planning and #SQL agents

Understanding Archer queries requires

Arithmetic reasoning
Commonsense inference
Hypotheticals and counterfactuals
Bilingual execution (English + Chinese)
buff.ly
November 7, 2025 at 12:01 PM
The KEEP clause - aka FIRST/LAST functions - in Oracle #SQL enables you to get the min/max row for one column sorted by another

MIN ( salary ) KEEP ( DENSE_RANK FIRST ORDER BY hire )

=> Get the lowest salary for the first hire

@quanwenzhao.bsky.social explores it & alternatives
Oracle FIRST/LAST functions with KEEP clause #JoelKallmanDay
A few days ago I’ve noticed that Tim Hall have announced the fabulous Oracle community activity about writing the several blog notes on the same day that is Oct 15th this year (on the 2nd or …
buff.ly
November 6, 2025 at 12:02 PM
Create a flashback archive in Oracle AI Database to record all changes to a table

CREATE FLASHBACK ARCHIVE ... RETENTION ...
ALTER TABLE ... FLASHBACK ARCHIVE

Then view the changes with

SELECT * FROM ... VERSIONS BETWEEN ...

@Matt_Mulvaney demos
buff.ly
November 5, 2025 at 12:03 PM
Storing UUIDs as RAW values is more efficient than strings

But RAW can lead to implicit conversions => poor row estimates

If you're stuck with string comparisons @andrejsql.bsky.social shows how to improve row estimates with

Extended stats
Virtual columns
Fix Optimizer Estimate Issues from Implicit Conversions #JoelKallmanDay
Learn how implicit RAW-to-VARCHAR2 conversions in Oracle break histograms, hurt optimizer estimates, and how to fix them safely.
buff.ly
November 4, 2025 at 12:02 PM
You can generate UUIDs/GUIDs in Oracle AI Database with

SYS_GUID since "forever", sequential based on host & process
UUID since 23.7, random

But should you store these as RAW(16) or CHAR(32)?

@oyvindisene.bsky.social finds RAW is faster when querying a 100M row table
UUIDs in Oracle Database
UUIDs are useful, especially when you expose data in REST APIs, but there are cases where you may want to stick to the good old sequence-based primary key. UUIDs in Oracle Database #JoelKallmanDay…
buff.ly
November 3, 2025 at 12:01 PM
Oracle AI Database has several string similarity functions

SOUNDEX
PHONIC_ENCODE - double metaphone
FUZZY_MATCH - several algorithms, including Jaro-Winkler & Levenshtein

@brendan-tierney.bsky.social compares how they encode spelling variations of Brendan
Comparing Text using Soundex, PHONIC_ENCODE and FUZZY_MATCH
When comparing text strings we have a number of functions on Oracle Database to help us. These include SOUNDEX, PHONIC_ENCODE and FUZZY_MATCH. Let’s have a look at what each of these can do. …
buff.ly
October 31, 2025 at 12:03 PM
Edition-based redefinition enables zero-downtime app upgrades for Oracle AI Database

@nakdimon.bsky.social discusses why it's worth using when offline upgrades are OK:

Any time or length upgrades
Separate database & app upgrades
Flexible release of new versions
EBR - Even If Downtime Is Acceptable - @DBoriented
So, You Don’t Need Online Upgrades EBR is a set of features that enables patching and upgrading live Oracle-based applications in an online fashion, with zero downtime. If you are responsible for an…
buff.ly
October 30, 2025 at 12:03 PM
Database deployments can fail

But rolling back schema changes is tricky - so plan them

@jasminfluri.bsky.social runs through options

Versioned Migrations with Reversible Scripts
Backups before Changes
Immutable Migrations & Forward Fixes
Restore Points & Flashbacks
Database Rollbacks in CI/CD: Strategies and Pitfalls
Database rollbacks would be incredibly valuable and essential if we want quick fixes for failed deployments. But they are rarely feasible.
buff.ly
October 29, 2025 at 12:03 PM
SYSDATE in Oracle AI Database is evaluated once per

Statement in #SQL
Call in PL/SQL

Wrap SYSDATE in a DETERMINISTIC function to trick the compiler into evaluating it once/statement

But beware: this can lead to unwanted behaviour

@salvis.com explores
Is SYSDATE Deterministic? #JoelKallmanDay - Philipp Salvisberg's Blog
Is SYSDATE deterministic in Oracle Database? Explore definitions, test cases, and pitfalls when using SYSDATE vs deterministic functions.
buff.ly
October 28, 2025 at 12:03 PM
Daylight saving is ending across Europe and North America

But they change on different dates!

To see when the continents are an hour closer, @kibeha.dk built a pattern-matching query comparing the TIMEZONE_HOUR for dates across the year
DST diffs across the pond #JoelKallmanDay
It's that time of the year. It's time to say goodbye to summer. It's time to set the clock and get back to normal time. ... It's also time f...
buff.ly
October 27, 2025 at 12:04 PM
Query Apache Iceberg tables from Oracle AI Database using external tables

To do this, set the

ACCESS PARAMETERS (
com.oracle.bigdata.fileformat=parquet
com.oracle.bigdata.credential.name=...
com.oracle.bigdata.access_protocol=iceberg
)

Bryan Grenn demos
Oracle DB 23ai supports external Apache Iceberg tables
Oracle database 23ai supports External Tables defined on Apache Iceberg objects. This post goes through how to configure an external table on Iceberg.
buff.ly
October 24, 2025 at 11:03 AM
Oracle Database 23ai becomes Oracle AI Database 26ai when you apply the Oct 2025 Release Update

This adds a GRAPHQL table function that

Accepts #GraphQL queries
Maps fields to database tables and columns
Returns JSON

e.g.

SELECT * FROM GRAPHQL ( ' tab { col1 col2 } ' )
October 23, 2025 at 11:03 AM
Use Oracle Data Redaction to mask sensitive data in query results

Kajal Singh runs through the enhancements added to this in 23.6 for

Mathematical & set functions
Sorting & grouping
Views with expressions
Virtual columns in function-based indexes
buff.ly
October 22, 2025 at 11:03 AM
Create new list partitions when you insert new partition key values in Oracle #SQL by defining the table

PARTITION BY LIST ( ... ) AUTOMATIC

Or convert existing tables with

ALTER TABLE ... SET PARTITIONING AUTOMATIC

@antikyte.bsky.social demos
Getting Oracle to Create List Partitions automatically
I recently inherited the support of an application that had been written on Oracle 11g. One of the maintenance tasks was to create a new set of partitions every so often so that records with a new …
buff.ly
October 21, 2025 at 11:02 AM
Apply the Oct 2025 Release Update and Oracle Database 23ai becomes Oracle AI Database 26ai

This adds the QUALIFY clause

QUALIFY filters window functions after grouping
Like the HAVING clause does for aggregate functions

SELECT ... FROM ...
QUALIFY fn OVER ( ... ) > ...
October 20, 2025 at 11:02 AM