Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving a value from an Oracle stored procedure. 1

Status
Not open for further replies.

dja1

Programmer
Apr 24, 2002
65
GB
I have the following Oracle Stored Procedure;

Code:
 Create or Replace Procedure CHECK_ACCOUNT_NO
                (SortCode      In   Char,
                 Account_Check In   Char,
                 Check_Ind     Out  Number)
As
Begin
    .
    (Code which sets Check_Ind to 0 or 1) 
    ;
End;
I have the following VB6 code;

Code:
 Dim LNGRETURN   As Long

   strSQL = "BEGIN  CHECK_ACCOUNT_NO _
                     ('SORTCD', 'ABCDEFGH', LNGRETURN); End;"
   Db.Execute strSQL, dbSQLPassThrough
When execute this code, I get the following error;
Error Message: [Microsoft][ODBC driver for Oracle][Oracle]ORA-06550: line 1, column 46:
PLS-00201: identifier 'LNGRETURN' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
ODBC--call failed.


I have to use the DAO Object Model - it would be too expensive to use ADO instead.

How do I get the value for the returned parameter in my application ?


 
If you have just one returned value, why you don't use the function? It would seem more logical.
 
The stored function. Instead of stored procedure. Why do you use procedure instead of the function? And if you cannot transform one into another, try IN OUT instead of OUT.
 
And in any case, I would investigate possible use of DAO Parameters collection and Parameter property (but I never did it with DAO).
 
vladk

Thanks very much for taking the time to reply.

As for using a function, or changing the parameter definition, I have been told that I have to use the present Oracle stored procedure, there simply is no "budget" to change anything on the Oracle database, (I'm sure most of us have been in a similar situation).
 
dja1,

Did you solve your problem? I never used DAO with ORACLE. Instead, I used ORACLE client. And I just attached parameters to the parameters collection in VB(the stored procedure arguments), specifying the properties (type, direction). I assume, DAO might offer similar technique.

vladk
 
You're just trying to pass your variable name as part of the string. Here's what Oracle sees when you send the string:
Code:
BEGIN  CHECK_ACCOUNT_NO ('SORTCD', 'ABCDEFGH', LNGRETURN); End;
Obviously, it's barfing on the LNGRETURN, because you're really trying to pass whatever value LNGRETURN is set to. So, try this:
Code:
Dim LNGRETURN   As Long

   strSQL = "BEGIN  CHECK_ACCOUNT_NO _
                     ('SORTCD', 'ABCDEFGH', [COLOR=red]" & LNGRETURN & "[/color]); End;"
   Db.Execute strSQL, dbSQLPassThrough
I'd be surprised if this weren't your problem.

HTH

Bob
 
Thanks for the continuing replies. Not back in the office until 23/11/2006 - will try it then
 
Vladk
Can't see an equivalent to the ADO Parameters collection in DAO, (except for QDF, which I assume is/are apply only to Access databases).

Bob
Tried your suggestion, as follows;
Code:
Dim intCheckInd     As Integer
Dim strsql          As String

    strsql = "BEGIN CHECK_ACCOUNT_NO('090126', '07449544', "
    strsql = strsql & intCheckInd & "); END;"
    Db.Execute strsql, dbSQLPassThrough
The result in strSQL;
debug.Print strsql
BEGIN CHECK_ACCOUNT_NO('090126', '07449544', 0); END;
[/color blue]
Result of executing the SQL;

Error Message: [Microsoft][ODBC driver for Oracle][Oracle]ORA-06550: line 1, column 46:
PLS-00363: expression '0' cannot be used as an assignment target
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
ODBC--call failed.
[/color blue]
Then tried;
Code:
Dim intCheckInd     As Integer
Dim strsql          As String
    strsql = "BEGIN CHECK_ACCOUNT_NO('090126', '07449544', intcheckind); END; "
    Db.Execute strsql, dbSQLPassThrough
The result in strSQL;
debug.Print strsql
BEGIN CHECK_ACCOUNT_NO('090126', '07449544', intcheckind); END;[/color blue]
Result of executing the SQL;

Error Message: [Microsoft][ODBC driver for Oracle][Oracle]ORA-06550: line 1, column 46:
PLS-00201: identifier 'INTCHECKIND' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
ODBC--call failed.
[/color blue]
Then tried;
Code:
Dim Check_Ind       As Integer
Dim strsql          As String
    strsql = "BEGIN CHECK_ACCOUNT_NO('090126', '07449544', Check_Ind); END; "
    Db.Execute strsql, dbSQLPassThrough
Result of executing the SQL;

Error Message: [Microsoft][ODBC driver for Oracle][Oracle]ORA-06550: line 1, column 46:
PLS-00201: identifier 'CHECK_IND' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
ODBC--call failed.
[/color blue]

I think I carried out your suggestion - any more ideas ??


 
Well, yes, you did. I thought that you were sending LNGRETURN as a variable, and failing to isolate it from inside the string. Which of course you were, but as it turns out that isn't really the problem.

You do not assume correctly that QueryDef objects only apply to Access databases. They apply to any database that can provide data to an ODBC connection, and I'm pretty confident that Oracle is one of those. I would take a look at the link that vladk sent; it has an example of how to get data from the pubs database in SQL server. It shouldn't be too difficult to modify it for Oracle.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top