472,958 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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_scripts
(
time_now INTEGER,
timeout INTEGER
)
language sql
dynamic result sets 1
Begin
DECLARE uut_disconnected_script_id BIGINT;
DECLARE uut_timed_out_id 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_id as test_script_id
FROM
test_script s,
pcd_system_scripts sk
WHERE
s.test_script_id != 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_times st,
pcd_system_scripts 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_id AND
(time_now - st.last_access_time) > timeout ;
/*call procedures to get values in the variable */
call get_test_result_id('UUT_DISCONNECTED_SCRIPT',
uut_disconnected_script_id);
call get_test_result_id('UUT_TIMED_OUT', uut_timed_out_id);

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_id as test_script_id
FROM
test_script s,
pcd_system_scripts sk
WHERE
s.test_script_id != 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_times st,
pcd_system_scripts 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_id 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 13550
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_scripts
(
time_now INTEGER,
timeout INTEGER
)
language sql
dynamic result sets 1
Begin
DECLARE uut_disconnected_script_id BIGINT;
DECLARE uut_timed_out_id 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_id as test_script_id
FROM
test_script s,
pcd_system_scripts sk
WHERE
s.test_script_id != 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_times st,
pcd_system_scripts 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_id AND
(time_now - st.last_access_time) > timeout ;
/*call procedures to get values in the variable */
call get_test_result_id('UUT_DISCONNECTED_SCRIPT',
uut_disconnected_script_id);
call get_test_result_id('UUT_TIMED_OUT', uut_timed_out_id);

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_id as test_script_id
FROM
test_script s,
pcd_system_scripts sk
WHERE
s.test_script_id != 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_times st,
pcd_system_scripts 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_id 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
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...
5
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...
1
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...
2
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. ...
2
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...
22
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...
5
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...
1
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...
1
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')"); ...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.