英文:
How to get output REFCURSOR in package oracle with golang ("github.com/sijms/go-ora/v2")
问题
我在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;
我使用Golang("github.com/sijms/go-ora/v2")连接到Oracle并成功进行了ping。我调用了这个包:
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})
// 检查错误
defer cursor.Close()
rows, err := cursor.Query()
// 检查错误
var (
var1 string
)
for rows.Next_() {
err = rows.Scan(&var1)
// 检查错误
fmt.Println(var1)
}
我按照https://github.com/sijms/go-ora/blob/master/README.md中的说明进行操作,并得到了以下结果:
谢谢你的帮助,对不起,我的英语不是我的母语。
英文:
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
Thank you for your help and sorry my English because English is not my native language
答案1
得分: 1
你还需要将 out param 传递给该过程。
statement := `begin PKG_TEST.PROC_GET_DUAL(:1); end;`
_, err := db.Exec(statement, sql.Out{Dest: &cursor})
英文:
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})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论