473,385 Members | 1,356 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,385 software developers and data experts.

Recursive stored proc call

I have a database I have inherited (new job). I am trying to baseline
the code and have done a DB2Look to get the code out of an existing
db. The DB2Look produced a SP with the following form:

Create SP1

(various code)

call sp1()

(various code)
end

This code will not compile because of the procedure is calling itself,
but the procedure does not yet exist so it cannot resolve the code.
Since this is currently in a working database I assume that it got
compiled, somehow. I've not run across this before and am stumped.
Is there some trick to getting a recursive call to compile?

thanks

Jack

Feb 2 '07 #1
3 3152
On Feb 2, 9:20 am, oregon...@yahoo.com wrote:
I have a database I have inherited (new job). I am trying to baseline
the code and have done a DB2Look to get the code out of an existing
db. The DB2Look produced a SP with the following form:

Create SP1

(various code)

call sp1()

(various code)
end

This code will not compile because of the procedure is calling itself,
but the procedure does not yet exist so it cannot resolve the code.
Since this is currently in a working database I assume that it got
compiled, somehow. I've not run across this before and am stumped.
Is there some trick to getting a recursive call to compile?

thanks

Jack
Hi, Jack:

Recursive SQL procedures are possible, but there's one thing you need
to do a little differently--precisely because of what you've bumped up
against--which is to make the call in dynamic SQL. The procession is
like so:

CREATE SP1()
*various and sundry declarations*
DECLARE v_SP_Call VARCHAR(100) DEFAULT 'CALL SP1()';--
*various and sundry code*
EXECUTE IMMEDIATE v_SP_Call;--
*various and sundry code*
END;

As to how it got compiled before, I'm stumped (if not skeptical), but
the way described here will work.

HTH,

--Jeff

Feb 2 '07 #2
On Feb 2, 10:14 am, "jefftyzzer" <jefftyz...@sbcglobal.netwrote:
On Feb 2, 9:20 am, oregon...@yahoo.com wrote:


I have a database I have inherited (new job). I am trying to baseline
the code and have done a DB2Look to get the code out of an existing
db. The DB2Look produced a SP with the following form:
Create SP1
(various code)
call sp1()
(various code)
end
This code will not compile because of the procedure is calling itself,
but the procedure does not yet exist so it cannot resolve the code.
Since this is currently in a working database I assume that it got
compiled, somehow. I've not run across this before and am stumped.
Is there some trick to getting a recursive call to compile?
thanks
Jack

Hi, Jack:

Recursive SQL procedures are possible, but there's one thing you need
to do a little differently--precisely because of what you've bumped up
against--which is to make the call in dynamic SQL. The procession is
like so:

CREATE SP1()
*various and sundry declarations*
DECLARE v_SP_Call VARCHAR(100) DEFAULT 'CALL SP1()';--
*various and sundry code*
EXECUTE IMMEDIATE v_SP_Call;--
*various and sundry code*
END;

As to how it got compiled before, I'm stumped (if not skeptical), but
the way described here will work.

HTH,

--Jeff- Hide quoted text -

- Show quoted text -
May I hasten add, for the benefit of hair-splitters everywhere, that
the "v_SP_Call" variable doesn't necessarily need to be 100. Please
size appropriately for the real name (and possibly fully qualified
path) of the SP.

:-)

--Jeff

Feb 2 '07 #3
I think I did this a long time ago by building a dummy procedure that
didn't have the recursive call as a "seed" to allow the real procedure
to compile.

Phil Sherman
or*******@yahoo.com wrote:
I have a database I have inherited (new job). I am trying to baseline
the code and have done a DB2Look to get the code out of an existing
db. The DB2Look produced a SP with the following form:

Create SP1

(various code)

call sp1()

(various code)
end

This code will not compile because of the procedure is calling itself,
but the procedure does not yet exist so it cannot resolve the code.
Since this is currently in a working database I assume that it got
compiled, somehow. I've not run across this before and am stumped.
Is there some trick to getting a recursive call to compile?

thanks

Jack
Feb 3 '07 #4

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

Similar topics

3
by: Robert Song | last post by:
Hi all I am implementing a stored procedure which needs to recursively call itself until specific condition is reached, Could anyone give some advice about that? Thanks a lot Robert Song
2
by: xAvailx | last post by:
I have a requirement that requires detection of rows deleted/updated by other processes. My business objects call stored procedures to create, read, update, delete data in a SQL Server 2000 data...
0
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE...
14
by: Roy | last post by:
Apologies for the cross-post, but this truly is a two-sided question. Given the option of creating Looping statements within a stored proc of sql server or in the code-behind of an .net webpage,...
45
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
3
by: mandible | last post by:
I'm trying to call one stored procedure inside another. I was wondering if this is possible Some ideas I was toying with is putting the first stored procedure inside of a temp table but haven't...
0
by: ravindrag | last post by:
Hi, I am getting error SQL1131N during sqlj.install_jar(...). There is no useful message in the diag.log (even with diag level 4). I am giving the diag.log entries at the end of this posting...
0
by: mirandacascade | last post by:
Questions toward the bottom of the post. Situation is this: 1) Access 97 2) SQL Server 2000 3) The Access app: a) sets up pass-thru query b) .SQL property of querydef is a string, the...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.