Visual Basic 与 Oracle 11g 使用 REF CURSOR 不起作用

发布于 2024-12-12 11:28:44 字数 2150 浏览 0 评论 0原文

我正在使用 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;"

我收到一个有关参数的错误。 错误信息是用韩语写的,所以我不能直接写。 请理解我。 有人能帮我解决这个问题吗?

I am using Visual Basic 6 to connect to Oracle 11g.
Yes, I can successfully connect to the database.
The problem is to receive the recordsets from the database.
I have created an oracle package like below:

Package:

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;
/

Body:

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;
/

It works great with C#.
I have already tested.

Now I have my Visual Basic 6 source codes below:

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

And the connection source is below:

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

And I receive an error something about parameters.
The error message is written in Korean language, so I cannot write straight away.
Please understand me.
Could anyone help me with this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神也荒唐 2024-12-19 11:28:44

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

You've got an extra parameter in there. Just don't try to append anything for that third parameter, and it should work. Note that you will need to set Cmd.Properties("PLSQLRSet") = TRUE

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文