Example of VB calling Oracle function return DataSet

Source: Internet
Author: User
oracle| Function | Data pl/sql code:
CREATE OR REPLACE PACKAGE "SCOTT". " Pkg_test "as
TYPE Myrctype is REF CURSOR;
FUNCTION get (Strbarcode VARCHAR) return myrctype;
End Pkg_test;

CREATE OR REPLACE PACKAGE Body "SCOTT". Pkg_test "as
FUNCTION get (Strbarcode in VARCHAR) return Myrctype is
RC Myrctype;
BEGIN
OPEN RC for Strbarcode;
return RC;
End get;
End Pkg_test;
--------------------------------------------------------------------------------------------------------
VB Code:
Private Sub Command1_Click ()
On Error GoTo Cursorerr:
Dim CNN as New ADODB. Connection
Dim rst as New ADODB. Recordset
Dim cmd as New adodb.command

Cnn. ConnectionString = "PROVIDER=ORAOLEDB.ORACLE.1; Password=tiger; Persist Security info=true; User Id=scott;data Source=oraany; Extended Properties=plsqlrset=1 "
Cnn. Open

With cmd
. ActiveConnection = CNN
. CommandType = adCmdText
. CommandText = "{call Scott.pkg_test.get (?)}"
. Parameters.Append. CreateParameter ("Strbarcode", adVarChar, adParamInput, "Select * from Tab")
End With

Rst. CursorType = adOpenStatic
Rst. LockType = adLockReadOnly
Set rst. Source = cmd
Rst. Open

MsgBox rst. RecordCount

Set rst = Nothing
Set cmd = Nothing
Exit Sub

Cursorerr:
Set cmd = Nothing
Set Rst1 = Nothing
MsgBox Err.Description
End Sub


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.