@@ -582,20 +582,20 @@ func buildBulkMergePLSQL(db *gorm.DB, createValues clause.Values, onConflictClau
582582 // Column is a BLOB, return raw bytes; no JSON_SERIALIZE
583583 stmt .Vars = append (stmt .Vars , sql.Out {Dest : & godror.Lob {IsClob : false }})
584584 plsqlBuilder .WriteString (fmt .Sprintf (
585- " IF l_affected_records.COUNT > %d THEN :%d := l_affected_records(%d)." ,
586- rowIdx , outParamIndex + 1 , rowIdx + 1 ,
585+ " IF l_affected_records.COUNT > %d THEN SELECT l_affected_records(%d)." ,
586+ rowIdx , rowIdx + 1 ,
587587 ))
588588 db .QuoteTo (& plsqlBuilder , column )
589- plsqlBuilder .WriteString (" ; END IF;\n " )
589+ plsqlBuilder .WriteString (fmt . Sprintf ( " INTO :%d FROM DUAL ; END IF;\n ", outParamIndex + 1 ) )
590590 } else {
591591 // datatypes.JSON (text-based) -> serialize to CLOB
592592 stmt .Vars = append (stmt .Vars , sql.Out {Dest : & godror.Lob {IsClob : true }})
593593 plsqlBuilder .WriteString (fmt .Sprintf (
594- " IF l_affected_records.COUNT > %d THEN :%d := JSON_SERIALIZE(l_affected_records(%d)." ,
595- rowIdx , outParamIndex + 1 , rowIdx + 1 ,
594+ " IF l_affected_records.COUNT > %d THEN SELECT JSON_SERIALIZE(l_affected_records(%d)." ,
595+ rowIdx , rowIdx + 1 ,
596596 ))
597597 db .QuoteTo (& plsqlBuilder , column )
598- plsqlBuilder .WriteString (" RETURNING CLOB); END IF;\n " )
598+ plsqlBuilder .WriteString (fmt . Sprintf ( " RETURNING CLOB) INTO :%d FROM DUAL ; END IF;\n " , outParamIndex + 1 ) )
599599 }
600600 } else {
601601 fieldType := createTypedDestination (field )
@@ -608,9 +608,9 @@ func buildBulkMergePLSQL(db *gorm.DB, createValues clause.Values, onConflictClau
608608 }
609609 }
610610 stmt .Vars = append (stmt .Vars , sql.Out {Dest : fieldType })
611- plsqlBuilder .WriteString (fmt .Sprintf (" IF l_affected_records.COUNT > %d THEN :%d := l_affected_records(%d)." , rowIdx , outParamIndex + 1 , rowIdx + 1 ))
611+ plsqlBuilder .WriteString (fmt .Sprintf (" IF l_affected_records.COUNT > %d THEN SELECT l_affected_records(%d)." , rowIdx , rowIdx + 1 ))
612612 db .QuoteTo (& plsqlBuilder , column )
613- plsqlBuilder .WriteString (" ; END IF;\n " )
613+ plsqlBuilder .WriteString (fmt . Sprintf ( " INTO :%d FROM DUAL ; END IF;\n ", outParamIndex + 1 ) )
614614 }
615615 outParamIndex ++
616616 }
@@ -717,15 +717,15 @@ func buildBulkInsertOnlyPLSQL(db *gorm.DB, createValues clause.Values, bindMap p
717717 // Column is a BLOB, return raw bytes; no JSON_SERIALIZE
718718 stmt .Vars = append (stmt .Vars , sql.Out {Dest : & godror.Lob {IsClob : false }})
719719 plsqlBuilder .WriteString (fmt .Sprintf (
720- " IF l_inserted_records.COUNT > %d THEN :%d := l_inserted_records(%d).%s; END IF;\n " ,
721- rowIdx , outParamIndex + 1 , rowIdx + 1 , quotedColumn ,
720+ " IF l_inserted_records.COUNT > %d THEN SELECT l_inserted_records(%d).%s INTO :%d FROM DUAL ; END IF;\n " ,
721+ rowIdx , rowIdx + 1 , quotedColumn , outParamIndex + 1 ,
722722 ))
723723 } else {
724724 // datatypes.JSON (text-based) -> serialize to CLOB
725725 stmt .Vars = append (stmt .Vars , sql.Out {Dest : & godror.Lob {IsClob : true }})
726726 plsqlBuilder .WriteString (fmt .Sprintf (
727- " IF l_inserted_records.COUNT > %d THEN :%d := JSON_SERIALIZE(l_inserted_records(%d).%s RETURNING CLOB); END IF;\n " ,
728- rowIdx , outParamIndex + 1 , rowIdx + 1 , quotedColumn ,
727+ " IF l_inserted_records.COUNT > %d THEN SELECT JSON_SERIALIZE(l_inserted_records(%d).%s RETURNING CLOB) INTO :%d FROM DUAL ; END IF;\n " ,
728+ rowIdx , rowIdx + 1 , quotedColumn , outParamIndex + 1 ,
729729 ))
730730 }
731731 } else {
@@ -740,9 +740,10 @@ func buildBulkInsertOnlyPLSQL(db *gorm.DB, createValues clause.Values, bindMap p
740740 }
741741 stmt .Vars = append (stmt .Vars , sql.Out {Dest : fieldType })
742742 plsqlBuilder .WriteString (fmt .Sprintf (
743- " IF l_inserted_records.COUNT > %d THEN :%d := l_inserted_records(%d).%s; END IF;\n " ,
744- rowIdx , outParamIndex + 1 , rowIdx + 1 , quotedColumn ,
743+ " IF l_inserted_records.COUNT > %d THEN SELECT l_inserted_records(%d).%s INTO :%d FROM DUAL ; END IF;\n " ,
744+ rowIdx , rowIdx + 1 , quotedColumn , outParamIndex + 1 ,
745745 ))
746+
746747 }
747748 outParamIndex ++
748749 }
0 commit comments