当前位置导航:炫浪网>>网络学院>>编程开发>>Oracle教程

VB调用Oracle返回数据集


  PL/SQL 代码:
  CREATE OR REPLACE PACKAGE "PKG_TEST" AS
  TYPE myrcType IS REF CURSOR;
  FUNCTION get(strbarcode VARCHAR) RETURN myrcType;
  END pkg_test;
  
  CREATE OR REPLACE PACKAGE BODY "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 代码:
  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, 100, "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
相关内容
赞助商链接