473,721 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fetching data from db2 using stored procedure


Hi,

I am trying to fetch data from db2 (express version) database by
calling stored procedure. I have tried to use both cursor and for loop
but still i am getting error.

--======Start procedure====== =======

Create PROCEDURE get_timedout_sc ripts
(
time_now INTEGER,
timeout INTEGER
)
language sql
dynamic result sets 1
Begin
DECLARE uut_disconnecte d_script_id BIGINT;
DECLARE uut_timed_out_i d BIGINT;
DECLARE system_id BIGINT;
DECLARE test_script_id BIGINT;
DECLARE status VARCHAR(24);
Declare c1 cursor for
SELECT
sk.system_id,
s.test_script_i d as test_script_id
FROM
test_script s,
pcd_system_scri pts sk
WHERE
s.test_script_i d != sk.test_script_ id AND
NOT sk.test_script_ id IS NULL AND
s.system_id = sk.system_id AND
s.is_running = 'Y';

Declare c2 cursor for
SELECT
ts.system_id,
sc.test_script_ id
FROM
pcd_system_time s st,
pcd_system_scri pts sc,
test_script ts
WHERE
NOT sc.test_script_ id IS NULL AND
ts.test_script_ id = sc.test_script_ id AND
sc.system_id = st.system_id AND
NOT ts.result_id = uut_timed_out_i d AND
(time_now - st.last_access_ time) > timeout ;
/*call procedures to get values in the variable */
call get_test_result _id('UUT_DISCON NECTED_SCRIPT',
uut_disconnecte d_script_id);
call get_test_result _id('UUT_TIMED_ OUT', uut_timed_out_i d);

Open c1;

fetch c1 into system_id, test_script_id;
set status = 'disconnected';
close c1;

open c2;

fetch c2 into system_id, test_script_id;
set status = 'timedout';

close c2;
/*
FOR t1 as
SELECT
sk.system_id,
s.test_script_i d as test_script_id
FROM
test_script s,
pcd_system_scri pts sk
WHERE
s.test_script_i d != sk.test_script_ id AND
NOT sk.test_script_ id IS NULL AND
s.system_id = sk.system_id AND
s.is_running = 'Y'
DO
BEGIN
set system_id = system_id;
set test_script_id = test_script_id;
set status = 'disconnected';
END;
END FOR;
*/
/*
FOR t2 as
SELECT
ts.system_id,
sc.test_script_ id
FROM
pcd_system_time s st,
pcd_system_scri pts sc,
test_script ts
WHERE
NOT sc.test_script_ id IS NULL AND
ts.test_script_ id = sc.test_script_ id AND
sc.system_id = st.system_id AND
NOT ts.result_id = uut_timed_out_i d AND
(time_now - st.last_access_ time) > timeout
DO
BEGIN
set system_id = system_id;
set test_script_id = test_script_id;
set status = 'timedout';
END;
END FOR;
*/
END@
--=====End of procedure

I am getting following error
-------------------------------

SQLSTATE[21000]: Cardinality violation: -811 [IBM][CLI Driver][DB2/NT]
SQL0811N The result of a scalar fullselect, SELECT INTO statement, or
VALUES INTO statement is more than one row. SQLSTATE=21000\ r [Thu May
25 12:05:37 2006] [error] [client 127.0.0.1] (SQLExecute[-811] at
ext\\pdo_odbc\\ odbc_stmt.c:133 )'
I have few questions regarding the same. i am new in db2 and porting my
existing database (firebird) to db2.

1) Is it good to have procedure for repeated select statements?

2) Difference between fetching multiple rows of data using for and
cursor. In my case both of them are giving errors.

Any help to fix above problem will be appreciated.

Thanks!
Regards,
--
deepdata
------------------------------------------------------------------------
deepdata's Profile: http://www.dbtalk.net/m335
View this thread: http://www.dbtalk.net/t309363

May 25 '06 #1
1 13667
Hi,
I dont think this particular error came from stored procedure.May be
remove all the other SQL and just call the stored procedure.
If the stored procedure is supposed to return a result set, then its
wrong. As the stored proced cursor declaration should have WITH RETURN
FOR clause .And you jsut need to open the cursor, not need for the
fetch statement.
1) Is it good to have procedure for repeated select statements?
Its good to have stored procedure when you have the results of one sql
statement being used as input to another and if something like that is
done in client it increases network traffic. You can go for stored
procedures or perpared sql statement if you executing same sql many
times.

2) Difference between fetching multiple rows of data using for and
cursor.
FOR internally opens a cursor is what I belieave.

Did you try running the same procedure from the command line ?


deepdata wrote:
Hi,

I am trying to fetch data from db2 (express version) database by
calling stored procedure. I have tried to use both cursor and for loop
but still i am getting error.

--======Start procedure====== =======

Create PROCEDURE get_timedout_sc ripts
(
time_now INTEGER,
timeout INTEGER
)
language sql
dynamic result sets 1
Begin
DECLARE uut_disconnecte d_script_id BIGINT;
DECLARE uut_timed_out_i d BIGINT;
DECLARE system_id BIGINT;
DECLARE test_script_id BIGINT;
DECLARE status VARCHAR(24);
Declare c1 cursor for
SELECT
sk.system_id,
s.test_script_i d as test_script_id
FROM
test_script s,
pcd_system_scri pts sk
WHERE
s.test_script_i d != sk.test_script_ id AND
NOT sk.test_script_ id IS NULL AND
s.system_id = sk.system_id AND
s.is_running = 'Y';

Declare c2 cursor for
SELECT
ts.system_id,
sc.test_script_ id
FROM
pcd_system_time s st,
pcd_system_scri pts sc,
test_script ts
WHERE
NOT sc.test_script_ id IS NULL AND
ts.test_script_ id = sc.test_script_ id AND
sc.system_id = st.system_id AND
NOT ts.result_id = uut_timed_out_i d AND
(time_now - st.last_access_ time) > timeout ;
/*call procedures to get values in the variable */
call get_test_result _id('UUT_DISCON NECTED_SCRIPT',
uut_disconnecte d_script_id);
call get_test_result _id('UUT_TIMED_ OUT', uut_timed_out_i d);

Open c1;

fetch c1 into system_id, test_script_id;
set status = 'disconnected';
close c1;

open c2;

fetch c2 into system_id, test_script_id;
set status = 'timedout';

close c2;
/*
FOR t1 as
SELECT
sk.system_id,
s.test_script_i d as test_script_id
FROM
test_script s,
pcd_system_scri pts sk
WHERE
s.test_script_i d != sk.test_script_ id AND
NOT sk.test_script_ id IS NULL AND
s.system_id = sk.system_id AND
s.is_running = 'Y'
DO
BEGIN
set system_id = system_id;
set test_script_id = test_script_id;
set status = 'disconnected';
END;
END FOR;
*/
/*
FOR t2 as
SELECT
ts.system_id,
sc.test_script_ id
FROM
pcd_system_time s st,
pcd_system_scri pts sc,
test_script ts
WHERE
NOT sc.test_script_ id IS NULL AND
ts.test_script_ id = sc.test_script_ id AND
sc.system_id = st.system_id AND
NOT ts.result_id = uut_timed_out_i d AND
(time_now - st.last_access_ time) > timeout
DO
BEGIN
set system_id = system_id;
set test_script_id = test_script_id;
set status = 'timedout';
END;
END FOR;
*/
END@
--=====End of procedure

I am getting following error
-------------------------------

SQLSTATE[21000]: Cardinality violation: -811 [IBM][CLI Driver][DB2/NT]
SQL0811N The result of a scalar fullselect, SELECT INTO statement, or
VALUES INTO statement is more than one row. SQLSTATE=21000\ r [Thu May
25 12:05:37 2006] [error] [client 127.0.0.1] (SQLExecute[-811] at
ext\\pdo_odbc\\ odbc_stmt.c:133 )'
I have few questions regarding the same. i am new in db2 and porting my
existing database (firebird) to db2.

1) Is it good to have procedure for repeated select statements?

2) Difference between fetching multiple rows of data using for and
cursor. In my case both of them are giving errors.

Any help to fix above problem will be appreciated.

Thanks!
Regards,
--
deepdata
------------------------------------------------------------------------
deepdata's Profile: http://www.dbtalk.net/m335
View this thread: http://www.dbtalk.net/t309363


May 26 '06 #2

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

Similar topics

0
5406
by: sedefo | last post by:
I ran into this Microsoft Patterns & Practices Enterprise Library while i was researching how i can write a database independent data access layer. In my company we already use Data Access Application Block (DAAB) in our .Net projects. We use SqlHelper in SQL based projects, and OracleHelper in Oracle based ones. OracleHelper was not published officially by Microsoft as part of the DAAB but it was given as a helper code in a sample .Net...
5
2502
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to have a separate data adapter & a separate data set for each select query? If thats possible then how?
1
2316
by: kjphipps_377 | last post by:
Hi all! I have an application that needs to copy the database structure from one database to another without using the "Generate SQL Script" function in Enterprise Manager. I'd like to do this from within a stored procedure. Can someone recommend the best approach for this? I've seen references to using SQL-DMO from a stored procedure using the sp_OA* procs in other postings to this group but was wondering if there was an easier way?...
2
11707
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. tCetecM1CUST (SQL Table that contains the Customer Information) tAccountingDetail (SQL Table that contains the information in the form) frmAccountingEntry (Access form used to enter data) spGetCustomerInformation (Stored Procedure which returns data using...
2
5193
by: yatharth | last post by:
Hi Mike I have Datagrid and i am fetching data around about 1 million into it , i think which is not good deal this makes my system slow.Please tell the way so that i can fetch data in my dataset or else so that i dont have to fetch such a large data again and again. My datagrid alows paging.
22
2724
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other things. So, in instances where I list, for example, the latest weblogs. I list the headline of the weblog, the date and the name of the member who wrote it. Now, the name isn't just "Smith", but rather Smith's online status, his nick and his...
5
2989
by: Bhavesh | last post by:
Hello genious people, I m trying to insert a LARGE text from Multiline Textbox into my table of sqlserver2000. I m using vs-2005. Please note that I dont want to store blob data From FILE TO TABLE, like storing IMAGE into DB.
1
1817
by: Bhavesh | last post by:
Hi Bruce, Thanks For Reply. U were right, Needed to pass string , but also need to pass size of Data( instead of 16, passed actual length of data). So that worked for me & didn't get any error. But now problem in fetching, not able to fetch data from table correctly. Here is my code. I hav following problems with this coding
1
3081
by: Frank Moyles | last post by:
I have two simple function in PHP that I want to convert to C# - function Doit($enc_user_name, $enc_password) { $result = $mysqli->query("call sp_userAuth('$enc_user_name','$enc_password')"); if (mysqli_num_rows($result) != 0) { $data = $result->fetch_array(MYSQLI_BOTH);
0
8840
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
9367
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9215
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...
0
9064
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...
0
8007
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6669
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
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
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 we have to send another system

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.