0

i have a package in oracle

    CREATE OR REPLACE PACKAGE PKG_TEST IS
    TYPE REFCURSOR IS REF CURSOR;
    PROCEDURE PROC_GET_DUAL(P_CUR OUT REFCURSOR);
end PKG_TEST;
CREATE OR REPLACE PACKAGE BODY PKG_TEST is
    PROCEDURE PROC_GET_DUAL(
        P_CUR OUT REFCURSOR)
        IS
    BEGIN
        OPEN P_CUR FOR
            select * from dual;
    END PROC_GET_DUAL;
end PKG_TEST;

and i use golang ("github.com/sijms/go-ora/v2") to connect oracle and ping success. I call package such as

var cursor go_ora.RefCursor
fmt.Println(db.Ping())
statement := `begin :x := PKG_TEST.PROC_GET_DUAL(); end;`
_, err := db.Exec(statement, sql.Out{Dest: &cursor})
//check errors

defer cursor.Close()
rows, err := cursor.Query()
// check for error

var (
    var1 string
)
for rows.Next_() {
    err = rows.Scan(&var1)
    // check for error
    fmt.Println(var1)
}

I followed the instructions in https://github.com/sijms/go-ora/blob/master/README.md and got this

enter image description here

enter image description here

Thank you for your help and sorry my English because English is not my native language

htan
  • 79
  • 6
  • Could be because of unhandled error here `_, err := db.Exec(statement, sql.Out{Dest: &refCursor})`] – medasx Jul 14 '22 at 09:28
  • @medasx i found 'PLS-00306: wrong number or types of arguments in call to 'PROC_GET_DUAL'' but my pakage has no paramater – htan Jul 14 '22 at 09:47
  • `PROCEDURE PROC_GET_DUAL(P_CUR OUT REFCURSOR)` I never used oracle but this seems to me like an param. Can't help with pkg specific stuff sorry. – medasx Jul 14 '22 at 10:07

1 Answers1

1

You also need to pass the out param to the procedure.

statement := `begin PKG_TEST.PROC_GET_DUAL(:1); end;`
_, err := db.Exec(statement, sql.Out{Dest: &cursor})
Gurkan Yesilyurt
  • 2,635
  • 2
  • 20
  • 21