473,666 Members | 2,296 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using a PROCEDURE to EXECUTE other PROCEDUREs

[DB2/SUN 8.1.6]

I've been asked to time about forty PROCEDUREs in the database, and
keep a history of them for comaprison. So, i figured i'd quickly try it
in the database itself, so anyone could execute it easily. Here's the
basics:

CREATE TABLE Timings_Call
(
Id INTEGER GENERATED ALWAYS AS IDENTITY,
Group VARCHAR(0050),
Name VARCHAR(0050),
Text VARCHAR(0256)
)

CREATE TABLE Timings_Log
(
Id INTEGER GENERATED ALWAYS AS IDENTITY,
Call INTEGER,
Start TIMESTAMP,
Stop TIMESTAMP
)

In both cases, Id is the PK, and CALL is an FK.

Then tried this:

DROP PROCEDURE Test_Timings_Ca ll

CREATE PROCEDURE Test_Timings_Ca ll
(
OUT OUT_SQLCODE INTEGER,
OUT OUT_SQLSTATE CHAR(0005)
)
SPECIFIC Test_Timings_Ca ll
BEGIN

DECLARE SQLCODE INTEGER DEFAULT 0;
DECLARE SQLSTATE CHAR(0005) DEFAULT '00000';
DECLARE Start_Time TIMESTAMP;
DECLARE Stop_Time TIMESTAMP;

DECLARE CONTINUE HANDLER FOR
SQLEXCEPTION, SQLWARNING, NOT FOUND
BEGIN
SET OUT_SQLCODE = SQLCODE;
SET OUT_SQLSTATE = SQLSTATE;
END;

FOR Current_Call AS SELECT Id, Text FROM Timings_Call
DO

SET Start_Time = CURRENT TIMESTAMP;
EXECUTE IMMEDIATE Current_Call.Te xt;
SET Stop_Time = CURRENT TIMESTAMP;

INSERT INTO Timings_Log(Cal l, Start, Stop)
VALUES(Current_ Call.Id, Start_Time, Stop_Time);

END FOR;

IF OUT_SQLSTATE IS NULL THEN

SET OUT_SQLCODE = 0;
SET OUT_SQLSTATE = '00000';

END IF;

END

Using the CLP: CALL Test_Timings_Ca ll(?, ?)

The problem comes in when its done and i issue a COMMIT or CONNECT
RESET.

SQL0774N The statement cannot be executed within an ATOMIC compound
SQL

TERMINATE works.

The other issue is speed. I know they don't run this quickly, the
PROCEDURE even took a few minutes, yet:

db2 => SELECT * FROM Timings_log

ID CALL START STOP
----------- ----------- --------------------------
--------------------------
81 1 2006-02-01-13.23.16.773902
2006-02-01-13.23.36.204279
82 2 2006-02-01-13.23.36.207569
2006-02-01-13.24.16.037312
83 3 2006-02-01-13.24.16.038008
2006-02-01-13.24.16.196470
84 4 2006-02-01-13.24.16.196978
2006-02-01-13.24.16.452116
85 5 2006-02-01-13.24.16.452686
2006-02-01-13.24.19.762783
86 6 2006-02-01-13.24.19.763450
2006-02-01-13.24.24.302802
87 7 2006-02-01-13.24.24.303569
2006-02-01-13.24.27.670360
88 8 2006-02-01-13.24.27.671175
2006-02-01-13.24.32.166419
89 9 2006-02-01-13.24.32.167163
2006-02-01-13.24.34.127496
90 10 2006-02-01-13.24.34.128259
2006-02-01-13.24.41.198766
91 11 2006-02-01-13.24.41.199463
2006-02-01-13.24.41.213446
92 12 2006-02-01-13.24.41.213939
2006-02-01-13.24.41.217095
93 13 2006-02-01-13.24.41.217468
2006-02-01-13.24.41.254833
94 14 2006-02-01-13.24.41.255385
2006-02-01-13.24.41.282525
95 15 2006-02-01-13.24.41.283041
2006-02-01-13.24.41.286024
96 16 2006-02-01-13.24.41.286396
2006-02-01-13.24.44.756141
97 17 2006-02-01-13.24.44.756880
2006-02-01-13.24.44.757890
98 18 2006-02-01-13.24.44.758297
2006-02-01-13.24.51.798671
99 19 2006-02-01-13.24.51.799408
2006-02-01-13.24.55.223971
100 20 2006-02-01-13.24.55.224786
2006-02-01-13.24.58.821576
101 21 2006-02-01-13.24.58.822333
2006-02-01-13.24.58.842636
102 22 2006-02-01-13.24.58.844363
2006-02-01-13.24.58.866712
103 23 2006-02-01-13.24.58.867420
2006-02-01-13.24.58.893308
104 24 2006-02-01-13.24.58.894157
2006-02-01-13.24.58.911025
105 25 2006-02-01-13.24.58.911564
2006-02-01-13.24.59.689057
106 26 2006-02-01-13.24.59.689840
2006-02-01-13.24.59.711142
120 40 2006-02-01-13.24.59.799941
2006-02-01-13.24.59.806985

This is just odd.

B.

Feb 1 '06 #1
2 5252
I think i figured out the main part of the problem. Many of the
PROCEDUREs DECLARE a GLOBAL TEMPORARY TABLE, and by default i named the
first one Temp_1, and incrementing as required. They are just
intermediate steps, so i figured a better name would probably just be
more confusing.

Being the CURSORs are DECALREd WITH RETURN TO CLIENT, it is holding a
lock on the TABLE, and when the next PROCEDURE tries to DECLARE it with
the same name (WITH REPLACE), it causes an error that i am trying to
DROP a TABLE that is still needed.

As simple example:

DROP PROCEDURE AA
CREATE PROCEDURE AA()
BEGIN
DECLARE GLOBAL TEMPORARY TABLE A(A INT) NOT LOGGED WITH REPLACE;
BEGIN
DECLARE A CURSOR WITH RETURN TO CLIENT FOR SELECT * FROM SESSION.A;
OPEN A;
END;
END

DROP PROCEDURE BB
CREATE PROCEDURE BB() BEGIN CALL AA; CALL AA; END

CALL BB

DROP PROCEDURE AA
DROP PROCEDURE BB
COMMIT

results in

SQL0910N The SQL statement cannot access an object on which a
modification is pending. SQLSTATE=57007

Which is understandable.

Without renaming all the objects, is there a way to test this?

B.

Feb 2 '06 #2
OK, got it to work. Changed the PROCEDURE to execute one comamnd at a
time, and used the shell.

DROP PROCEDURE Test_Timings_Ca ll

CREATE PROCEDURE Test_Timings_Ca ll(IN_Id INT)
SPECIFIC Test_Timings_Ca ll
BEGIN

DECLARE Start_Time TIMESTAMP;
DECLARE Stop_Time TIMESTAMP;
DECLARE Query VARCHAR(256);

SELECT Text INTO Query FROM Timings_Call
WHERE Timings_Call.Id = IN_Id;

SET Start_Time = CURRENT TIMESTAMP;
EXECUTE IMMEDIATE Query;
SET Stop_Time = CURRENT TIMESTAMP;

INSERT INTO Timings_Log(Cal l, Start, Stop)
VALUES(IN_Id, Start_Time, Stop_Time);

END

eval "$(db2 -x "SELECT 'db2 +o \"CALL Test_Timings_Ca ll(' || CHAR(Id)
|| ')\"' FROM Timings_Call")"

B.

Feb 3 '06 #3

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

Similar topics

10
2306
by: Dragonhunter | last post by:
Hello, The aspfaq.com seems to really push stored procedures, and I hear the same advice here all the time. So I want to take the advice. Is it possible to create and practically maintain, delete, use, etc.. stored procedures soley from asp (i.e., no GUI or console- like being hosted on Brinkster)? The tutorial on aspfaq.com mentions that stored procedures can be
2
7319
by: Yves Touze | last post by:
Hi All, I'm trying to migrate from SQL Server 7.0 to SQL Server 2000. I've got some ASP page which call VB components that retrieve shaped recordsets from SQL Server using the MSDATASHAPE provider. Precisely, here is the code i have Dim Cmdobj As New ADODB.Command Cmdobj.ActiveConnection = oconn Cmdobj.CommandType = adCmdStoredProc
2
9218
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered problems doing this. I wanted to implemented a generic "Helper" class like this: /** * Helper
0
2573
by: billmiami2 | last post by:
Perhaps many of you MS Access fanatics already know this, but it seems that stored procedures and views are possible in Jet. I thought I would leave this message just in case it would help anyone. I discovered this the other day while doing some experiments with ADO and ADO.NET. Basically, I wanted to run a stored MS Access query with parameters using the syntax Execute MyProcedure @Param1, @Param2...
2
3327
by: Eli | last post by:
Hi all We currently have a strange problem with calling a Stored Procedure (SQL Database) in our C# Project. The only error I get is "System error" which says a lot :) Background: We have several stored procedures to Insert and update datas in our SQL database. Some stored procedures are smaller (insert datas in only one table) and some of them are quite big (insert datas in several
0
2642
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how to call them from an ASP.Net page Every modern database system has a stored procedure language. SQL Server is no different and has a relatively sophisticated and easy to use system. This article will not attempt to go into depth in explaining...
0
1495
by: jer006 | last post by:
Hi, This is more of a general question... I have a series of stored procedures (chain of procedures) in db2 on an AS400 which are executed from a SQL Server Job, when I execute the job manually during the day (or when I execute the stored procedures in db2 on the AS400 directly) everything completes successfully. However when the procedures are executed on its scheduled cycle at 3am in the morning it fails most every morning with a...
2
4079
by: acw | last post by:
On a SQL Server 2000 db I would like to setup a stored procedure that accesses couple tables and runs the extended stored procedure xp..cmdshell. The goal is to grant users with limited privileges the right to run the stored procedure but not the rights to directly access either the referenced tables or the extended stored procedure. TIA!
3
4142
by: gopi2ks | last post by:
Dear All, I have one stored procedure like sp_insertEmployee Employee Table Fileds Eno int pk, ename varchar(100), designation varchar
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.