如何在 LotusScript 中接收 DB2 存储过程结果

How to receive DB2 stored procedure result in LotusScript

我有以下 DB2 存储过程

CREATE PROCEDURE SCHEME.getData(IN inputParam VARCHAR(100), OUT outputParam VARCHAR(100))
BEGIN
    -- do sth
    SET outputParam = 'something2';
END

我想 运行 这个过程带有 on 参数并在 LotusScript 代理中接收结果:

Set con = New ODBCConnection
Set qry = New ODBCQuery
Set result = New ODBCResultSet

Call con.ConnectTo("MyOdbcDriverName", "user", "pass")

Set result.Query = qry
Set qry.Connection = con


sql = |Call SCHEME.getData('arg1')|//it runs ok - no odbc errors

qry.Sql = sql
result.Execute

If result.Isresultsetavailable() Then    //false here so no idea how to process the result
    REM do sth with result
    value = result.GetValue(1)      
Else

我应该在 SQL 语句中添加什么以及我应该如何处理结果才能收到结果?

有一个方法 ODBCResultSet.ExecProcedure,所以这样的方法可能有效:

Dim inputParm as String
Dim outputParm as String

Set inputParm = 'arg1'
result.ExecProcedure('SCHEME.GETDATA',inputParm,outputParm)

Print outputParm

请注意,您可能希望使用大写的过程名称。

Link to the manual page.

我发现以下解决方案适合我。它使用 LCConnection class 而不是 ODBCConnection

Dim sess As New LCSession
Dim conn As New LCConnection ("db2")

'set the connection parameters...
conn.Database = "ODBCSourceName"
conn.UserId = "user"
conn.Password = "pass"

'connect to the database...
conn.Connect    

'set the stored procedure owner and stored procedure name...            
conn.Procedure = "SCHEME.getData"

'set Fieldnames property with any output parameters declared in 
'the stored procedure...
conn.Fieldnames = "outputParam" 'stored procedure output param name



'declare any fields and fieldlists for input/output data...

Dim inputParams As New LCFieldList
Dim outputParams As New LCFieldlist
Dim inputValue As LCField
Dim outputValue As LCField

Dim out As Double

'set the input parameters of the stored procedure...                
Set inputValue = inputParams.Append ("inputParam", LCTYPE_TEXT) 'stored procedure input param name                  
inputValue.Value = "my input value"                 


'with the input parameters set, call the stored procedure...
'the declared output_parms fieldlist will hold the output parameters 
'of the stored procedure...

out = conn.Call (inputParams, 1, outputParams)

'fetch parameter(s) into the output_parms fieldlist...
out = conn.Fetch (outputParams) 

'retrieve the parameter(s) from the output_parms fieldlist...
Set outputValue = outputParams.GetField (1)         

'do somethin with the result
Print outputValue.Value(0)  

更多信息: