Returning values with INSERT query using ORACLE database in GOLANG

Returning values with INSERT query using ORACLE database in GOLANG

How do I pass bind params values in EXE statement?

Eg -

actualvalue = append(actualvalue, 1)
actualvalue = append(actualvalue, 2)
actualvalue = append(actualvalue, 3)

query = “insert into table (a,b,c) values (:a,:b,:c) returning primarykey, secondarykey into :primarykey,:secondarykey”
stmtIns, err := dbConnImbl.Prep(query)
if err != nil {
fmt.Println("Second Method Error 22====>> ",err)
}
var id uint64
var id2 uint64
rowsAffected, err := stmtIns.Exe(actualvalue…, &id,&id2)//.Scan(&id,&id2)
if err != nil {
fmt.Println("Error Cluses " , err)
}

the highlighted line is not working

please, someone, help how to pass dynamic values in “stmtIns.Exe”

Where does acutalvalue come from?
What do you want to express by using the ellipsis (...) on it?
Do you see any compiler or runtime error?

Could you also please use markdown to format your code? (Cheatsheet)

Especially code is much easier to read when fenced:

```go
// your code here
```
1 Like

Hi. Is this using golangs sql package? Then would the function be Exec https://golang.org/pkg/database/sql/#DB.Exec

when returning clause is required while INSERT, we can not use database/sql package.

we have to add orav4 package to do that.

My problem is that -

the EXE command not supporting the variadic functions values which i want to send as bind params Values.

And if i have 100 columns in database and i need to insert some random columns then how do i process…

actualvalue = append(actualvalue, 1)
actualvalue = append(actualvalue, 2)
actualvalue = append(actualvalue, 3)

query = “insert into table (a,b,c) values (:a,:b,:c) returning primarykey, secondarykey into :primarykey,:secondarykey”
stmtIns, err := dbConnImbl.Prep(query)
if err != nil {
fmt.Println("Second Method Error 22====>> ",err)
}
var id uint64
var id2 uint64
**rowsAffected, err := stmtIns.Exe(actualvalue…, &id,&id2)//.Scan(&id,&id2)**
if err != nil {
fmt.Println("Error Cluses " , err)
}

when returning clause is required while INSERT, we can not use database/sql package.

we have to add orav4 package to do that.

My problem is that -

the EXE command not supporting the variadic functions values which i want to send as bind params Values.

And if i have 100 columns in database and i need to insert some random columns then how do i process…

You can only use the ellipsis for variadify a slice in a function/method call when it is the last argument, you need to append the two values you give explicitly as well.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.