From f530dae125307d8b436e858513b23306c63222df Mon Sep 17 00:00:00 2001 From: Ting-Lan Wang Date: Wed, 29 Oct 2025 15:26:53 -0400 Subject: [PATCH] Add workaround for unsupported JSON type in PL/SQL collections --- oracle/common.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/oracle/common.go b/oracle/common.go index 041354a..efcb375 100644 --- a/oracle/common.go +++ b/oracle/common.go @@ -55,6 +55,14 @@ import ( "gorm.io/gorm/schema" ) +// Extra data types for the data type that are not declared in the +// default DataType list +const ( + JSON schema.DataType = "json" + Timestamp schema.DataType = "timestamp" + TimestampWithTimeZone schema.DataType = "timestamp with time zone" +) + // Helper function to get Oracle array type for a field func getOracleArrayType(field *schema.Field, values []any) string { switch field.DataType { @@ -64,6 +72,10 @@ func getOracleArrayType(field *schema.Field, values []any) string { return "TABLE OF NUMBER" case schema.Float: return "TABLE OF NUMBER" + case JSON: + // PL/SQL does not yet allow declaring collections of JSON (TABLE OF JSON) directly. + // Workaround for JSON type + fallthrough case schema.String: if field.Size > 0 && field.Size <= 4000 { return fmt.Sprintf("TABLE OF VARCHAR2(%d)", field.Size) @@ -113,13 +125,6 @@ func findFieldByDBName(schema *schema.Schema, dbName string) *schema.Field { return nil } -// Extra data types to determine the destination type for OUT parameters -// when using a serializer -const ( - Timestamp schema.DataType = "timestamp" - TimestampWithTimeZone schema.DataType = "timestamp with time zone" -) - // Create typed destination for OUT parameters func createTypedDestination(f *schema.Field) interface{} { if f == nil {