473,467 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

GET DIAGNOSTICS statement....

Hi,

I am trying to use GET DIAGNOSTICS statement after an INSERT. DB2
does not return the # of rows inserted. Below is the code and output.

----Code snippet

DROP PROCEDURE DIAG_CHECK @

CREATE PROCEDURE DIAG_CHECK ()
LANGUAGE SQL
BEGIN

DECLARE v_tmp_var CHAR(10);
DECLARE v_temp_SQLCODE INT DEFAULT 0;
DECLARE v_temp_SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE SQLCODE INT;

DECLARE v_row_inserted INT;

DECLARE CONTINUE HANDLER FOR SQLWARNING,NOT FOUND
BEGIN NOT ATOMIC
SET v_tmp_var = SQLSTATE|| CAST(SQLCODE AS CHAR(5));
SET v_temp_SQLSTATE = SUBSTR(v_tmp_var, 1, 5);
SET v_temp_SQLCODE = INT(SUBSTR(v_tmp_var, 6, 5));
END;

DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN NOT ATOMIC
SET v_tmp_var = SQLSTATE|| CAST(SQLCODE AS CHAR(5));
SET v_temp_SQLSTATE = SUBSTR(v_tmp_var, 1, 5);
SET v_temp_SQLCODE = INT(SUBSTR(v_tmp_var, 6, 5));
RESIGNAL;
END;

SET v_row_inserted = 0;

INSERT INTO DBUG VALUES ( MICROSECOND( CURRENT TIMESTAMP), 'New row
inserted' );

GET DIAGNOSTICS v_row_inserted = ROW_COUNT;

INSERT INTO DBUG_CHK VALUES ( v_row_inserted, '# rows inserted' );

COMMIT;
END
@
---------Output:

from dbug table

ROW_ID DESC
-------- -------------------
328826 New row inserted
from dbug_chk

NROWS DESC
----------- -------------------------
0 # rows inserted

Please let me know the mistake.

Thanks in advance,

Dev
Nov 12 '05 #1
2 4833
One thought:
Could be you fall into one of the handlers whcih wipe out the row_count.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #2
Serge Rielau <sr*****@ca.eye-bee-m.com> wrote in message news:<bp**********@hanover.torolab.ibm.com>...
One thought:
Could be you fall into one of the handlers whcih wipe out the row_count.

Cheers
Serge


Nopes, tried commenting handlers and ran but in vain... and below is the output.

added below in addition to the exisiting procedure

--------------------------------------------------------
INSERT INTO DBUG
SELECT MICROSECOND( CURRENT TIMESTAMP ), 'From select' FROM SYSIBM.SYSDUMMY1;

GET DIAGNOSTICS v_row_inserted = ROW_COUNT;

INSERT INTO DBUG_CHK VALUES ( v_row_inserted, '# rows from select' );

----------------------------------------------------

Output :

select * from dbug_chk

NROWS DESC
----------- -------------------------
0 # rows inserted
1 # rows from select

Thanks,
Dev
Nov 12 '05 #3

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

Similar topics

3
by: Rhino | last post by:
I just stumbled on something odd but I'm not sure if it's a bug in DB2 or something that is "working as designed." I have a simple SQL PL stored procedure which is doing an "INSERT SELECT..."...
2
by: cody | last post by:
System.Diagnostics.Debug.Assert(); Hello??? A language should encourage programmers to heavily use the assert-feature, since it improves safety, stability, readability and maintainability of...
2
by: Michael Johnson Sr. | last post by:
I am trying to view a list of running processes using ASP.NET with C#, I found System.Diagnostics.Process which seems to work good with IIS 5 and XP, when I move the application to Windows 2000...
4
by: Jiho Han | last post by:
I have the following defined in web.config under <configuration> node: <system.diagnostics> <switches> <add name="MainSwitch" value="4"/> </switches>
1
by: Patrick | last post by:
When Tracing in ASP.NET, the IIS process (on IIs5.1) is locking on the Trace file, and I can't read the trace file without restarting the IIS: Even the following does NOT work (how could I fix...
5
by: John A Grandy | last post by:
how to use System.Diagnostics.Debug.WriteLine to write directly to a window viewable during debug mode (similar to Debug.Print in VB6)
2
by: XxLicherxX | last post by:
Hello, I tried posting this in a different VB.net newsgroup, but never got a response. Please let me know if there is a better group to post this in. Thanks. For some reason I cannot look at...
5
by: Praveen_db2 | last post by:
Hi All db2 8.1.3 Windows I have folowing table structures CREATE TABLE tb_RTB( EMP_ID INTEGER, DESC VARCHAR(20)); CREATE TABLE tb_ERROR( SQL_STATE CHAR(5), SQL_DESC VARCHAR(20),
0
by: jammendolia | last post by:
Hello all, I am having an intermittent exception occur when writing the the eventlog from a windows service application written in c#, running on a Win2k SP4 server. Here's the code: ...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.