1

我正在使用 Visual Basic 6 连接到 Oracle 11g。是的,我可以成功连接到数据库。问题是从数据库接收记录集。我创建了一个如下所示的 oracle 包:

包裹:

CREATE OR REPLACE PACKAGE PKG_BASECODE AS

TYPE T_CURSOR IS REF CURSOR;

--// customer
PROCEDURE CustomerCode (
    I_CUST_CODE          IN VARCHAR2
    , I_CUST_NAME        IN VARCHAR2
    , customer_cursor    OUT T_CURSOR
);

END PKG_BASECODE;
/

身体:

CREATE OR REPLACE PACKAGE BODY PKG_BASECODE AS

--// customer
PROCEDURE CustomerCode (
    I_CUST_CODE          IN VARCHAR2
    , I_CUST_NAME        IN VARCHAR2
    , customer_cursor    OUT T_CURSOR
)
IS
    BEGIN
    OPEN customer_cursor FOR
    SELECT  CUST_CODE      AS KEYVALUE
            , CUST_NAME    AS DATAVALUE
    FROM    CUSTOMER_MASTER
    WHERE   CUST_CODE      LIKE I_CUST_CODE || '%'
    AND     CUST_NAME      LIKE I_CUST_NAME || '%'
    ORDER BY CUST_NAME ASC
    ;
    END CustomerCode;


END PKG_BASECODE;
/

它适用于 C#。我已经测试过了。

现在我的 Visual Basic 6 源代码如下:

Dim rst As ADODB.Recordset
Dim cmd As ADODB.Command
Dim input1 As ADODB.Parameter
Dim input2 As ADODB.Parameter
Dim output1 As ADODB.Parameter
Set cmd = CreateObject("ADODB.Command")
With cmd
    .ActiveConnection = tmpDB_Total

    .CommandText = "PKG_BASECODE.CustomerCode"
    .CommandType = adCmdStoredProc

    .Parameters.Append .CreateParameter("I_CUST_CODE", adVarChar, adParamInput, 10, "")
    .Parameters.Append .CreateParameter("I_CUST_NAME", adVarChar, adParamInput, 50, "")
    .Parameters.Append .CreateParameter("CustomerCode", adVarChar, adParamReturnValue)
    Set rst = .Execute
End With

If Not rst.BOF And Not rst.EOF Then
    Do Until rst.EOF
        Debug.Print rst.Fields(1).Value & "," & rst.Fields(0).Value
        rst.MoveNext
    Loop
End If

连接源如下:

tmpDB_Total.Open "Provider=OraOLEDB.Oracle;" _
                 & "Password=mes123;" _
                 & "User ID=mes;" _
                 & "Persist Security Info=True;" _
                 & "Data Source=stmdev;"

我收到一个关于参数的错误。错误信息是用韩语写的,所以我不能马上写。请理解我。谁能帮我解决这个问题?

4

1 回答 1

2

你在那里有一个额外的参数。只是不要尝试为第三个参数附加任何内容,它应该可以工作。请注意,您将需要设置Cmd.Properties("PLSQLRSet") = TRUE

于 2011-10-28T01:40:10.593 回答