VBA calling Oracle procedure with ref cursor - Oracle error ORA-06550
722748Sep 15 2009 — edited Sep 17 2009Hello,
I created a test procedure in Oracle 10g that returns data to my VBA code via a cursor. Given a last name passed as parameter, the procedure will return all the resources with that last name (first name, last name):
-----------------------------------------------
CREATE OR REPLACE PACKAGE pmo_dashboard AS
TYPE PmoDashboardRecord IS RECORD(
FirstName Varchar2(50),
LastName varchar2(50)
);
TYPE type_pmo_dashboard IS REF CURSOR RETURN PmoDashboardRecord;
End;
/
Create Or Replace Procedure getFullName (
lastname IN VARCHAR2,
recordSetCursor IN OUT pmo_dashboard.type_pmo_dashboard)
AS
BEGIN
Open recordSetCursor for
select first_name,last_name
from resources
where last_name=lastname;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK WORK;
RAISE;
End getFullName;
/
-----------------------------------------------
The code compiles perfect in SQL*Plus, and I have this VBA code (running in Excel 2007, with ADODB 2.8 Library set in references:
------------------------------------------------
Sub Button1_Click()
Dim dbConn As ADODB.Connection
Dim Cmd As ADODB.Command
Dim rs As ADODB.Recordset
On Error GoTo ExitME
Err.Clear
Set dbConn = New ADODB.Connection
With dbConn
.Provider = "OraOLEDB.Oracle"
.Properties("Data Source") = "DBPMODATA"
.Properties("User Id") = "user"
.Properties("Password") = "password"
.Open
End With
Set Cmd = New ADODB.Command
Set Cmd.ActiveConnection = dbConn
With Cmd
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 50, "Smith") 'last name used as test parameter
.Parameters.Append .CreateParameter(, adNumeric, adParamOutput)
End With
If dbConn.State Then
Cmd.Properties("PLSQLRSet") = True
Cmd.CommandType = adCmdText
Cmd.CommandText = "{CALL getfullname(?,?)}"
Set rs = Cmd.Execute()
End If
If Not rs Is Nothing Then
If Not rs.BOF And Not rs.EOF Then
Do Until rs.EOF
Debug.Print rs.Fields(1).Value & "," & rs.Fields(0).Value
rs.MoveNext
Loop
End If
End If
ExitME:
If Not Cmd Is Nothing Then
Set Cmd = Nothing
End If
If Not dbConn Is Nothing Then
If dbConn.State Then dbConn.Close
Set dbConn = Nothing
End If
End Sub
------------------------------------------------------
When the code runs the Execute statement, I get this error:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'GETFULLNAME'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
I've tried changed the parameter types, order, etc. I also tried to enable ODBC tracing, to no avail (the file created was empty )...
Please advise. An help would be greatly appreciated!!!