Class SqlUtils
This class changes for different versions of Oracle. Copyright 2003-2026 ATB Consultancy Services Ltd (formerly Orinda Software Ltd, Dublin, Ireland)
- Version:
- 7
- Author:
- devteam@mcpdbwizard.com
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConstant for identifying statements as being DDL statementsstatic final intConstant for identifying statements as being deletesstatic final intConstant for ORA-17059 message - invalid name pattern The most common cause for this is a DB/Driver version mismatchstatic final StringThe comment every generated statement carries, so a DBA can find this product's SQL inV$SQLwithout knowing what the application was called.static final intConstant for identifying statements as being insertsstatic final intConstant for ORA-17074 message - invalid name patternstatic final intConstant for identifying statements as being Lock statementsstatic final intConstant for identifiying PL/SQL Booleanstatic final intConstant for identifying statements as being Merge statementsstatic final intConstant for ORA-4043 - Object does not existstatic final intConstant for identifiying oracle BFILE datatypesstatic final intConstant for identifiying oracle Binary datatypesstatic final intConstant for identifiying oracle BLOB datatypesstatic final intConstant for identifiying PL/SQL Booleanstatic final intConstant for identifiying oracle CLOB datatypesstatic final intConstant for identifiying oracle Date datatypesstatic final intConstant for identifiying INTERVAL DAY TO SECOND Datatypestatic final intConstant for identifiying INTERVAL YEAR TO MONTH Datatypestatic final intConstant for identifiying the native JSON datatype.static final intConstant for identifiying oracle Long Binary datatypesstatic final intConstant for identifiying oracle Long Text datatypesstatic final intConstant for identifiying the native (ISO-SQL) BOOLEAN column datatype.static final intConstant for identifiying null datatypesstatic final intConstant for identifiying oracle Number datatypesstatic final intConstant for identifiying Oracle OBJECT Datatypestatic final intConstant for identifiying unrecognized oracle datatypesstatic final intConstant for identifiying PL/SQL Index By tablesstatic final intConstant for identifiying PL/SQL Index By tablesstatic final intConstant for identifiying oracle ref cursorsstatic final intConstant for identifiying ROWIDstatic final intConstant for identifiying PL/SQL Rowtype Datatypestatic final intConstant for identifiying ORACLE_SDO_GEOMETRY_DATATYPEstatic final intConstant for identifiying oracle Collection's TABLEstatic final intConstant for identifiying oracle Text datatypesstatic final intConstant for identifiying TIMESTAMPstatic final intConstant for identifiying TIMESTAMPLTZstatic final intConstant for identifiying TIMESTAMPTZstatic final intConstant for identifiying UROWIDstatic final intConstant for identifiying oracle Collection's VARRAYstatic final intConstant for identifiying a native VECTOR whose storage format isBINARY(bit-packed).static final intConstant for identifiying the VECTOR datatype (AI vector embeddings).static final intConstant for identifiying a native VECTOR whose storage isSPARSE(index/value pairs rather than a dense array).static final intConstant for identifiying XMLTypestatic final intConstant for identifying statements as being PL/SQL statementsstatic final String[]Array containing words which are not legal identifers...static final intConstant for identifying statements as being Lock statementsstatic final intConstant for identifying statements as being queriesstatic final intConstant for identifying statements as being Lock statementsstatic final intConstant for identifying statements as being Lock statementsstatic final intConstant for identifying statements as being Lock statementsstatic final intConstant for ORA-2303 message - cannot drop or replace a type with type or table dependentsstatic final intConstant for identifying statements as being unidentifiablestatic final intConstant for identifying statements as being updatesstatic final intConstant for identifying statements as being Lock statements -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcountParameters(String aSqlStatement) Count the JDBC bind parameters in a SQL statement.static oracle.sql.BFILEcreateBfileLocator(String theOracleDirectory, String theFileName, Connection theConnection, LogInterface theLog, boolean debugMessages) Create and return a BFILE locator.static intgetStatementType(String theStatement) Classify a SQL statement as a SELECT, INSERT, UPDATE, etc.static intgetUnderlyingOracleDatatype(String theColumnDataType) Return anintthat represents the underlying oracle data type.static intgetVectorDatatypeFromInfo(String vectorInfo) Refine a native VECTOR column's datatype code from itsUSER/ALL_TAB_COLUMNS.VECTOR_INFOdescriptor.static StringnormaliseTypeSpec(String theSpec) Reduce an Oracle TYPE specification to the form that two spellings of the same type share.
-
Field Details
-
SELECT
public static final int SELECTConstant for identifying statements as being queries- See Also:
-
INSERT
public static final int INSERTConstant for identifying statements as being inserts- See Also:
-
UPDATE
public static final int UPDATEConstant for identifying statements as being updates- See Also:
-
DELETE
public static final int DELETEConstant for identifying statements as being deletes- See Also:
-
DDL
public static final int DDLConstant for identifying statements as being DDL statements- Since:
- 2.0.1527 Support for Lock, Merge and DDL statements
- See Also:
-
LOCK
public static final int LOCKConstant for identifying statements as being Lock statements- Since:
- 2.0.1527 Support for Lock, Merge and DDL statements
- See Also:
-
MERGE
public static final int MERGEConstant for identifying statements as being Merge statements- Since:
- 2.0.1527 Support for Lock, Merge and DDL statements
- See Also:
-
XPLAN
public static final int XPLANConstant for identifying statements as being Lock statements- Since:
- 2.0.1527 Support for Lock, Merge and DDL statements
- See Also:
-
SAVEPOINT
public static final int SAVEPOINTConstant for identifying statements as being Lock statements- Since:
- 2.0.1527 Support for Lock, Merge and DDL statements
- See Also:
-
SET_CONSTRAINTS
public static final int SET_CONSTRAINTSConstant for identifying statements as being Lock statements- Since:
- 2.0.1527 Support for Lock, Merge and DDL statements
- See Also:
-
SET_TRANSACTION
public static final int SET_TRANSACTIONConstant for identifying statements as being Lock statements- Since:
- 2.0.1527 Support for Lock, Merge and DDL statements
- See Also:
-
SET_ROLE
public static final int SET_ROLEConstant for identifying statements as being Lock statements- Since:
- 2.0.1527 Support for Lock, Merge and DDL statements
- See Also:
-
PLSQL
public static final int PLSQLConstant for identifying statements as being PL/SQL statements- Since:
- 2.0.1527 Support for Lock, Merge and DDL statements
- See Also:
-
UNKNOWN
public static final int UNKNOWNConstant for identifying statements as being unidentifiable- See Also:
-
RESERVED_WORDS
Array containing words which are not legal identifers... -
ORACLE_TEXT_DATATYPE
public static final int ORACLE_TEXT_DATATYPEConstant for identifiying oracle Text datatypes- See Also:
-
ORACLE_NUMBER_DATATYPE
public static final int ORACLE_NUMBER_DATATYPEConstant for identifiying oracle Number datatypes- See Also:
-
ORACLE_DATE_DATATYPE
public static final int ORACLE_DATE_DATATYPEConstant for identifiying oracle Date datatypes- See Also:
-
ORACLE_LONGTEXT_DATATYPE
public static final int ORACLE_LONGTEXT_DATATYPEConstant for identifiying oracle Long Text datatypes- See Also:
-
ORACLE_LONG_BINARY_DATATYPE
public static final int ORACLE_LONG_BINARY_DATATYPEConstant for identifiying oracle Long Binary datatypes- See Also:
-
ORACLE_BINARY_DATATYPE
public static final int ORACLE_BINARY_DATATYPEConstant for identifiying oracle Binary datatypes- See Also:
-
ORACLE_CLOB_DATATYPE
public static final int ORACLE_CLOB_DATATYPEConstant for identifiying oracle CLOB datatypes- See Also:
-
ORACLE_BLOB_DATATYPE
public static final int ORACLE_BLOB_DATATYPEConstant for identifiying oracle BLOB datatypes- See Also:
-
ORACLE_BFILE_DATATYPE
public static final int ORACLE_BFILE_DATATYPEConstant for identifiying oracle BFILE datatypes- See Also:
-
ORACLE_REFCURSOR_DATATYPE
public static final int ORACLE_REFCURSOR_DATATYPEConstant for identifiying oracle ref cursors- See Also:
-
ORACLE_BOOLEAN_DATATYPE
public static final int ORACLE_BOOLEAN_DATATYPEConstant for identifiying PL/SQL Boolean- See Also:
-
MCPDBWIZARD_READONLYROWSET
public static final int MCPDBWIZARD_READONLYROWSETConstant for identifiying PL/SQL Boolean- See Also:
-
ORACLE_ROWID_DATATYPE
public static final int ORACLE_ROWID_DATATYPEConstant for identifiying ROWID- See Also:
-
ORACLE_UROWID_DATATYPE
public static final int ORACLE_UROWID_DATATYPEConstant for identifiying UROWID- See Also:
-
ORACLE_TIMESTAMP_DATATYPE
public static final int ORACLE_TIMESTAMP_DATATYPEConstant for identifiying TIMESTAMP- See Also:
-
ORACLE_TIMESTAMPTZ_DATATYPE
public static final int ORACLE_TIMESTAMPTZ_DATATYPEConstant for identifiying TIMESTAMPTZ- See Also:
-
ORACLE_TIMESTAMPLTZ_DATATYPE
public static final int ORACLE_TIMESTAMPLTZ_DATATYPEConstant for identifiying TIMESTAMPLTZ- See Also:
-
ORACLE_TABLE_DATATYPE
public static final int ORACLE_TABLE_DATATYPEConstant for identifiying oracle Collection's TABLE- See Also:
-
ORACLE_VARRAY_DATATYPE
public static final int ORACLE_VARRAY_DATATYPEConstant for identifiying oracle Collection's VARRAY- See Also:
-
ORACLE_OBJECT_DATATYPE
public static final int ORACLE_OBJECT_DATATYPEConstant for identifiying Oracle OBJECT Datatype- See Also:
-
ORACLE_ROWTYPE_DATATYPE
public static final int ORACLE_ROWTYPE_DATATYPEConstant for identifiying PL/SQL Rowtype Datatype- See Also:
-
ORACLE_INTERVAL_YEAR_TO_MONTH_DATATYPE
public static final int ORACLE_INTERVAL_YEAR_TO_MONTH_DATATYPEConstant for identifiying INTERVAL YEAR TO MONTH Datatype- See Also:
-
ORACLE_INTERVAL_DAY_TO_SECOND_DATATYPE
public static final int ORACLE_INTERVAL_DAY_TO_SECOND_DATATYPEConstant for identifiying INTERVAL DAY TO SECOND Datatype- Since:
- Oracle 10.1.0
- See Also:
-
ORACLE_PLSQL_INDEXBY_DATATYPE
public static final int ORACLE_PLSQL_INDEXBY_DATATYPEConstant for identifiying PL/SQL Index By tables- Since:
- Oracle 10.1.0
- See Also:
-
ORACLE_PLSQL_INDEXBY_ROWTYPE_DATATYPE
public static final int ORACLE_PLSQL_INDEXBY_ROWTYPE_DATATYPEConstant for identifiying PL/SQL Index By tables- Since:
- Oracle 10.1.0
- See Also:
-
ORACLE_XMLTYPE_DATATYPE
public static final int ORACLE_XMLTYPE_DATATYPEConstant for identifiying XMLType- Since:
- Oracle 10.2.0
- See Also:
-
ORACLE_SDO_GEOMETRY_DATATYPE
public static final int ORACLE_SDO_GEOMETRY_DATATYPEConstant for identifiying ORACLE_SDO_GEOMETRY_DATATYPE- Since:
- Oracle 10.2.0
- See Also:
-
ORACLE_JSON_DATATYPE
public static final int ORACLE_JSON_DATATYPEConstant for identifiying the native JSON datatype.The binary (OSON) JSON column type. Read through the JDBC driver as an
oracle.sql.json.OracleJsonValue.- Since:
- Oracle 21c
- See Also:
-
ORACLE_NATIVE_BOOLEAN_DATATYPE
public static final int ORACLE_NATIVE_BOOLEAN_DATATYPEConstant for identifiying the native (ISO-SQL) BOOLEAN column datatype.This is the real
BOOLEANcolumn type, distinct from the older PL/SQL-only boolean (ORACLE_BOOLEAN_DATATYPE). It arrives from the driver as aBoolean.- Since:
- Oracle 23ai
- See Also:
-
ORACLE_VECTOR_DATATYPE
public static final int ORACLE_VECTOR_DATATYPEConstant for identifiying the VECTOR datatype (AI vector embeddings).Covers
VECTORand its dimensioned/typed forms (VECTOR(3, FLOAT32),VECTOR_FLOAT64,VECTOR_INT8, ...). Read through the JDBC driver as adouble[](orfloat[]/byte[]for the storage-typed accessors).- Since:
- Oracle 23ai
- See Also:
-
ORACLE_VECTOR_BINARY_DATATYPE
public static final int ORACLE_VECTOR_BINARY_DATATYPEConstant for identifiying a native VECTOR whose storage format isBINARY(bit-packed).Distinct from the dense-numeric
ORACLE_VECTOR_DATATYPEbecause a binary vector cannot be read/bound as adouble[](the driver throwsORA-17004); its natural Java representation is abyte[](nbits =n/8bytes), bound viaoracle.jdbc.OracleType.VECTOR_BINARY. The format is not visible inDATA_TYPE(always"VECTOR"); it is derived from theUSER/ALL_TAB_COLUMNS.VECTOR_INFOdescriptor — seegetVectorDatatypeFromInfo(String).- Since:
- Oracle 23ai
- See Also:
-
ORACLE_VECTOR_SPARSE_DATATYPE
public static final int ORACLE_VECTOR_SPARSE_DATATYPEConstant for identifiying a native VECTOR whose storage isSPARSE(index/value pairs rather than a dense array).Recognised so the generator can detect and skip/flag such a column rather than emit the dense
double[]path that fails on it. NOTE: sparse vectors are not readable by the currently bundled Oracle JDBC driver (ojdbc11 23.7 throwsORA-17004for every Java type and provides noVECTOR_SPARSEbind type), so no read/write support is wired for this constant yet — seedocs/oracle23ai-vector-subformats-plan.md. Derived fromVECTOR_INFO— seegetVectorDatatypeFromInfo(String).- Since:
- Oracle 23ai
- See Also:
-
ORACLE_OTHER_DATATYPE
public static final int ORACLE_OTHER_DATATYPEConstant for identifiying unrecognized oracle datatypes- See Also:
-
ORACLE_NULL_DATATYPE
public static final int ORACLE_NULL_DATATYPEConstant for identifiying null datatypes- See Also:
-
OBJECT_DOES_NOT_EXIST
public static final int OBJECT_DOES_NOT_EXISTConstant for ORA-4043 - Object does not exist- See Also:
-
INVALID_NAME_PATTERN
public static final int INVALID_NAME_PATTERNConstant for ORA-17074 message - invalid name pattern- See Also:
-
FAILED_TO_CONVERT_INTERNAL
public static final int FAILED_TO_CONVERT_INTERNALConstant for ORA-17059 message - invalid name pattern The most common cause for this is a DB/Driver version mismatch- See Also:
-
TYPE_HAS_DEPENDENTS
public static final int TYPE_HAS_DEPENDENTSConstant for ORA-2303 message - cannot drop or replace a type with type or table dependents- See Also:
-
GENERATED_BY_COMMENT
The comment every generated statement carries, so a DBA can find this product's SQL inV$SQLwithout knowing what the application was called.Deliberately a plain comment rather than anything Oracle interprets: it costs a few bytes per cursor, survives into the shared pool exactly as written, and cannot change a plan. It is emitted by BOTH halves of the generator — the PL/SQL call builder and the SQL statement builder — so it is declared once here rather than typed twice.
Anything matching on it should match this constant, not a literal: it read
"Created By"with two spaces until 2026-08-16, so a hand-writtensql_text LIKEagainst old and new output has to allow for both.- See Also:
-
-
Constructor Details
-
SqlUtils
public SqlUtils()A set of useful static methods for working with SQL.
-
-
Method Details
-
normaliseTypeSpec
Reduce an Oracle TYPE specification to the form that two spellings of the same type share.Generated code uses this to tell a type that merely could not be replaced (ORA-2303 is the ordinary outcome once the
_Acollection depends on the_Tobject type) from one whose definition has actually changed underneath it. Oracle keeps a type's specification text inUSER_SOURCEexactly as submitted, so the comparison is against the DDL itself rather than againstUSER_TYPE_ATTRS- which would need the DDL's datatype spellings mapped onto the data dictionary's, and would report a difference wherever that mapping was imperfect.Discarded: everything up to and including the leading
TYPEkeyword (soCREATE OR REPLACE TYPE x ...and the storedTYPE x ...agree), semicolons, case, and all whitespace - the same statement arrives as one concatenated line from generated Java and as several lines fromextraObjects.sql. Removing whitespace outright is safe because a type specification contains no string literals.- Parameters:
theSpec- a CREATE TYPE statement or a stored specification; null is treated as empty- Returns:
- the comparable form, never null
-
getStatementType
Classify a SQL statement as a SELECT, INSERT, UPDATE, etc.Leading comments and whitespace are skipped before the first keyword is read. That was once a known bug, and fixing it is what allows
GENERATED_BY_COMMENTto be put at the START of a generated statement: without it every marked statement classified asUNKNOWN, which inDmlStatementmeans a statement that no longer knows whether it is a query. Block comments may nest neither in SQL nor here; a comment that is never closed consumes the rest of the string, which then classifies as UNKNOWN — correctly, since such a statement would not parse either.- Parameters:
theStatement- a SQL Statement- Returns:
- an int that will be a SqlUtils constant such as SqlUtils.SELECT, SqlUtils.UPDATE, etc.
- Since:
- 2.0.1527 Support for Lock, Merge and DDL statements
-
countParameters
Count the JDBC bind parameters in a SQL statement.Comments are skipped, so a
?inside one is not counted and -- the case that actually bit -- an apostrophe inside one does not open a phantom string literal. The demo statementCustomerDeletecarries the comment "If you don't have a comment after a parameter"; that lone apostrophe used to swallow the rest of the statement, so its real?went uncounted,StatementParameters2was sized 0, and every call died with "Attempt to set parameter number '1' even though statement doesn't take parameters."A doubled
''escape inside a literal needs no special case: the toggle turns off then straight back on, which lands in the right state at the closing quote.- Parameters:
aSqlStatement- a SQL Statement; null is treated as empty- Returns:
- an int The number of JDBC parameters in this SQL statement
-
getUnderlyingOracleDatatype
Return anintthat represents the underlying oracle data type. This method takes an oracle data type and classifies it as Text, Number, Date Long Text or Other.- Parameters:
theColumnDataType-- Returns:
- int A SqlUtils constant that represents the underlying oracle data type.
-
getVectorDatatypeFromInfo
Refine a native VECTOR column's datatype code from itsUSER/ALL_TAB_COLUMNS.VECTOR_INFOdescriptor.On Oracle 23ai every VECTOR column reports
DATA_TYPE = "VECTOR"regardless of storage format, sogetUnderlyingOracleDatatype(String)cannot tell dense from binary from sparse. The format is exposed for a table/view column in theVECTOR_INFOdescriptor, which looks likeVECTOR(<dim>,<format>,<storage>)— e.g.VECTOR(3,FLOAT32,DENSE),VECTOR(16,BINARY,DENSE),VECTOR(4,FLOAT32,SPARSE),VECTOR(*,*,DENSE). This method maps that descriptor to the specific constant:SPARSEstorage →ORACLE_VECTOR_SPARSE_DATATYPEBINARYformat (dense) →ORACLE_VECTOR_BINARY_DATATYPE- anything else, incl. dense FLOAT32/FLOAT64/INT8 and flexible
(*,*)→ORACLE_VECTOR_DATATYPE
null, blank, or unrecognised descriptor falls back to the denseORACLE_VECTOR_DATATYPE— the pre-existing behaviour — so callers that have noVECTOR_INFO(e.g. proc parameters, which do not expose it) are unaffected. Sparse takes precedence over binary because it is the harder limitation (unreadable by the current driver); the two are not combinable in practice.- Parameters:
vectorInfo- theVECTOR_INFOdescriptor, ornull- Returns:
- one of
ORACLE_VECTOR_DATATYPE,ORACLE_VECTOR_BINARY_DATATYPE,ORACLE_VECTOR_SPARSE_DATATYPE - Since:
- Oracle 23ai
-
createBfileLocator
public static oracle.sql.BFILE createBfileLocator(String theOracleDirectory, String theFileName, Connection theConnection, LogInterface theLog, boolean debugMessages) throws CSException Create and return a BFILE locator. This static method creates an oracle.sql.BFILE object by accessing the database. Note that a 'valid' BFILE will be returned even if theOracleDirectory does not exist or theFileName does not refer to an existing file.- Parameters:
theOracleDirectory-theFileName-theConnection-theLog- a logging mechanismdebugMessages- Create debug messages in log- Returns:
- oracle.sql.BFILE A BFILE which may or may not be usable.
- Throws:
CSException- If we can't create a BFILE.- Since:
- Oracle 8.1.7 / 4.0.2108
-