473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

Jul 12 '07 #1
8 11226
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.
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
Jul 12 '07 #2
On Jul 12, 10:10 am, Tim Marshall
<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.

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

Jul 12 '07 #3
On 12 Jul, 19:47, Gord <g...@kingston.netwrote:
On Jul 12, 10:10 am, Tim Marshall

<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.
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- 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.

Jul 16 '07 #4
On Jul 16, 5:21 am, colmkav <colmj...@yahoo.co.ukwrote:
On 12 Jul, 19:47, Gord <g...@kingston.netwrote:
On Jul 12, 10:10 am, Tim Marshall
<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.
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- 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.
Sorry, I don't understand your question.

Jul 16 '07 #5
On 16 Jul, 17:53, Gord <g...@kingston.netwrote:
On Jul 16, 5:21 am, colmkav <colmj...@yahoo.co.ukwrote:


On 12 Jul, 19:47, Gord <g...@kingston.netwrote:
On Jul 12, 10:10 am, Tim Marshall
<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.
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- 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.

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)

Jul 17 '07 #6
On Jul 17, 3:33 am, colmkav <colmj...@yahoo.co.ukwrote:
On 16 Jul, 17:53, Gord <g...@kingston.netwrote:
On Jul 16, 5:21 am, colmkav <colmj...@yahoo.co.ukwrote:
On 12 Jul, 19:47, Gord <g...@kingston.netwrote:
On Jul 12, 10:10 am, Tim Marshall
<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.
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- 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.
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)
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;

Jul 17 '07 #7
On 17 Jul, 12:46, Gord <g...@kingston.netwrote:
On Jul 17, 3:33 am, colmkav <colmj...@yahoo.co.ukwrote:


On 16 Jul, 17:53, Gord <g...@kingston.netwrote:
On Jul 16, 5:21 am, colmkav <colmj...@yahoo.co.ukwrote:
On 12 Jul, 19:47, Gord <g...@kingston.netwrote:
On Jul 12, 10:10 am, Tim Marshall
<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.
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- 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.
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)

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.
Jul 17 '07 #8
On Jul 17, 6:59 am, colmkav <colmj...@yahoo.co.ukwrote:
On 17 Jul, 12:46, Gord <g...@kingston.netwrote:
On Jul 17, 3:33 am, colmkav <colmj...@yahoo.co.ukwrote:
On 16 Jul, 17:53, Gord <g...@kingston.netwrote:
On Jul 16, 5:21 am, colmkav <colmj...@yahoo.co.ukwrote:
On 12 Jul, 19:47, Gord <g...@kingston.netwrote:
On Jul 12, 10:10 am, Tim Marshall
<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.
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- 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.
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)
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.
The only way? Perhaps not, but IMO it is no more convoluted than using
an ADODB.Command object to return values from Procedures.

Jul 17 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sachin Narasimhan via .NET 247 | last post by:
(Type your message here) Hi, I am at my wits end. It would be great if someone can help. Wehave a Stored Function(Oracle) that returns a boolean that wecannot change to return something else and we...
1
by: robin via SQLMonster.com | last post by:
I've tried several different way to execute a oracle stored procedure from a DTS package but to no avail. I have a Linked Server setup which does bring back Oracle tables from the server when I...
4
by: Sameer Deshpande | last post by:
How do I create and return user defined data types in DB2. F.ex In Oracle I can create a user define datatype and return this data type from stored function. How can I do the same in DB2? ...
2
by: Raj | last post by:
Hi, Does anybody know how to call an oracle stored procedure ( with parameters ofcourse) from MS Access 2002. I want to invoke an oracle stored procedure which takes 2 parameters. Thanks,...
0
by: george | last post by:
Hi world! Anyone experienced building gridview in Oracle environment using stored procedures, please help! Right now, I have issues using Oracle SP, I spent a whole day on this and still...
2
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I can successfully insert and update the oracle database by calling a oracles stored proc from my .net code. This oracle stored proc is returning some value. I cannot see that...
1
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I can successfully insert and update the oracle database by calling a oracles stored proc from my .net code. This oracle stored proc is returning some value. I cannot see that...
7
by: E11esar | last post by:
Hi there. I have written a C# web service that calls an Oracle stored procedure. The SP is a simple select-max query and the table it is getting the value from has about 2.8 million rows in it. ...
3
by: rajkumarbathula | last post by:
Hi I was struck up with big problem of executing a oracle stored procedure in C#. Inputs 1:I am having 1 oracle stored procedure eg. myProc() and this procedure takes 1 INOUT parameter. of type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.