mattn / go-oci8

Oracle driver for Go using database/sql

Home Page:https://mattn.kaoriya.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

support sql.Out for cursors

dbalamo opened this issue · comments

Hello,
I'm still experiencing the same issue described here
#188
using Oracle 12.

I have this stored Procedure, which returns a sys_refcursor :

create or replace PROCEDURE PROCSELECTDIPCURSOR2
( 
  outcur OUT SYS_REFCURSOR
) AS
    
BEGIN            
    OPEN outcur FOR SELECT PERSON_ID, FIRST_NAME,LAST_NAME from DIPENDENTI where LAST_NAME LIKE 'T%';    
END PROCSELECTDIPCURSOR2;

and the GO code calling the stored procedure is this :

func main() {
	db, err := sql.Open("oci8", "user/password@localhost:1521/orclsid")
	if err != nil {
		log.Fatal(fmt.Errorf("ERROR OPEN - %w", err))
	}
	defer db.Close()

	ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
	defer cancel()

	tx, err := db.BeginTx(ctx, nil)
	if err != nil {
		log.Fatal(fmt.Errorf("ERROR BeginTx - %w", err))
		log.Fatal(err)
	}
	defer tx.Commit()

	var dr interface{}
	qry := "BEGIN PROCSELECTDIPCURSOR2(:outcur); END;"

	_, sqlErr := tx.ExecContext(ctx, qry, sql.Out{Dest: &dr})
	if sqlErr != nil {
		log.Fatal(sqlErr)
	} else {
		fmt.Println("Went OK")
	}
}

I've tried using interface, sql.Rows and driver.Rows as return variable for the sys_refcursor, but no luck , it keeps saying

PLS-00306: wrong number or types of arguments in call to 'PROCSELECTDIPCURSOR2' .

The code above works ok if I call a stored procedure returning base types (a number, for example).
Is the sql.Out support still missing something about cursors, or it's my fault?

Thanks

I don't think cursor has been added to outputBoundParameters yet.
https://github.com/mattn/go-oci8/blob/master/statement.go#L766-L933