Learn Oracle SQL: what changes compared with standard SQL

Most of what you write in Oracle is plain standard SQL: SELECT, WHERE, JOIN, GROUP BY, CASE and window functions read the same as in our practice database. This page shows, side by side, where Oracle has its own way, and which lesson lets you practise the idea behind it.

In short: Oracle has no LIMIT. You write FETCH FIRST 3 ROWS ONLY (or the older ROWNUM). Text columns are VARCHAR2, numbers NUMBER, and a DATE always carries a time as well. An empty string '' counts as NULL. Instead of an upsert with ON CONFLICT you use MERGE, and automatic IDs come from identity columns or sequences. Everything else you learn in this course carries over.

What is Oracle SQL?

Oracle SQL is the SQL that Oracle Database understands. The current release is called Oracle AI Database 26ai and succeeds Oracle Database 23ai. Older versions such as 19c differ in places, and this page says where. The core of the language follows the SQL standard, so the queries from this course work almost unchanged. Oracle adds its own data types, functions and a few older notations that you will find in existing reports and job interviews. LearnThisNext is not affiliated with Oracle; this page summarises the Oracle documentation for learners.

Why this course works for Oracle

Our exercises run on SQLite. Like Oracle, SQLite joins text with ||, knows COALESCE, CASE, CTEs with WITH, window functions and CREATE TABLE … AS SELECT. SELECT, WHERE, JOIN, GROUP BY, HAVING, subqueries and UNION are the same everywhere anyway. Where Oracle differs, you find the Oracle version below with a link to the lesson where you practise the concept. For MySQL, PostgreSQL and SQL Server there is a separate comparison: MySQL vs PostgreSQL vs SQL Server.

Try it now

The three most recent orders, newest first. In the practice database you finish with LIMIT 3; the Oracle version follows right below the exercise.

Task The dashboard should show the three most recent orders. Show order_id, order_date and status for those three orders, newest first.

orders 18 rows, 5 columns
order_idcustomer_idorder_datestatusemployee_id
100112026-01-08delivered3
100242026-01-12delivered4
100332026-01-20delivered3
100472026-02-03delivered4
100522026-02-11cancelled8
100612026-02-25delivered3
1007102026-03-04delivered2
100852026-03-17delivered4
100982026-03-30delivered3
101062026-04-07delivered8
1011122026-04-22delivered4
101232026-05-06delivered3
101392026-05-19cancelled8
101472026-06-02shipped4
101512026-06-10shipped3
1016112026-06-12openNULL
101742026-06-13openNULL
1018102026-06-14openNULL

In Oracle, the same query ends with the row limiting clause from the SQL standard, available since Oracle Database 12c:

-- Oracle
SELECT order_id, order_date, status
FROM orders
ORDER BY order_date DESC
FETCH FIRST 3 ROWS ONLY;

The differences at a glance

TopicHere (SQLite)OraclePractise in
First n rowsLIMIT 3FETCH FIRST 3 ROWS ONLY, older: ROWNUMORDER BY
Skip rowsLIMIT 10 OFFSET 20OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLYORDER BY
Expression without a tableSELECT 2 * 3;SELECT 2 * 3 FROM dual; (FROM optional since Release 23)Calculations
Text, numbers, datesTEXT, INTEGER, REAL, dates as textVARCHAR2(100), NUMBER(10,2), DATE with timeCREATE TABLE
Empty text'' is not NULL'' is NULLNULL
Joining text|||| or CONCAT(); NULL is ignoredString functions
Replacement for NULLCOALESCE()COALESCE() or NVL()NULL and COALESCE
Month from a datestrftime('%Y-%m', order_date)TO_CHAR(order_date, 'YYYY-MM')Date functions
Automatic IDINTEGER PRIMARY KEYGENERATED ALWAYS AS IDENTITY or a sequencePrimary keys
Insert or updateON CONFLICT … DO UPDATEMERGEUpsert
Several rows in one INSERTVALUES (…), (…)same since 23ai, before: INSERT … SELECT … FROM dual UNION ALL …INSERT
UPDATE with values from another tablesubquery in SETsubquery, MERGE, or UPDATE … FROM since 23aiUPDATE
Outer joinLEFT JOINLEFT JOIN, in old code (+)LEFT JOIN
Rows of the first query onlyEXCEPTMINUS (EXCEPT also in current versions)UNION
Empty a tableDELETE FROM t;TRUNCATE TABLE t; (cannot be rolled back)DELETE
Copy a table, rename a columnCREATE TABLE … AS SELECT, RENAME COLUMNsameALTER TABLE
HierarchiesWITH RECURSIVEWITH without RECURSIVE, or CONNECT BYRecursive queries

Where Oracle differs, with examples

The first rows: FETCH FIRST and ROWNUM

-- Here
SELECT name, price FROM products ORDER BY price DESC LIMIT 5;

-- Oracle
SELECT name, price FROM products ORDER BY price DESC FETCH FIRST 5 ROWS ONLY;
SELECT name, price FROM products ORDER BY price DESC OFFSET 5 ROWS FETCH NEXT 5 ROWS ONLY;

In older code you will see ROWNUM. It numbers rows in the order Oracle reads them, before ORDER BY. That is why WHERE ROWNUM <= 5 ORDER BY price DESC returns five arbitrary rows, sorted afterwards. The documentation's fix is to sort inside a subquery and filter outside:

SELECT * FROM (SELECT name, price FROM products ORDER BY price DESC)
WHERE ROWNUM <= 5;

A condition like ROWNUM > 1 never returns a row, according to the documentation.

DUAL: a table with exactly one row

For years, Oracle required a FROM clause in every SELECT. For calculations without a table there is DUAL, a table with exactly one row. Since Release 23 the FROM clause is optional for such queries, but you will still find FROM dual in nearly every script and textbook.

SELECT SYSDATE FROM dual;          -- current date and time
SELECT ROUND(19.99 * 1.19, 2) FROM dual;
SELECT 2 * 3;                      -- since Release 23 (23ai)

Data types: VARCHAR2, NUMBER and DATE

-- Oracle
CREATE TABLE categories (
  category_id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  name        VARCHAR2(100) NOT NULL,
  margin      NUMBER(5,2),
  created     DATE DEFAULT SYSDATE
);

VARCHAR2 is variable-length text; Oracle advises against plain VARCHAR because its meaning may change in a future release. NUMBER(p,s) covers whole numbers and decimals. Important for queries: a DATE stores year, month, day, hour, minute and second. If a value contains a time, WHERE order_date = DATE '2026-06-18' misses it; TRUNC(order_date) removes the time first.

An empty string is NULL

Oracle treats a string of length zero as NULL. In our practice database, '' and NULL are two different things. In Oracle, WHERE phone = '' never finds a row; you write WHERE phone IS NULL. The documentation adds that this may change in future releases and recommends not treating empty strings as NULL in your own logic. The safe habit for both worlds: test for missing values with IS NULL.

Joining text: || and CONCAT

SELECT first_name || ' ' || last_name AS full_name FROM employees;
SELECT CONCAT(first_name, last_name) FROM employees;

|| works as it does here. One difference catches people out: in SQLite, 'Smith' || NULL gives NULL; in Oracle it gives 'Smith', because NULL counts as an empty string. Only two NULLs give NULL. In the current documentation CONCAT accepts two or more arguments; in 19c it takes exactly two.

NVL and COALESCE

SELECT name, NVL(phone, 'no number') AS phone FROM customers;       -- Oracle only
SELECT name, COALESCE(phone, 'no number') AS phone FROM customers;  -- everywhere

NVL takes exactly two values, COALESCE any number of them and returns the first that is not NULL. Both exist in Oracle and both are on the exam list. In the practice database, NVL gets the reply: “NVL() does not exist in this practice database (SQLite). For a replacement for NULL, use COALESCE(column, replacement).”

Dates: TO_CHAR, TO_DATE and arithmetic

-- Here (dates stored as text)
SELECT strftime('%Y-%m', order_date) AS order_month FROM orders;
SELECT date(order_date, '+7 days') FROM orders;

-- Oracle
SELECT TO_CHAR(order_date, 'YYYY-MM') AS order_month FROM orders;
SELECT order_date + 7 FROM orders;                         -- one week later
SELECT DATE '2026-06-30' - DATE '2026-06-01' FROM dual;    -- 29 (days)
SELECT TO_DATE('17.11.2026', 'DD.MM.YYYY') FROM dual;      -- text to date

Oracle reads a number added to a date as days: SYSDATE + 1 is tomorrow, and subtracting two dates returns the days between them. The literal DATE '2026-06-18' always uses the form YYYY-MM-DD and has no time part.

Automatic IDs: identity columns and sequences

-- identity column (since Oracle Database 12c)
CREATE TABLE notes (
  note_id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  text    VARCHAR2(400)
);

-- sequence: a number generator of its own
CREATE SEQUENCE order_seq START WITH 2001 INCREMENT BY 1;
INSERT INTO orders (order_id, customer_id, order_date, status)
VALUES (order_seq.NEXTVAL, 4, DATE '2026-11-17', 'open');

With ALWAYS, Oracle rejects a value you supply yourself; with BY DEFAULT, your value wins. Sequences are separate database objects: NEXTVAL returns the next number, CURRVAL the number NEXTVAL last returned in your session. In our course the database assigns the ID itself; the idea is the same.

MERGE instead of ON CONFLICT

-- Here
INSERT INTO products (product_id, name, price, stock)
VALUES (12, 'Desk lamp', 39.90, 5)
ON CONFLICT (product_id) DO UPDATE SET stock = stock + excluded.stock;

-- Oracle
MERGE INTO products p
USING goods_in g
ON (p.product_id = g.product_id)
WHEN MATCHED THEN UPDATE SET p.stock = p.stock + g.quantity
WHEN NOT MATCHED THEN INSERT (product_id, name, price, stock)
  VALUES (g.product_id, g.name, g.price, g.quantity);

MERGE compares a source with the target table: matching rows are updated, missing ones inserted. The condition after ON goes in parentheses. You learn the idea behind it in the upsert lesson.

Several rows in one INSERT

-- Here, and in Oracle since 23ai
INSERT INTO customers (name, city, country, segment)
VALUES ('Lorenz Animal Clinic', 'Denver', 'USA', 'Business'),
       ('Emma Fisher', 'Austin', 'USA', 'Consumer');

-- Oracle before 23ai: one SELECT per row from DUAL
INSERT INTO customers (name, city, country, segment)
SELECT 'Lorenz Animal Clinic', 'Denver', 'USA', 'Business' FROM dual UNION ALL
SELECT 'Emma Fisher', 'Austin', 'USA', 'Consumer' FROM dual;

INSERT ALL is something else: one source row goes into several INTO clauses, even into different tables. The exam calls this a multi-table insert.

UPDATE with values from another table

The subquery version you practise in the exercise below runs unchanged in Oracle. Since 23ai, Oracle also accepts a direct join with FROM; before that, MERGE was the usual route:

-- Oracle since 23ai
UPDATE order_items i
SET i.unit_price = p.price
FROM products p
WHERE i.product_id = p.product_id;

Outer joins with (+)

-- standard, also in Oracle
SELECT c.name, o.order_id
FROM customers c LEFT JOIN orders o ON o.customer_id = c.customer_id;

-- old Oracle notation, same result
SELECT c.name, o.order_id
FROM customers c, orders o
WHERE c.customer_id = o.customer_id(+);

The (+) goes on the side that may be missing. Oracle itself recommends the LEFT JOIN syntax, and you cannot mix both in one query block. You will still meet (+) in older reports and on the exam.

MINUS, TRUNCATE and table operations

  • MINUS: rows of the first query that are missing from the second. The current documentation lists EXCEPT as a synonym; the 19c documentation only knows MINUS.
  • TRUNCATE TABLE: removes all rows at once. Unlike DELETE, it cannot be rolled back.
  • CREATE TABLE … AS SELECT and ALTER TABLE … RENAME COLUMN … TO … look the same as in our CREATE TABLE and ALTER TABLE lessons.

Hierarchies: WITH and CONNECT BY

-- Oracle: recursive WITH, without the word RECURSIVE, with a column list
WITH chain (employee_id, last_name, lvl) AS (
  SELECT employee_id, last_name, 1 FROM employees WHERE manager_id IS NULL
  UNION ALL
  SELECT e.employee_id, e.last_name, c.lvl + 1
  FROM employees e JOIN chain c ON e.manager_id = c.employee_id
)
SELECT * FROM chain;

-- Oracle's own notation
SELECT last_name, LEVEL
FROM employees
START WITH manager_id IS NULL
CONNECT BY PRIOR employee_id = manager_id;

Oracle requires UNION ALL between the anchor and the recursive part. CONNECT BY is older and specific to Oracle; START WITH names the top of the tree, PRIOR the parent row. The concept is the same as in our lesson on recursive queries.

Exercise: a phone list without gaps

Solve it with COALESCE. In Oracle you could also write NVL. Bear in mind that a phone number stored as '' would already be NULL there.

Task Sales wants a phone list: show the name and phone of every customer. Where no number is on file, the list should say no number instead of leaving the cell blank.

customers 12 rows, 7 columns
customer_idnamecitycountrycustomer_sincesegmentphone
1Harbor Fremont PartnersBostonUSA2021-03-15Business617-555-0142
2Emily CarterChicagoUSA2022-07-01ConsumerNULL
3Riverside County OfficeRiversideUSA2020-11-20Government951-555-0110
4Raj PatelLeedsUK2023-01-09Consumer0113 496 0123
5Lakeview Hotel LtdManchesterUK2022-04-18Business0161 496 0456
6Olivia BrooksAustinUSA2024-02-27ConsumerNULL
7Greene & Shaw LLPLondonUK2021-09-05Business020 7946 0321
8Maple Grove High SchoolAustinUSA2023-08-14School512-555-0187
9Chloe EvansBostonUSA2025-05-30Consumer617-555-0199
10Northline Printing CoTorontoCanada2020-06-12Business416-555-0133
11Daniel KimSeattleUSA2024-10-03ConsumerNULL
12Westbrook Dental ClinicChicagoUSA2022-12-01Business312-555-0164

Exercise: update prices from another table

This correlated subquery in SET and the IN list in WHERE run in Oracle exactly as written. The exam topics list this pattern as “update and delete rows using correlated subqueries”.

Task Before shipping, every open order should be billed at the current list price. In order_items, set unit_price to the product's price from products, but only for items that belong to orders whose status in orders is open. After Run or Check you will see the items whose price actually changed.

order_items 38 rows, 4 columns
order_idproduct_idquantityunit_price
10011404.79
10013252.79
10016424.9
1002223.49
10021035.49
10031604.69
100311684.9
10033502.59
100443179
100493269
100551449
10061304.79
10067106.99
100782219
100711489.9
10071204.99
100846175
1008253.49
1009101204.99
10092403.19
100992279
1010726.99
1010213.49
1011121129
10111104.99
10113122.79
10126823.9
10121404.69
101391279
101452439
101442179
10151504.79
101511289.9
10161045.49
1017233.49
1017726.99
10181804.79
101861024.9
products 12 rows, 5 columns
product_idnamecategorypricestock
1Copy paper, 500 sheetsPaper4.99420
2Blue ballpoint pens, 10-packWriting3.49310
3Lever arch file, grayFiling2.79185
4Comfort office chairFurniture18912
5Standing deskFurniture4495
6Black ink cartridgePrinter supplies24.964
7Yellow sticky notes, 12 padsWriting6.990
8Mono laser printer L30Electronics2198
927-inch monitorElectronics27915
10Notebook A5, ruledPaper5.49140
11Black toner XLPrinter supplies89.922
12Cross-cut shredderElectronics1290
orders 18 rows, 5 columns
order_idcustomer_idorder_datestatusemployee_id
100112026-01-08delivered3
100242026-01-12delivered4
100332026-01-20delivered3
100472026-02-03delivered4
100522026-02-11cancelled8
100612026-02-25delivered3
1007102026-03-04delivered2
100852026-03-17delivered4
100982026-03-30delivered3
101062026-04-07delivered8
1011122026-04-22delivered4
101232026-05-06delivered3
101392026-05-19cancelled8
101472026-06-02shipped4
101512026-06-10shipped3
1016112026-06-12openNULL
101742026-06-13openNULL
1018102026-06-14openNULL

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

Trying Oracle for free

  • FreeSQL: Oracle's browser worksheet at freesql.com, described on the Oracle AI Database Free page as a free sandbox for developing SQL. The former Live SQL address livesql.oracle.com now leads there.
  • Oracle AI Database 26ai Free: a free edition to install, for Windows, Linux and as a container image (on a Mac via Docker). Limits according to Oracle: up to 2 CPU threads, 2 GB of database RAM and 12 GB of user data.

Our practice database is not an Oracle database. It is enough for learning the logic of SQL; for the Oracle-specific notations on this page, use one of the two tools above.

Oracle certification

If you are aiming for the Oracle Database SQL exam (1Z0-071): Oracle Database SQL Certified Associate (1Z0-071) lists the official exam topics and maps each one to our lessons, including what our course does not cover.

FAQ

Is Oracle SQL different from SQL?

Oracle SQL is SQL with Oracle-specific additions. SELECT, WHERE, JOIN, GROUP BY, subqueries and window functions are written as in the standard. The differences are in data types, some functions (NVL, TO_CHAR, TO_DATE), row limiting and older notations such as (+) and CONNECT BY.

How do I select the top 10 rows in Oracle?

Sort first, then limit: ORDER BY … FETCH FIRST 10 ROWS ONLY. In versions before 12c, sort in a subquery and filter outside with WHERE ROWNUM <= 10.

How do I insert multiple rows in Oracle?

Since 23ai with several row groups after VALUES, as in our course. In older versions with INSERT INTO … SELECT … FROM dual UNION ALL SELECT … FROM dual.

How do I update with a join in Oracle?

With a correlated subquery in SET (works in every version), with MERGE, or since 23ai with UPDATE … SET … FROM other_table WHERE ….

Does SELECT INTO create a table in Oracle?

No. To copy a table, use CREATE TABLE new_table AS SELECT …. SELECT … INTO belongs to PL/SQL, Oracle's programming language, and fills variables there.

Which version does this page cover?

We checked everything against the Oracle SQL Language Reference for Oracle AI Database 26ai. Where older versions behave differently, the text names the version (12c, 19c, 23ai).

Sources: Oracle AI Database SQL Language Reference 26ai on docs.oracle.com (SELECT with row_limiting_clause and values_clause, ROWNUM Pseudocolumn, Selecting from the DUAL Table, Data Types, Nulls, Concatenation Operator, CONCAT, NVL, COALESCE, TO_CHAR (datetime), TO_DATE, Literals, CREATE TABLE identity_clause, CREATE SEQUENCE, Sequence Pseudocolumns, MERGE, INSERT, UPDATE, Joins, The UNION [ALL], INTERSECT, MINUS Operators, TRUNCATE TABLE, ALTER TABLE, Hierarchical Queries), PL/SQL Language Reference (SELECT INTO Statement), SQL Language Reference 12.1 and 19c for the version notes, Oracle AI Database New Features (SQL), Oracle tutorial “Oracle Database 23ai SQL features” on docs.oracle.com/en/learn, oracle.com/database/free, freesql.com; checked 17 November 2026.

Next up: the first lesson

The course starts with your first query and takes you through JOIN, GROUP BY, CTEs and window functions. Nearly all of it is written the same way in Oracle.

Start with the basics

Write to us

Choose language

Select your preferred language