Updated on 2025-04-14 GMT+08:00

Struct

This section describes the differences between Oracle Database and GaussDB when the JDBC driver of the java.sql.Struct type is used.

Table 1 Constructor reference

Constructor

Oracle Database

GaussDB

API Difference

1. Use the static constructor of StructDescriptor to construct a StructDescriptor object.

2. Use StructDescriptor to construct a struct object.

String typeName = "XXX";

Connection conn = getConnection();

Object[] attributes = null;

StructDescriptor desc = StructDescriptor.createDescriptor(typeName, conn);

Struct struct = new STRUCT(desc, conn, attributes);

String typeName = "xxx";

Connection conn = getConnection();

Object[] elements = null;

StructDescriptor desc = StructDescriptor.getDescriptor(typeName, conn);

Struct struct = new GaussStruct(desc, attributes);

  • Different names of the static constructor for StructDescriptor: In Oracle Database, it is createDescriptor, while in GaussDB it is getDescriptor.
  • Different constructor names for structs. In Oracle Database, it is defined as STRUCT(StructDescriptor, Connection, Object[]), while in GaussDB, it is defined as GaussStruct(StructDescriptor, Object[]).
  • Variable description:

    typeName indicates the type name and is case-sensitive. Generally, it uses uppercase in Oracle Database, while in GaussDB it is lowercase.

    conn indicates the connection object for the corresponding database.

    attributes indicates the element data array.

Use the createStruct standard API of Connection to construct a struct object.

String typeName = "XXX";

Connection conn = getConnection();

Object[] attributes = null;

Struct struct = conn.createStruct(typeName, attributes);

String typeName = "XXX";

Connection conn = getConnection();

Object[] attributes = null;

Struct struct = conn.createStruct(typeName, attributes);

  • Variable description:

    typeName indicates the type name and is case-sensitive. Generally, it uses uppercase in Oracle Database, while in GaussDB it is lowercase.

    conn indicates the connection object for the corresponding database.

    attributes indicates the element data array.

  1. GaussDB currently does not support the constructors not listed in the aforementioned table.
  2. If the attribute type is a character type and the length of the construction input string exceeds that defined by the element type, Oracle Database reports an error during input parameter binding.

    GaussDB does not verify type modifiers when constructing or binding input parameters. When a database receives struct objects and executes SQL statements, it decides whether to report an error.

  3. If the number of array elements exceeds the actual number of columns of the corresponding type, an error is reported during creation.

    When the number of array elements is less than the actual number of columns, the creation of Oracle Database is successful, but an error is reported during parameter input for execution; GaussDB reports an error during creation.

Table 2 API reference

Method

Return Value Type

Throws

GaussDB

getSQLTypeName()

String

SQLException

Supported.

getAttributes()

Object[]

SQLException

Supported.

getAttributes(java.util.Map<String,Class<?>> map)

Object[]

SQLException

Not supported.

The differences in the getSQLTypeName API are as follows:

  1. For the package type, the struct constructed in the packageName.typeName format, the differences in the getSQLTypeName API are as follows:
    • OJDBC11 returns packageName.typeName.
    • OJDBC8 generally returns packageName.typeName, or returns "packageName"."typeName" when packageName and typeName meet the following condition:

      Any of packageName or typeName does not meet the rule of starting with a letter followed by characters including letters, digits, or underscores.

    • GaussDB generally returns schemaName.packageName.typeName, or returns "schemaName"."packageName"."typeName" when schemaName, packageName, and typeName meet the following condition:

      Any of schemaName, packageName, or typeName does not meet the rule of starting with a letter or underscore followed by characters including letters, digits, or underscores.

  2. For the package type, the differences in the getSQLTypeName API in other scenarios are as follows:
    • OJDBC11 returns schemaName.packageName.typeName.
    • OJDBC8 generally returns schemaName.packageName.typeName, or returns "schemaName"."packageName.typeName" when schemaName, packageName, and typeName meet the following condition:

      Any of schemaName, packageName, or typeName does not meet the rule of starting with a letter followed by characters including letters, digits, or underscores.

    • GaussDB generally returns schemaName.packageName.typeName, or returns "schemaName"."packageName"."typeName" when schemaName, packageName, and typeName meet the following condition:

      Any of schemaName, packageName, or typeName does not meet the rule of starting with a letter or underscore followed by characters including letters, digits, or underscores.

  3. For the non-package type, the differences in the getSQLTypeName API are as follows:
    • OJDBC11 returns schemaName.typeName.
    • OJDBC8 generally returns schemaName.typeName, or returns "schemaName"."typeName" when schemaName and typeName meet the following condition:

      Any of schemaName or typeName does not meet the rule of starting with a letter followed by characters including letters, digits, or underscores.

    • GaussDB generally returns schemaName.typeName, or returns "schemaName"."typeName" when schemaName and typeName meet the following condition:

      Any of schemaName or typeName does not meet the rule of starting with a letter or underscore followed by characters including letters, digits, or underscores.

Table 3 Differences in the getAttributes() API

Database Attribute Type

Java Type of the Corresponding Element in the Return Value (Oracle Database OJDBC8)

Java Type of the Corresponding Element in the Return Value (Oracle Database OJDBC11)

Java Type of the Corresponding Element in the Return Value (GaussDB)

CHAR

String

String

String

VARCHAR/VARCHAR2

String

String

String

NCHAR

String

String

String

NVARCHAR2

String

String

String

NUMBER

BigDecimal

BigDecimal

BigDecimal

NUMERIC

BigDecimal

BigDecimal

BigDecimal

DECIMAL

BigDecimal

BigDecimal

BigDecimal

INTEGER

BigDecimal

BigDecimal

Integer

SMALLINT

BigDecimal

BigDecimal

Short

DOUBLE PRECISION

BigDecimal

BigDecimal

Double

FLOAT

BigDecimal

BigDecimal

Double

REAL

BigDecimal

BigDecimal

Float

BINARY_DOUBLE

Double

Double

Double

BINARY_INTEGER

BigDecimal

Integer

Integer

BOOLEAN

BigDecimal

Integer

Boolean

TIMESTAMP

Timestamp

Timestamp

Timestamp

TIMESTAMP WITH TIME ZONE

TIMESTAMPTZ

TIMESTAMPTZ

Timestamp

BLOB

BLOB

BLOB

PGBlob

CLOB

CLOB

CLOB

PGClob

Set/Array

ARRAY

ARRAY

GaussArray

RECORD

STRUCT

STRUCT

GaussStruct

GaussDB currently does not support the types unlisted in the aforementioned table.

Table 4 Differences in struct construction APIs

Database Attribute Type

List of Java Types Supported by Attribute Input Parameters (Oracle Database)

List of Java Types Supported by Attribute Input Parameters (GaussDB)

Difference

CHAR

Any Java type

Byte, Short, Integer, Long, BigInteger, BigDecimal, Float, Double, Character, Boolean, String, java.sql.Date, java.sql.Time, java.sql.Timestamp, and PGClob

  1. The different types supported by attribute input parameters can be seen in the table.
  2. When the input parameter is of the String type, Oracle Database adds spaces at the end of the string until its length matches the length defined by the type; GaussDB does not add spaces.

VARCHAR/VARCHAR2

Any Java type

Byte, Short, Integer, Long, BigInteger, BigDecimal, Float, Double, Character, Boolean, String, java.sql.Date, java.sql.Time, java.sql.Timestamp, and PGClob

The different types supported by attribute input parameters can be seen in the table.

NCHAR

Any Java type

Byte, Short, Integer, Long, BigInteger, BigDecimal, Float, Double, Character, Boolean, String, java.sql.Date, java.sql.Time, java.sql.Timestamp, and PGClob

The different types supported by attribute input parameters can be seen in the table.

NVARCHAR2

Any Java type

Byte, Short, Integer, Long, BigInteger, BigDecimal, Float, Double, Character, Boolean, String, java.sql.Date, java.sql.Time, java.sql.Timestamp, and PGClob

The different types supported by attribute input parameters can be seen in the table.

NUMBER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, String, and oracle.sql.NUMBER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. When the input parameter is of the Float, Double, BigDecimal, or String type and the decimal part is 0, Oracle Database truncates the decimal part, while GaussDB retains it.

NUMERIC

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, String, and oracle.sql.NUMBER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. When the input parameter is of the Float, Double, BigDecimal, or String type and the decimal part is 0, Oracle Database truncates the decimal part, while GaussDB retains it.

DECIMAL

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, String, and oracle.sql.NUMBER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. When the input parameter is of the Float, Double, BigDecimal, or String type and the decimal part is 0, Oracle Database truncates the decimal part, while GaussDB retains it.

INTEGER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, String, and oracle.sql.NUMBER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. The target types are inconsistent. For details, see differences in the getAttributes() API.
  3. When the input parameter value exceeds the integer range, GaussDB reports an error.

SMALLINT

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, String, and oracle.sql.NUMBER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. The target types are inconsistent. For details, see differences in the getAttributes() API.
  3. When the input parameter exceeds the Short range, GaussDB reports an error.

DOUBLE PRECISION

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, String, and oracle.sql.NUMBER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. The target types are inconsistent. For details, see differences in the getAttributes() API.
  3. Converting a higher-precision type to Double may result in precision loss.

FLOAT

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, String, and oracle.sql.NUMBER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. The target types are inconsistent. For details, see differences in the getAttributes() API.
  3. Converting a higher-precision type to Double may result in precision loss.

REAL

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, String, and oracle.sql.NUMBER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. The target types are inconsistent. For details, see differences in the getAttributes() API.
  3. Converting a higher-precision type to Float may result in precision loss.

BINARY_DOUBLE

byte[], Double, and oracle.sql.BINARY_DOUBLE

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. The target types are inconsistent. For details, see differences in the getAttributes() API.
  3. Converting a higher-precision type to Double may result in precision loss.

BINARY_INTEGER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, AtomicInteger, AutomicLong, DoubleAccumulator, DoubleAddr, LongAccumulator, LondAdder, Striped64, String, and oracle.sql.NUMBER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. If the input value exceeds the integer range, GaussDB reports an error, whereas Oracle Database truncates the value.

BOOLEAN

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, AtomicInteger, AutomicLong, DoubleAccumulator, DoubleAddr, LongAccumulator, LondAdder, Striped64, String, and oracle.sql.NUMBER

Byte, Short, Integer, Long, Float, Double, Boolean, BigDecimal, BigInteger, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. The target types are inconsistent. For details, see differences in the getAttributes() API.
  3. In GaussDB, the target data type is Boolean, which only supports inputs of 1, 0, "true", and "false".

TIMESTAMP

byte[], java.sql.Date, String, java.sql.Time, java.sql.Timestamp, oracle.sql.TIMESTAMP, and oracle.sql.DATE

java.util.Date, java.sql.Date, java.sql.Time, java.sql.Timestamp, LocalDateTime, and String

The different types supported by attribute input parameters can be seen in the table.

TIMESTAMP WITH TIME ZONE

java.sql.Date, Calendar, java.util.Date, LocalDate, LocalDateTime, LocalTime, OffsetDateTime, OffsetTime, String, java.sql.Time, java.sql.Timestamp, oracle.sql.TIMESTAMP, oracle.sql.TIMESTAMPTZ, oracle.sql.TIMESTAMPLTZ, and ZonedDateTime

java.util.Date, java.sql.Date, java.sql.Time, java.sql.Timestamp, LocalDateTime, and String

  1. The different types supported by attribute input parameters can be seen in the table.
  2. The target types are inconsistent. For details, see differences in the getAttributes() API.

BLOB

oracle.sql.BLOB and oracle.jdbc.driver.OracleBlob

PGBlob

  1. The different types supported by attribute input parameters can be seen in the table.
  2. The target types are inconsistent. For details, see differences in the getAttributes() API.

CLOB

oracle.sql.CLOB and oracle.jdbc.driver.OracleClob

PGClob

  1. The different types supported by attribute input parameters can be seen in the table.
  2. The target types are inconsistent. For details, see differences in the getAttributes() API.

Set/Array

Array and Object

GaussArray and Object

  1. The different types supported by attribute input parameters can be seen in the table.
  2. In Oracle Database, no error is reported when the attribute input parameter is of the Array type, even if the Array type differs from the actual type required by the attribute.

    In GaussDB, an error is reported when the attribute input parameter is of the GaussArray type that differs from the actual type required by the attribute.

  3. When the input parameter of an attribute is of the Object type, refer to the differences in array construction APIs.

RECORD

Struct and Object[]

GaussStruct and Object[]

  1. The different types supported by attribute input parameters can be seen in the table.
  2. In Oracle Database, no error is reported when the attribute input parameter is of the Struct type, even if the Struct type differs from the actual type required by the attribute.

    In GaussDB, an error is reported when the attribute input parameter is of the GaussStruct type that differs from the actual type required by the attribute.

  3. When the input parameter of an attribute is of the Object[] type, refer to the differences in struct construction APIs.
  1. When a struct is constructed, if the Java type of the input element does not match the target type, an implicit conversion operation is performed. For details on the Java types of input elements supported by various database element types, refer to the preceding table.
  2. GaussDB currently does not support the types unlisted in the aforementioned table.
  3. The constructor needs to provide an attribute array. The preceding table describes the differences of each attribute in the array.