go-goracle / goracle

Go database/sql driver for connecting to Oracle Database, using the ODPI-C library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sql "in" query with slice not work

TheWinds opened this issue · comments

Describe the bug
writing a sql below only got the user record which id=2(first elem in slice)

rows, err := db.DB.Query("select * from T_USER where USERID in(:ids)", []int{2, 1})

To Reproduce
Steps to reproduce the behavior:
use this code

package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "gopkg.in/goracle.v2"
)

var db *sql.DB

func init() {
	var err error
	db, err = sql.Open("goracle", "...connstr")
	if err != nil {
		panic(err)
	}
}

func main() {
	rows, err := db.Query("select * from T_USER where USERID in(:ids)", []int{2, 1})
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()
	for rows.Next() {
		var id int
		var name string
		var ignore interface{}
		err = rows.Scan(&id, &ignore, &name, &ignore, &ignore, &ignore, &ignore, &ignore, &ignore)
		if err != nil {
			log.Fatalln(err)
		}
		fmt.Println(id, name)
	}
}

Expected behavior
result two rows not one

Screenshots
If applicable, add screenshots to help explain your problem.

Your oracle client version
instantclient_19_3

Your goracle version
v2

Your go version
go version go1.12.7 darwin/amd64

Your gcc version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Machine (please complete the following information):

  • OS: [Mac OS X]
  • Architecture [x86_64]
  • Version: [10.14.6]

Additional context
Add any other context about the problem here.

Oracle libraries don't allow binding multiple values to a single bind variable. See related doc at https://oracle.github.io/node-oracledb/doc/api.html#sqlwherein and https://cx-oracle.readthedocs.io/en/latest/user_guide/bind.html#binding-multiple-values-to-a-sql-where-in-clause for solution ideas.

Oracle libraries don't allow binding multiple values to a single bind variable. See related doc at https://oracle.github.io/node-oracledb/doc/api.html#sqlwherein and https://cx-oracle.readthedocs.io/en/latest/user_guide/bind.html#binding-multiple-values-to-a-sql-where-in-clause for solution ideas.

thanks for your solutions ,now it works.