Skip to content

feat: parse Oracle RAW(n) and NUMBER(*, s) data types - #2875

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
knutwannheden:jsqlparser-parse-oracle-raw-n-and-number-s
Oct 31, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
knutwannheden:jsqlparser-parse-oracle-raw-n-and-number-s

Conversation

@knutwannheden

Copy link
Copy Markdown
Contributor

DDL exported from Oracle with DBMS_METADATA.GET_DDL spells an INTEGER column as NUMBER(*,0), keeps NUMBER(*,2) as written, and prints binary columns as RAW(16). None of these parse on master, neither in column definitions nor as CAST targets:

CREATE TABLE t (id RAW(16))
  Encountered: <K_RAW> / "RAW", at line 1, column 20
CREATE TABLE t (a NUMBER(*,0))
  Wildcard type arguments are only supported for VECTOR
SELECT CAST(1.5 AS NUMBER(*,0)), CAST(HEXTORAW('AB') AS RAW(16)) FROM dual
  same two errors

Oracle 21c accepts all of them: CREATE TABLE t (a NUMBER(*,0), b NUMBER(*), c RAW(16), d INTEGER, e NUMBER(*,2)) succeeds, and so does the SELECT above. A downstream consumer parsing such exports ran into both.

RAW is a non-reserved keyword token that ColDataType() did not list among its type-name tokens. It is listed now, so RAW(16) is handled like any other identifier type with a length argument, and the other K_RAW uses (FOR XML RAW, DDL parameter lists) are untouched.

NUMBER(*, s) takes the same path as NUMBER(p, s) rather than the generic argument list that VECTOR(*, *) uses since #2845: DataType() accepts * in its precision slot, for NUMBER only, and ColDataType folds it into the type name the way it folds a numeric precision. The scale stays a scale, so both spellings expose the same shape:

NUMBER(5, 0)  getDataType() "NUMBER (5, 0)"  getPrecision() 5     getScale() 0
NUMBER(*, 0)  getDataType() "NUMBER (*, 0)"  getPrecision() null  getScale() 0

The scale slot is unchanged, so NUMBER(*, *) is rejected, and VARCHAR(*) and NUMERIC(3, *) are rejected as before. Neither form is gated on the Oracle dialect; checkGrammarAmbiguity reports no conflicts.

Tests: ColDataTypeTest.testOracleNumberWithWildcardPrecision and testOracleRawType cover the CREATE TABLE, ALTER TABLE ADD and CAST round trips and the NUMBER(*, *) rejection. Both failed with the errors above before the grammar change.

DDL exported from Oracle with DBMS_METADATA.GET_DDL prints an INTEGER
column as NUMBER(*,0) and binary columns as RAW(16). CREATE TABLE and
ALTER TABLE with such columns failed to parse, and so did
CAST(x AS NUMBER(*,0)) and CAST(x AS RAW(16)).

RAW is a keyword token, so ColDataType did not accept it as a type name.
NUMBER(*, s) now takes the same path as NUMBER(p, s): DataType() accepts
* in its precision slot for NUMBER only, and ColDataType folds it into
the type name as "NUMBER (*, 0)" with a null precision and the scale
set. NUMBER(*, *) and VARCHAR(*) stay rejected.
@manticore-projects
manticore-projects merged commit 83f9066 into JSQLParser:master Oct 31, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants