Nigel's post above shows code for a pl/sql procedure returning a ref cursor as an in/out parameter -- and the accompanying VB. I think it is unnecessary to explicity define the cursor as a parameter to ADO as Tom shows here: </code>
http://asktom.oracle.com/~tkyte/ResultSets/index.html <code>
I have a similar working example.
In package specification:
TYPE metric_rt IS RECORD
(m_id metric.id%TYPE,
m_owningOrgId metric.owningOrgId%TYPE,
m_uomId metric.uomId%TYPE,
m_frequencyId metric.frequencyId%TYPE,
m_calendarIndicator metric.calendarIndicator%TYPE,
m_name metric.name%TYPE,
m_abbreviation metric.abbreviation%TYPE,
m_owningOrgName organization.name%TYPE);
TYPE metric_rct IS REF CURSOR RETURN metric_rt;
function getMetric(p_metricId_in IN number)
return metric_rct;
procedure getMetricProc(p_metricId_in IN number,
p_cursor_out IN OUT metric_rct);
in package body:
function getMetric(p_metricId_in IN number)
return metric_rct
is
metric_ref_cursor metric_rct;
begin
OPEN metric_ref_cursor FOR
SELECT m.id,
m.owningOrgId,
m.uomId,
m.frequencyId,
m.calendarIndicator,
m.name,
m.abbreviation,
o.name as owningOrgName
FROM metrics.metric m, metrics.organization o
WHERE m.id = p_metricId_in
AND o.id = m.owningOrgId;
RETURN metric_ref_cursor;
end getMetric;
procedure getMetricProc(p_metricId_in IN number,
p_cursor_out IN OUT metric_rct)
is
begin
OPEN p_cursor_out FOR
SELECT m.id,
m.owningOrgId,
m.uomId,
m.frequencyId,
m.calendarIndicator,
m.name,
m.abbreviation,
o.name as owningOrgName
FROM metrics.metric m, metrics.organization o
WHERE m.id = p_metricId_in
AND o.id = m.owningOrgId;
end getMetricProc;
Note that I have a function returning a ref cursor, and a proc with an in/out ref cursor, both of which do the same sql.
I am a Java developer who has working VB/ADO code calling the proc, but can't figure out how to call the function.
Every example I found on the internet is of a proc with an in/out parameter.
This works for the proc:
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=MSDAORA.1;Password=blabla;User ID=blabla;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=somehost)(PORT=1522))(CONNECT_DATA=(SID = mysid)))"
conn.Open
Dim proc As ADODB.Command
Set proc = New ADODB.Command
Set proc.ActiveConnection = conn
proc.CommandType = adCmdStoredProc
proc.CommandText = "metrics_pkg.getMetricProc"
proc.Prepared = False
proc.Parameters.Append proc.CreateParameter("p_metricId_in", adInteger, adParamInput, , 3)
Dim rs As New ADODB.Recordset
Set rs = proc.Execute
While Not rs.EOF
Debug.Print rs(0)
Debug.Print rs(1)
Debug.Print rs(2)
Debug.Print rs(3)
Debug.Print rs(4)
Debug.Print rs(5)
Debug.Print rs(6)
Debug.Print rs(7)
rs.MoveNext
Wend
rs.Close
conn.Close
Set proc = Nothing
Set rs = Nothing
Set conn = Nothing
If I change the name of the proc to be "metrics_pkg.getMetric", the above code fails with
"Wrong number or types of arguments in call to getMetric" ORA-06550.
Anyone know how to call a function which returns a ref cursor from VB/ADO?