问题如下: 现有个存储过程如下(只是随便举个例子):
CREATE PROCEDURE test(
UID INT,
OUT Ret1 VARCHAR(200),
OUT Ret2 VARCHAR(200),
)
BEGIN
SET Ret1 = "test ret1";
SET Ret2 = "test ret2";
SELECT * FROM user;
SELECT * FROM phones;
END
GO 里如何调佣这个存储过程获取 Ret1 、Ret2 出参,及获取 user 、phones 的两个结果集呢
翻遍了度娘和谷哥没找到想要的答案,求助 V 友
1
wd 2021-12-13 13:21:16 +08:00 via iPhone
按说 procedure 应该是需要类似函数那样显式声明 输入和输出的吧?就是输入应该在定义里面,输出是通过 return 之类。我感觉你举的栗子就没有输入输出,你无法获取
|
2
gamexg 2021-12-13 13:46:31 +08:00
```
package main import ( "database/sql" "fmt" _ "github.com/denisenkom/go-mssqldb" _ "github.com/go-sql-driver/mysql" ) func main() { db, err := sql.Open("mssql", `server=1.2.3.4;user id=test;password=test;encrypt=disable;database=test`) if err != nil { panic(err) } if err := db.Ping(); err != nil { panic(err) } tx, err := db.Begin() row := tx.QueryRow(`DECLARE @o_id int EXEC [dbo].[AAAAAAA] @serverid = ?, @o_id = @o_id OUTPUT; SELECT @o_id as N'@o_id' `, 99) id := 0 if err := row.Scan(&id); err != nil { panic(err) } fmt.Print(id) if err := tx.Commit(); err != nil { panic(err) } /* id, err := result.LastInsertId() if err != nil { panic(err) }*/ return } ``` |