Syntax: Functions
This page lists common functions tasks in five databases, so you can copy the form your database understands. Each task shows whether the SQL standard defines it (standard) or each database has its own way (dialect). For what each feature does and when to use it, follow the lesson link under each task. The SQL Syntax by Database page explains how to find out which database and version you're using.
How these were checked: every PostgreSQL and SQLite form on this page was run (PostgreSQL 18 and SQLite 3.54). MySQL, SQL Server and Oracle forms follow each database's current documentation (MySQL 8.4, SQL Server 2022 and later, Oracle AI Database 26ai); version notes such as "8.0.19+" mark features that older releases lack.
Join Text
Standard. Lesson: String Functions.
| Database | Syntax |
|---|---|
| PostgreSQL | first_name || ' ' || last_name |
| MySQL | CONCAT(first_name, ' ', last_name) |
| SQL Server | CONCAT(first_name, ' ', last_name) |
| Oracle | first_name || ' ' || last_name |
| SQLite | first_name || ' ' || last_name |
Text Length
Dialect. Lesson: String Functions.
| Database | Syntax |
|---|---|
| PostgreSQL | length(name) |
| MySQL | CHAR_LENGTH(name) |
| SQL Server | LEN(name) |
| Oracle | LENGTH(name) |
| SQLite | length(name) |
Part of a String
Standard. Lesson: String Functions.
| Database | Syntax |
|---|---|
| PostgreSQL | substring(name FROM 1 FOR 3) |
| MySQL | SUBSTRING(name, 1, 3) |
| SQL Server | SUBSTRING(name, 1, 3) |
| Oracle | SUBSTR(name, 1, 3) |
| SQLite | substr(name, 1, 3) |
Replace NULL
Standard. Lesson: NULL Functions.
| Database | Syntax |
|---|---|
| PostgreSQL | COALESCE(email, 'none') |
| MySQL | COALESCE(email, 'none') |
| SQL Server | COALESCE(email, 'none') |
| Oracle | COALESCE(email, 'none') |
| SQLite | COALESCE(email, 'none') |
Round to Cents
Dialect. Lesson: Numeric Functions.
| Database | Syntax |
|---|---|
| PostgreSQL | round(x, 2) |
| MySQL | ROUND(x, 2) |
| SQL Server | ROUND(x, 2) |
| Oracle | ROUND(x, 2) |
| SQLite | round(x, 2) |
Today's Date
Standard. Lesson: Dates and Times.
| Database | Syntax |
|---|---|
| PostgreSQL | CURRENT_DATE |
| MySQL | CURRENT_DATE |
| SQL Server | CAST(GETDATE() AS DATE) |
| Oracle | TRUNC(SYSDATE) |
| SQLite | date('now') |
Add 30 Days
Dialect. Lesson: Date Functions.
| Database | Syntax |
|---|---|
| PostgreSQL | d + 30 |
| MySQL | DATE_ADD(d, INTERVAL 30 DAY) |
| SQL Server | DATEADD(day, 30, d) |
| Oracle | d + 30 |
| SQLite | date(d, '+30 days') |
Days Between Dates
Dialect. Lesson: Date Functions.
| Database | Syntax |
|---|---|
| PostgreSQL | d2 - d1 |
| MySQL | DATEDIFF(d2, d1) |
| SQL Server | DATEDIFF(day, d1, d2) |
| Oracle | d2 - d1 |
| SQLite | julianday(d2) - julianday(d1) |
Year of a Date
Standard. Lesson: Date Functions.
| Database | Syntax |
|---|---|
| PostgreSQL | EXTRACT(YEAR FROM d) |
| MySQL | EXTRACT(YEAR FROM d) |
| SQL Server | YEAR(d) |
| Oracle | EXTRACT(YEAR FROM d) |
| SQLite | strftime('%Y', d) |
Format a Date
Dialect. Lesson: Date Functions.
| Database | Syntax |
|---|---|
| PostgreSQL | to_char(d, 'YYYY-MM-DD') |
| MySQL | DATE_FORMAT(d, '%Y-%m-%d') |
| SQL Server | FORMAT(d, 'yyyy-MM-dd') |
| Oracle | TO_CHAR(d, 'YYYY-MM-DD') |
| SQLite | strftime('%Y-%m-%d', d) |
Convert Text to a Number
Standard. Lesson: Type Conversion.
| Database | Syntax |
|---|---|
| PostgreSQL | CAST('450.00' AS NUMERIC) |
| MySQL | CAST('450.00' AS DECIMAL(8,2)) |
| SQL Server | CAST('450.00' AS DECIMAL(8,2)) |
| Oracle | CAST('450.00' AS NUMBER) |
| SQLite | CAST('450.00' AS REAL) |
If / Else
Standard. Lesson: CASE Expressions.
| Database | Syntax |
|---|---|
| PostgreSQL | CASE WHEN x > 0 THEN 'yes' ELSE 'no' END |
| MySQL | CASE WHEN x > 0 THEN 'yes' ELSE 'no' END |
| SQL Server | CASE WHEN x > 0 THEN 'yes' ELSE 'no' END |
| Oracle | CASE WHEN x > 0 THEN 'yes' ELSE 'no' END |
| SQLite | CASE WHEN x > 0 THEN 'yes' ELSE 'no' END |
Join Values from Many Rows
Standard. Lesson: String Functions.
| Database | Syntax |
|---|---|
| PostgreSQL | string_agg(name, ', ' ORDER BY name) |
| MySQL | GROUP_CONCAT(name ORDER BY name SEPARATOR ', ') |
| SQL Server | STRING_AGG(name, ', ') WITHIN GROUP (ORDER BY name) |
| Oracle | LISTAGG(name, ', ') WITHIN GROUP (ORDER BY name) |
| SQLite | group_concat(name, ', ' ORDER BY name) -- 3.44+ |
Try the PostgreSQL Forms
These run on the Fee Tracker in Try it:
SELECT first_name || ' ' || last_name AS full_name,
length(first_name) AS name_length,
COALESCE(email, 'none') AS email,
joined_on + 30 AS plus_30_days,
EXTRACT(YEAR FROM joined_on) AS joined_year
FROM students
ORDER BY student_id;
SELECT string_agg(title, ', ' ORDER BY title) AS java_courses
FROM courses WHERE technology = 'Java'; full_name | name_length | email | plus_30_days | joined_year
--------------------+-------------+--------------------------------+--------------+-------------
Srihitha Anamaneni | 8 | srihitha.anamaneni@example.com | 2024-09-18 | 2024
Advitha Anamaneni | 7 | none | 2025-02-12 | 2025
Navika Anamaneni | 6 | none | 2025-10-02 | 2025
(3 rows)
java_courses
-----------------------------------------
Java Basics, Java Collections, Java OOP
(1 row)Was this tutorial helpful?