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

时间:2015-08-27 13:11:10

标签: stored-procedures db2 lotus-notes lotusscript

我有以下DB2存储过程

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

我想在on param上运行此过程并在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语句添加什么以及如何处理结果以便接收结果?

2 个答案:

答案 0 :(得分:1)

有一个方法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.

答案 1 :(得分:0)

我发现以下解决方案对我有用。它使用LCConnection类而不是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)  

更多信息: