How to call a pl/sql function from Access97 using ODBCDirect ?

From: (wrong string) érôme Villafruela <jerome_villafruela_at_yoni.fr>
Date: Wed, 31 Mar 1999 22:33:10 GMT
Message-ID: <370aa28b.6794159_at_news.directprovider.net>



Hello !

I have to write an import procedure to transfer data from an MS Access97 'database' to Oracle 8.0.5 and I need to call a stored function from a VBA module.

I thought this would be easy using an ODBCDirect workspace as indicated in the doc (MS Office 97/Visual basic programmer's guide - chapter 11) but I didn't manage to handle the function's return value.

here is my first try :

Sub odbc_test()
Dim wrk As Workspace, cnn As Connection, rst As Recordset Dim strConnect As String ' Create ODBCDirect workspace. Dim qdf As QueryDef

    Set wrk = DBEngine.CreateWorkspace("ODBCDirect", "Admin", "", dbUseODBC)

    strConnect = "ODBC;DSN=ORCL;UID=SCOTT;PWD=tiger;" ' Open connection.     Set cnn = wrk.OpenConnection("", dbDriverNoPrompt, False, strConnect)     

    Set qdf = cnn.CreateQueryDef("Qry", "{? = call JVAFUNC(?) }")     qdf.Parameters(0).Direction = dbParamReturnValue     qdf.Parameters(1) = 10 'error here, seems there's only 1 parameter     On Error GoTo errprint:
    qdf.Execute

    qdf.Close
    cnn.Close
    wrk.Close

    Exit Sub
errprint:

    Dim MyError As Error
    For Each MyError In DBEngine.Errors

       Debug.Print MyError.Number, MyError.Description     Next MyError
End Sub

The JVAFUNC is defined as :
FUNCTION JVAFUNC(prm in integer) RETURN INTEGER IS n integer;
BEGIN
 n:= prm*2;
 return n;
END; According to the doc the syntax for calling stored procs in an Oracle or SQL Server should be the same : {? = call stored-func(?) } From the sample code I've infered that the return value is stored in parameter #0 but this doesn't work. (at least using Oracle 8.0.5 ODBC driver).

However I've found a workaround :

    Set qdf = cnn.CreateQueryDef("Qry", "select JVAFUNC(?) from dual")     qdf.Parameters(0) = 10
    On Error GoTo errprint:
    Set rst = qdf.OpenRecordset
    Debug.Print rst(0).Name, rst(0).Value '=> JVAFUNC(:1) 20

Could someone explain how this parameter stuff is supposed to work ?

-- 
Jérôme Villafruela
Grenoble - FRANCE
Please forgive any spelling mistake, english is not my native language.
Received on Thu Apr 01 1999 - 00:33:10 CEST

Original text of this message