Golang oci8存储过程查询产生错误

时间:2015-04-13 05:01:55

标签: stored-procedures go oracle11g oci8

我想使用golang oci8进行查询,这是我在oracle xe中的设置;

CREATE OR REPLACE PACKAGE user_mgt
IS
PROCEDURE login(u_mail_in IN VARCHAR2,
              u_pwd_in IN VARCHAR2,
              retval OUT VARCHAR2)  ;
END user_mgt;
CREATE OR REPLACE PACKAGE   BODY user_mgt
   is
        PROCEDURE login(u_mail_in IN VARCHAR2,
        u_pwd_in IN VARCHAR2,
        retval OUT VARCHAR2)
        AS
             l_count NUMBER     ;
        BEGIN
            SELECT Count(*)
            INTO  l_count
            FROM USERTABLE
            WHERE u_mail= u_mail_in;

            IF l_count=1 then
             SELECT u_pwd
             INTO   retval
             FROM usertable
             WHERE u_mail= u_mail_in;
            ELSE
                  retval:='NotFound';
            END IF    ;

        END   login;
    END user_mgt

我的测试下面没有错误并返回预期的结果;

DECLARE
em VARCHAR2(50);
pwd VARCHAR2(200);
retval VARCHAR2(200);
BEGIN
em:='blow';
pwd:='pwd';
   user_mgt.login(em,pwd,retval);
   Dbms_Output.put_line(retval);
END;

现在,当我尝试在golang设置中查询时,我收到错误; 包主要

import (
    "database/sql"
    "fmt"
    _ "github.com/mattn/go-oci8"
)
func main() {
    db, err := sql.Open("oci8", "user/password@XE")
    if err != nil {
        fmt.Println(err)
        return
    }
    defer db.Close()
    loginStmt,err:=db.Prepare("begin user_mgt.login(:1,:2,:3);end;")
        defer loginStmt.Close()
    mail:="ofoe"
    pwd:="testing"
    var retVal string
    var retStatus string
    er:=loginStmt.QueryRow(mail,pwd,retVal).Scan(&retStatus)
    if er!=nil{
        panic(er)
    }
    fmt.Println("retval")
    fmt.Println(retStatus)
}

我会感激任何帮助,我真的卡住了,我得到的错误是;

panic: ORA-06502: PL/SQL: numeric or value error: character string buffer too sm
all
ORA-06512: at "BLOW.USER_MGT", line 20
ORA-06512: at line 1
goroutine 1 [running]:
main.main()
        C:/Users/pc/Documents/goPlayground/src/blow.com/oracle_test/main.go:27 +
0x3ab

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        c:/go/src/runtime/asm_386.s:2287 +0x1

goroutine 5 [runnable]:
database/sql.(*DB).connectionOpener(0x12252460)
        c:/go/src/database/sql/sql.go:589 +0x43
created by database/sql.Open
        c:/go/src/database/sql/sql.go:452 +0x256
exit status 2

0 个答案:

没有答案