@@ -507,15 +507,23 @@ func buildBulkMergePLSQL(db *gorm.DB, createValues clause.Values, onConflictClau
507507 }
508508 plsqlBuilder .WriteString ("\n BULK COLLECT INTO l_affected_records;\n " )
509509
510- // Add OUT parameter population
510+ // Add OUT parameter population (JSON serialized to CLOB)
511511 outParamIndex := len (stmt .Vars )
512512 for rowIdx := 0 ; rowIdx < len (createValues .Values ); rowIdx ++ {
513513 for _ , column := range allColumns {
514514 if field := findFieldByDBName (schema , column ); field != nil {
515- stmt .Vars = append (stmt .Vars , sql.Out {Dest : createTypedDestination (field )})
516- plsqlBuilder .WriteString (fmt .Sprintf (" IF l_affected_records.COUNT > %d THEN :%d := l_affected_records(%d)." , rowIdx , outParamIndex + 1 , rowIdx + 1 ))
517- writeQuotedIdentifier (& plsqlBuilder , column )
518- plsqlBuilder .WriteString ("; END IF;\n " )
515+ if isJSONField (field ) {
516+ // JSON -> text bind
517+ stmt .Vars = append (stmt .Vars , sql.Out {Dest : new (string )})
518+ plsqlBuilder .WriteString (fmt .Sprintf (" IF l_affected_records.COUNT > %d THEN :%d := JSON_SERIALIZE(l_affected_records(%d)." , rowIdx , outParamIndex + 1 , rowIdx + 1 ))
519+ writeQuotedIdentifier (& plsqlBuilder , column )
520+ plsqlBuilder .WriteString (" RETURNING CLOB); END IF;\n " )
521+ } else {
522+ stmt .Vars = append (stmt .Vars , sql.Out {Dest : createTypedDestination (field )})
523+ plsqlBuilder .WriteString (fmt .Sprintf (" IF l_affected_records.COUNT > %d THEN :%d := l_affected_records(%d)." , rowIdx , outParamIndex + 1 , rowIdx + 1 ))
524+ writeQuotedIdentifier (& plsqlBuilder , column )
525+ plsqlBuilder .WriteString ("; END IF;\n " )
526+ }
519527 outParamIndex ++
520528 }
521529 }
@@ -613,7 +621,7 @@ func buildBulkInsertOnlyPLSQL(db *gorm.DB, createValues clause.Values) {
613621 }
614622 plsqlBuilder .WriteString ("\n BULK COLLECT INTO l_inserted_records;\n " )
615623
616- // Add OUT parameter population
624+ // Add OUT parameter population (JSON serialized to CLOB)
617625 outParamIndex := len (stmt .Vars )
618626 for rowIdx := 0 ; rowIdx < len (createValues .Values ); rowIdx ++ {
619627 for _ , column := range allColumns {
@@ -622,9 +630,20 @@ func buildBulkInsertOnlyPLSQL(db *gorm.DB, createValues clause.Values) {
622630 quotedColumn := columnBuilder .String ()
623631
624632 if field := findFieldByDBName (schema , column ); field != nil {
625- stmt .Vars = append (stmt .Vars , sql.Out {Dest : createTypedDestination (field )})
626- plsqlBuilder .WriteString (fmt .Sprintf (" IF l_inserted_records.COUNT > %d THEN :%d := l_inserted_records(%d).%s; END IF;\n " ,
627- rowIdx , outParamIndex + 1 , rowIdx + 1 , quotedColumn ))
633+ if isJSONField (field ) {
634+ // JSON -> text bind
635+ stmt .Vars = append (stmt .Vars , sql.Out {Dest : new (string )})
636+ plsqlBuilder .WriteString (fmt .Sprintf (
637+ " IF l_inserted_records.COUNT > %d THEN :%d := JSON_SERIALIZE(l_inserted_records(%d).%s RETURNING CLOB); END IF;\n " ,
638+ rowIdx , outParamIndex + 1 , rowIdx + 1 , quotedColumn ,
639+ ))
640+ } else {
641+ stmt .Vars = append (stmt .Vars , sql.Out {Dest : createTypedDestination (field )})
642+ plsqlBuilder .WriteString (fmt .Sprintf (
643+ " IF l_inserted_records.COUNT > %d THEN :%d := l_inserted_records(%d).%s; END IF;\n " ,
644+ rowIdx , outParamIndex + 1 , rowIdx + 1 , quotedColumn ,
645+ ))
646+ }
628647 outParamIndex ++
629648 }
630649 }
0 commit comments