SQLDaily
sqldaily.bsky.social
SQLDaily
@sqldaily.bsky.social
Daily Oracle SQL tips from the Oracle Developer Advocates for SQL
You can subtract one year from a date in Oracle #SQL with either

ADD_MONTHS ( dt, -12 )
- INTERVAL '1' YEAR

But take care - these handle 29th Feb differently:

ADD_MONTHS => 29th Feb -> 28th Feb in previous year
INTERVAL => 29th Feb -> 29th Feb in previous year => error!
October 6, 2025 at 11:03 AM
Get the top-N rows in Oracle #SQL with

FETCH FIRST n ROWS ONLY

You can include all rows with the same sort value as the Nth with

FETCH FIRST n ROWS WITH TIES

Or get a fraction of the rows with

FETCH FIRST n PERCENT ROWS [ ONLY | WITH TIES ]
September 8, 2025 at 11:03 AM
Use the right data type when defining #database columns, e.g.

Numbers => numeric type
Datetimes => date/timestamp type

Using the wrong data type leads to implicit type conversions which can:

Prevent index use => slow SQL
Be invalid => runtime errors

Choose wisely!
August 25, 2025 at 11:01 AM