SQL NUMERIC precision and scale
Defines the two knobs of an exact decimal column: precision p (total digits, up to 38 on SQL Server and Oracle) and scale s (digits after the point), and what happens past either.
- Category
- Math
- Returns
exact decimal- In this category
- 69 of 82
Syntax
NUMERIC(precision, scale)
DECIMAL(p, s)
Each block is a separate form. The support table and the examples show which engine takes which.
Engine support
| Engine | Support | Notes |
|---|---|---|
| SQL Server | Yes | p up to 38; DECIMAL and NUMERIC are synonyms |
| PostgreSQL | Yes | Declared p up to 1000; unconstrained numeric holds up to 131072 digits before the point and 16383 after |
| MySQL | Yes | p up to 65, s up to 30 |
| SQLite | Different name or syntax | NUMERIC(p, s) is parsed but ignored; NUMERIC affinity stores INTEGER, REAL or TEXT per value |
| Oracle | Yes | NUMBER(p, s), p up to 38; NUMERIC(p, s) and DECIMAL(p, s) are accepted as ANSI aliases. Bare NUMBER keeps up to 38 digits at any scale |
Examples
SQL Server
SELECT CAST(1234.567 AS NUMERIC(6, 2)) AS rounded; -- 1234.57, same on PostgreSQL, MySQL and Oracle
PostgreSQL
CREATE TABLE prices (amount NUMERIC(10, 2)); -- up to 99999999.99
SQLite
SELECT CAST(1234.567 AS NUMERIC(6, 2)) AS not_rounded; -- 1234.567: the (6, 2) is ignored
Good to know
- NUMERIC(5, 2) holds up to 999.99: five digits total, two after the point, three before. A sixth significant digit is an error, not a round.
- One-argument DECIMAL(p) means scale 0, an integer column, not a scale-only declaration. Bare NUMERIC is engine-specific: unconstrained on PostgreSQL, DECIMAL(18,0) on SQL Server, DECIMAL(10,0) on MySQL. Oracle writes NUMBER(*, s) for maximum precision.
- SQLite accepts the declaration and then ignores it: column affinity decides storage per value, so a NUMERIC(5,2) column can hold 123456.789 as REAL.
Questions about NUMERIC(p, s)
What does NUMERIC(10, 2) hold?
Values up to 99999999.99: ten significant digits, two of them after the point. The scale costs two of the ten digits, a common miscount when sizing money columns.
Is DECIMAL different from NUMERIC?
The standard lets DECIMAL(p, s) carry more precision than declared while NUMERIC(p, s) must be exactly p. In practice SQL Server, PostgreSQL, MySQL and SQLite treat them as synonyms, and Oracle maps both onto NUMBER.
Why does SQLite ignore my NUMERIC(5, 2)?
SQLite's type system is affinity-based: the declaration only nudges storage class choice per value. Enforce scale with triggers, or keep cents as INTEGER.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.