使用IN参数调用Oracle存储过程时的运行时错误3151

时间:2014-10-09 08:52:02

标签: oracle vba ms-access access-vba ms-access-2003

我正在尝试在MS Access中调用Oracle过程。过程有IN参数,我无法调用它,每次我得到“ODBC调用失败”错误。在没有任何IN或OUT参数的情况下运行Oracle过程时,即成功调用并执行所需的结果。我只是想知道如何在Access for Oracle过程中调用参数。

在下面的代码中,我有一个Oracle过程trtP_FILENAME是IN参数,我希望IN参数P_FILENAME仅由用户给出。在那个trt过程中我试图通过utl_file函数导入文件,并且它正常工作,而我在运行SQL Developer时在Access中调用它我无法这样做。

On Error GoTo trap


Dim db As Database
   Dim LSProc As QueryDef
   Dim LSQL As String

   Set db = CurrentDb()

   Set LSProc = db.CreateQueryDef("")

   'SQL to call stored procedure (with parameters)
    LSQL = "BEGIN trt ('" & P_FILENAME & "' )"
    'LSQL = "Begin TRT ('BUSMAY2014.csv')"
    LSQL = LSQL & "; END;"


   'Use {Microsoft ODBC for Oracle} ODBC connection
  LSProc.Connect = "ODBC;DSN=ODM_UNCT;UID=ODM_UNCTLD;PWD=****;SERVER=******"
   LSProc.SQL = LSQL
   LSProc.ReturnsRecords = False
   LSProc.ODBCTimeout = 0

   LSProc.Execute
   'DoCmd.RunSQL ("EXEC trt " & P_FILENAME)
 CallSProc = True
 Exit Sub
trap:
        Dim MyError As Error
      MsgBox Errors.Count
      For Each MyError In DBEngine.Errors
        With MyError
          MsgBox .Number & " " & .Description
        End With
      Next MyError

End Sub

MS ACCESS是前端,Oracle是后端。 TRT是程序名称 P_FILENAME是过程的IN参数

1 个答案:

答案 0 :(得分:1)

以下代码适用于我:

Dim db As DAO.Database, LSProc As DAO.QueryDef
Set db = CurrentDb
Set LSProc = db.CreateQueryDef("")
LSProc.Connect = "ODBC;DSN=ODM_UNCT;UID=GORD;PWD=whatever;"
LSProc.SQL = "BEGIN TRT('HelloFromAccess'); END;"
LSProc.ReturnsRecords = False
LSProc.Execute dbFailOnError
Set LSProc = Nothing
Set db = Nothing