return Oracle stored function value back to Access VBA 
July 12th, 2007, 01:55 PM
| | | return Oracle stored function value back to Access VBA
Can someone tell me how I can access the return value of a function
called from Oracle as opposed to a store proc from oracle? my oracle
function is get_num_dates_varposfile. I am only used to using this
method with store procs that dont return a value back to Access. Hope
this makes sense.
Set Cmd = New Command
With Cmd
Set .ActiveConnection = get_XE_Conn 'makes a connection
Oracle XE
.CommandType = adCmdStoredProc
.CommandText = "pkg_EQRISK.get_num_dates_varposfile"
'returns the number of
distinct dates in tmp_varposition table using Oracle proc
.Execute , , adExecuteNoRecords
End With
Set Cmd = Nothing
Private m_conn As ADODB.Connection
Public Function get_XE_Conn() As ADODB.Connection
If m_conn Is Nothing Then
Set m_conn = New ADODB.Connection
End If
If m_conn.State <adStateOpen Then
m_conn.Open "PROVIDER=MSDAORA.1;USER
ID=EQRISK;PASSWORD=eq;DATA SOURCE=XE;"
'//m_conn.Open "Driver={Oracle in
XE};Server=XE;Uid=EQRISK;Pwd=eq;"
'//m_conn.Open "ODBC;DSN=EQRISK;DBQ=XE;UID=EQRISK;PWD=eq"
End If
Set get_XE_Conn = m_conn
End Function | 
July 12th, 2007, 03:15 PM
| | | Re: return Oracle stored function value back to Access VBA
colmkav wrote: Quote:
Can someone tell me how I can access the return value of a function
called from Oracle as opposed to a store proc from oracle? my oracle
function is get_num_dates_varposfile. I am only used to using this
method with store procs that dont return a value back to Access. Hope
this makes sense.
| I didn't look closely at your code as I stick exclusively to DAO when
writing mdbs against Oracle back ends (which is what all my work
comprises), but have you tried running:
Select get_num_dates_varposfile from dual
Or whatever SQL statement is required to get the function to run in SQL
Plus via a pass through query with returns records set to true?
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me | 
July 12th, 2007, 05:55 PM
| | | Re: return Oracle stored function value back to Access VBA
On Jul 12, 10:10 am, Tim Marshall
<TIM...@PurplePandaChasers.Moertheriumwrote: Quote:
colmkav wrote: Quote:
Can someone tell me how I can access the return value of a function
called from Oracle as opposed to a store proc from oracle? my oracle
function is get_num_dates_varposfile. I am only used to using this
method with store procs that dont return a value back to Access. Hope
this makes sense.
| >
I didn't look closely at your code as I stick exclusively to DAO when
writing mdbs against Oracle back ends (which is what all my work
comprises), but have you tried running:
>
Select get_num_dates_varposfile from dual
>
Or whatever SQL statement is required to get the function to run in SQL
Plus via a pass through query with returns records set to true?
>
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
| FWIW, this works for me (VBScript example):
Option Explicit
Dim con, rst
Set con = CreateObject("ADODB.Connection")
con.CursorLocation = 3 ' adUseClient
con.Properties("Prompt") = 2 ' adPromptComplete
con.Open "DSN=Oracle ODBC local GDT;"
Set rst = CreateObject("ADODB.Recordset")
rst.Open _
"SELECT MYTESTFUNC FROM DUAL", _
con, 3, 1
Wscript.Echo rst(0).Value
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing | 
July 16th, 2007, 09:25 AM
| | | Re: return Oracle stored function value back to Access VBA
On 12 Jul, 19:47, Gord <g...@kingston.netwrote: Quote:
On Jul 12, 10:10 am, Tim Marshall
>
>
>
>
>
<TIM...@PurplePandaChasers.Moertheriumwrote: Quote:
colmkav wrote: Quote:
Can someone tell me how I can access the return value of a function
called from Oracle as opposed to a store proc from oracle? my oracle
function is get_num_dates_varposfile. I am only used to using this
method with store procs that dont return a value back to Access. Hope
this makes sense.
| | > Quote:
I didn't look closely at your code as I stick exclusively to DAO when
writing mdbs against Oracle back ends (which is what all my work
comprises), but have you tried running:
| > Quote: |
Select get_num_dates_varposfile from dual
| > Quote:
Or whatever SQL statement is required to get the function to run in SQL
Plus via a pass through query with returns records set to true?
| >>
FWIW, this works for me (VBScript example):
>
Option Explicit
>
Dim con, rst
>
Set con = CreateObject("ADODB.Connection")
con.CursorLocation = 3 ' adUseClient
con.Properties("Prompt") = 2 ' adPromptComplete
con.Open "DSN=Oracle ODBC local GDT;"
>
Set rst = CreateObject("ADODB.Recordset")
rst.Open _
"SELECT MYTESTFUNC FROM DUAL", _
con, 3, 1
>
Wscript.Echo rst(0).Value
>
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing- Hide quoted text -
>
- Show quoted text -
| thanks. I guess this would work.
Do you know if its possible to return the return value of an Oracle
function in cases where a recordset? I know how to do this via a
stored proc but not a function. | 
July 16th, 2007, 03:55 PM
| | | Re: return Oracle stored function value back to Access VBA
On Jul 16, 5:21 am, colmkav <colmj...@yahoo.co.ukwrote: Quote:
On 12 Jul, 19:47, Gord <g...@kingston.netwrote:
>
>
> Quote: |
On Jul 12, 10:10 am, Tim Marshall
| > Quote:
<TIM...@PurplePandaChasers.Moertheriumwrote: Quote:
colmkav wrote:
Can someone tell me how I can access the return value of a function
called from Oracle as opposed to a store proc from oracle? my oracle
function is get_num_dates_varposfile. I am only used to using this
method with store procs that dont return a value back to Access. Hope
this makes sense.
| | > Quote: Quote:
I didn't look closely at your code as I stick exclusively to DAO when
writing mdbs against Oracle back ends (which is what all my work
comprises), but have you tried running:
| | > Quote: Quote: |
Select get_num_dates_varposfile from dual
| | > Quote: Quote:
Or whatever SQL statement is required to get the function to run in SQL
Plus via a pass through query with returns records set to true?
| | >> Quote: |
FWIW, this works for me (VBScript example):
| >>> Quote:
Set con = CreateObject("ADODB.Connection")
con.CursorLocation = 3 ' adUseClient
con.Properties("Prompt") = 2 ' adPromptComplete
con.Open "DSN=Oracle ODBC local GDT;"
| > Quote:
Set rst = CreateObject("ADODB.Recordset")
rst.Open _
"SELECT MYTESTFUNC FROM DUAL", _
con, 3, 1
| > Quote: |
Wscript.Echo rst(0).Value
| > Quote:
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing- Hide quoted text -
| >>
thanks. I guess this would work.
>
Do you know if its possible to return the return value of an Oracle
function in cases where a recordset? I know how to do this via a
stored proc but not a function.
| Sorry, I don't understand your question. | 
July 17th, 2007, 07:35 AM
| | | Re: return Oracle stored function value back to Access VBA
On 16 Jul, 17:53, Gord <g...@kingston.netwrote: Quote:
On Jul 16, 5:21 am, colmkav <colmj...@yahoo.co.ukwrote:
>
>
>
>
> Quote: |
On 12 Jul, 19:47, Gord <g...@kingston.netwrote:
| > Quote: Quote: |
On Jul 12, 10:10 am, Tim Marshall
| | > Quote: Quote:
<TIM...@PurplePandaChasers.Moertheriumwrote:
colmkav wrote:
Can someone tell me how I can access the return value of a function
called from Oracle as opposed to a store proc from oracle? my oracle
function is get_num_dates_varposfile. I am only used to using this
method with store procs that dont return a value back to Access. Hope
this makes sense.
| | > Quote: Quote:
I didn't look closely at your code as I stick exclusively to DAO when
writing mdbs against Oracle back ends (which is what all my work
comprises), but have you tried running:
| | > Quote: Quote: |
Select get_num_dates_varposfile from dual
| | > Quote: Quote:
Or whatever SQL statement is required to get the function to run in SQL
Plus via a pass through query with returns records set to true?
| | >> Quote: Quote: |
FWIW, this works for me (VBScript example):
| | >>> Quote: Quote:
Set con = CreateObject("ADODB.Connection")
con.CursorLocation = 3 ' adUseClient
con.Properties("Prompt") = 2 ' adPromptComplete
con.Open "DSN=Oracle ODBC local GDT;"
| | > Quote: Quote:
Set rst = CreateObject("ADODB.Recordset")
rst.Open _
"SELECT MYTESTFUNC FROM DUAL", _
con, 3, 1
| | > Quote: Quote: |
Wscript.Echo rst(0).Value
| | > Quote: Quote:
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing- Hide quoted text -
| | >> Quote: |
thanks. I guess this would work.
| > Quote:
Do you know if its possible to return the return value of an Oracle
function in cases where a recordset? I know how to do this via a
stored proc but not a function.
| >
Sorry, I don't understand your question.- Hide quoted text -
>
- Show quoted text -
| What I mean is if I run a stored procedure I know how to return a
value through one of the parameters
eg
Dim UpdateCmd As ADODB.Command
Set Cmd = New Command
With Cmd
Set .ActiveConnection = get_XE_Conn 'makes a connection
Oracle XE
.CommandType = adCmdStoredProc
.CommandText = "pkg_EQRISK.get_num_dates_Varposfile"
'returns the no. of distinct dates
in tmp_varposition using Oracle proc
.Execute , , adExecuteNoRecords
End With
debug.print Cmd(1)
however, if I want to write it as a function I am not sure how to do
this. (Cmd(1) returns the value in the 2nd parameter) | 
July 17th, 2007, 10:55 AM
| | | Re: return Oracle stored function value back to Access VBA
On Jul 17, 3:33 am, colmkav <colmj...@yahoo.co.ukwrote: Quote:
On 16 Jul, 17:53, Gord <g...@kingston.netwrote:
>
>
> Quote: |
On Jul 16, 5:21 am, colmkav <colmj...@yahoo.co.ukwrote:
| > Quote: Quote: |
On 12 Jul, 19:47, Gord <g...@kingston.netwrote:
| | > Quote: Quote: |
On Jul 12, 10:10 am, Tim Marshall
| | > Quote: Quote:
<TIM...@PurplePandaChasers.Moertheriumwrote:
colmkav wrote:
Can someone tell me how I can access the return value of a function
called from Oracle as opposed to a store proc from oracle? my oracle
function is get_num_dates_varposfile. I am only used to using this
method with store procs that dont return a value back to Access. Hope
this makes sense.
| | > Quote: Quote:
I didn't look closely at your code as I stick exclusively to DAO when
writing mdbs against Oracle back ends (which is what all my work
comprises), but have you tried running:
| | > Quote: Quote: |
Select get_num_dates_varposfile from dual
| | > Quote: Quote:
Or whatever SQL statement is required to get the function to run in SQL
Plus via a pass through query with returns records set to true?
| | >> Quote: Quote: |
FWIW, this works for me (VBScript example):
| | >>> Quote: Quote:
Set con = CreateObject("ADODB.Connection")
con.CursorLocation = 3 ' adUseClient
con.Properties("Prompt") = 2 ' adPromptComplete
con.Open "DSN=Oracle ODBC local GDT;"
| | > Quote: Quote:
Set rst = CreateObject("ADODB.Recordset")
rst.Open _
"SELECT MYTESTFUNC FROM DUAL", _
con, 3, 1
| | > Quote: Quote: |
Wscript.Echo rst(0).Value
| | > Quote: Quote:
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing- Hide quoted text -
| | >> Quote: Quote: |
thanks. I guess this would work.
| | > Quote: Quote:
Do you know if its possible to return the return value of an Oracle
function in cases where a recordset? I know how to do this via a
stored proc but not a function.
| | > Quote: |
Sorry, I don't understand your question.- Hide quoted text -
| >>
What I mean is if I run a stored procedure I know how to return a
value through one of the parameters
>
eg
>
Dim UpdateCmd As ADODB.Command
>
Set Cmd = New Command
With Cmd
Set .ActiveConnection = get_XE_Conn 'makes a connection
Oracle XE
.CommandType = adCmdStoredProc
.CommandText = "pkg_EQRISK.get_num_dates_Varposfile"
'returns the no. of distinct dates
in tmp_varposition using Oracle proc
.Execute , , adExecuteNoRecords
End With
debug.print Cmd(1)
>
however, if I want to write it as a function I am not sure how to do
this. (Cmd(1) returns the value in the 2nd parameter)
| Have your function return a value, then call it using an
ADODB.Recordset object as I illustrated previously.
In that example my test function was simply
create or replace function "MYTESTFUNC"
return VARCHAR2
is
begin
RETURN 'Gord was here.';
end; | 
July 17th, 2007, 11:05 AM
| | | Re: return Oracle stored function value back to Access VBA
On 17 Jul, 12:46, Gord <g...@kingston.netwrote: Quote:
On Jul 17, 3:33 am, colmkav <colmj...@yahoo.co.ukwrote:
>
>
>
>
> Quote: |
On 16 Jul, 17:53, Gord <g...@kingston.netwrote:
| > Quote: Quote: |
On Jul 16, 5:21 am, colmkav <colmj...@yahoo.co.ukwrote:
| | > Quote: Quote: |
On 12 Jul, 19:47, Gord <g...@kingston.netwrote:
| | > Quote: Quote: |
On Jul 12, 10:10 am, Tim Marshall
| | > Quote: Quote:
<TIM...@PurplePandaChasers.Moertheriumwrote:
colmkav wrote:
Can someone tell me how I can access the return value of a function
called from Oracle as opposed to a store proc from oracle? my oracle
function is get_num_dates_varposfile. I am only used to using this
method with store procs that dont return a value back to Access. Hope
this makes sense.
| | > Quote: Quote:
I didn't look closely at your code as I stick exclusively to DAO when
writing mdbs against Oracle back ends (which is what all my work
comprises), but have you tried running:
| | > Quote: Quote: |
Select get_num_dates_varposfile from dual
| | > Quote: Quote:
Or whatever SQL statement is required to get the function to run in SQL
Plus via a pass through query with returns records set to true?
| | >> Quote: Quote: |
FWIW, this works for me (VBScript example):
| | >>> Quote: Quote:
Set con = CreateObject("ADODB.Connection")
con.CursorLocation = 3 ' adUseClient
con.Properties("Prompt") = 2 ' adPromptComplete
con.Open "DSN=Oracle ODBC local GDT;"
| | > Quote: Quote:
Set rst = CreateObject("ADODB.Recordset")
rst.Open _
"SELECT MYTESTFUNC FROM DUAL", _
con, 3, 1
| | > Quote: Quote: |
Wscript.Echo rst(0).Value
| | > Quote: Quote:
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing- Hide quoted text -
| | >> Quote: Quote: |
thanks. I guess this would work.
| | > Quote: Quote:
Do you know if its possible to return the return value of an Oracle
function in cases where a recordset? I know how to do this via a
stored proc but not a function.
| | > Quote: Quote: |
Sorry, I don't understand your question.- Hide quoted text -
| | >> Quote:
What I mean is if I run a stored procedure I know how to return a
value through one of the parameters
| >> Quote: |
Dim UpdateCmd As ADODB.Command
| > Quote:
Set Cmd = New Command
With Cmd
Set .ActiveConnection = get_XE_Conn 'makes a connection
Oracle XE
.CommandType = adCmdStoredProc
.CommandText = "pkg_EQRISK.get_num_dates_Varposfile"
'returns the no. of distinct dates
in tmp_varposition using Oracle proc
.Execute , , adExecuteNoRecords
End With
debug.print Cmd(1)
| > Quote:
however, if I want to write it as a function I am not sure how to do
this. (Cmd(1) returns the value in the 2nd parameter)
| >
Have your function return a value, then call it using an
ADODB.Recordset object as I illustrated previously.
>
In that example my test function was simply
>
create or replace function "MYTESTFUNC"
return VARCHAR2
is
begin
RETURN 'Gord was here.';
end;- Hide quoted text -
>
- Show quoted text -
| ok, thanks. I see what you mean now. Is this the only way to return
the value of a function? Seems slightly convoluted. | 
July 17th, 2007, 11:55 AM
| | | Re: return Oracle stored function value back to Access VBA
On Jul 17, 6:59 am, colmkav <colmj...@yahoo.co.ukwrote: Quote:
On 17 Jul, 12:46, Gord <g...@kingston.netwrote:
>
>
> Quote: |
On Jul 17, 3:33 am, colmkav <colmj...@yahoo.co.ukwrote:
| > Quote: Quote: |
On 16 Jul, 17:53, Gord <g...@kingston.netwrote:
| | > Quote: Quote: |
On Jul 16, 5:21 am, colmkav <colmj...@yahoo.co.ukwrote:
| | > Quote: Quote: |
On 12 Jul, 19:47, Gord <g...@kingston.netwrote:
| | > Quote: Quote: |
On Jul 12, 10:10 am, Tim Marshall
| | > Quote: Quote:
<TIM...@PurplePandaChasers.Moertheriumwrote:
colmkav wrote:
Can someone tell me how I can access the return value of a function
called from Oracle as opposed to a store proc from oracle? my oracle
function is get_num_dates_varposfile. I am only used to using this
method with store procs that dont return a value back to Access. Hope
this makes sense.
| | > Quote: Quote:
I didn't look closely at your code as I stick exclusively to DAO when
writing mdbs against Oracle back ends (which is what all my work
comprises), but have you tried running:
| | > Quote: Quote: |
Select get_num_dates_varposfile from dual
| | > Quote: Quote:
Or whatever SQL statement is required to get the function to run in SQL
Plus via a pass through query with returns records set to true?
| | >> Quote: Quote: |
FWIW, this works for me (VBScript example):
| | >>> Quote: Quote:
Set con = CreateObject("ADODB.Connection")
con.CursorLocation = 3 ' adUseClient
con.Properties("Prompt") = 2 ' adPromptComplete
con.Open "DSN=Oracle ODBC local GDT;"
| | > Quote: Quote:
Set rst = CreateObject("ADODB.Recordset")
rst.Open _
"SELECT MYTESTFUNC FROM DUAL", _
con, 3, 1
| | > Quote: Quote: |
Wscript.Echo rst(0).Value
| | > Quote: Quote:
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing- Hide quoted text -
| | >> Quote: Quote: |
thanks. I guess this would work.
| | > Quote: Quote:
Do you know if its possible to return the return value of an Oracle
function in cases where a recordset? I know how to do this via a
stored proc but not a function.
| | > Quote: Quote: |
Sorry, I don't understand your question.- Hide quoted text -
| | >> Quote: Quote:
What I mean is if I run a stored procedure I know how to return a
value through one of the parameters
| | >> Quote: Quote: |
Dim UpdateCmd As ADODB.Command
| | > Quote: Quote:
Set Cmd = New Command
With Cmd
Set .ActiveConnection = get_XE_Conn 'makes a connection
Oracle XE
.CommandType = adCmdStoredProc
.CommandText = "pkg_EQRISK.get_num_dates_Varposfile"
'returns the no. of distinct dates
in tmp_varposition using Oracle proc
.Execute , , adExecuteNoRecords
End With
debug.print Cmd(1)
| | > Quote: Quote:
however, if I want to write it as a function I am not sure how to do
this. (Cmd(1) returns the value in the 2nd parameter)
| | > Quote:
Have your function return a value, then call it using an
ADODB.Recordset object as I illustrated previously.
| > Quote: |
In that example my test function was simply
| > Quote:
create or replace function "MYTESTFUNC"
return VARCHAR2
is
begin
RETURN 'Gord was here.';
end;- Hide quoted text -
| >>
ok, thanks. I see what you mean now. Is this the only way to return
the value of a function? Seems slightly convoluted.
| The only way? Perhaps not, but IMO it is no more convoluted than using
an ADODB.Command object to return values from Procedures. | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,989 network members.
|