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

pass an recordset to a procedure

Hello!

I am migrating from PostgreSQL to DB2 and now I've got a problem with a
Stored Procedure. In PG it is possible to pass SQL Results to a
Procedure but how to do this in DB2? The online Doku only explains the
"normal" Datatypes such as int, real, ...

The procedure call should look like:
call myprocedure((select nr from street where ...));

Can Anyone hlep??

Thanks
Christian Meier

Nov 12 '05 #1
8 1834
nsd
Hi,
The following code may help u..
db2 describe table t_street
--------------------------------------------------------------------------------
Column Type Type
name schema name Length
Scale Nulls

------------------------------ --------- ------------------ --------
----- -----
-
SNO SYSIBM INTEGER 4
0 Yes

ADD1 SYSIBM VARCHAR 20
0 Yes
2 record(s) selected.

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

----------------------------------------------------------------------------------------------------
CALLER
---------------------------------------------------------------------------------------------------
CREATE PROCEDURE proc_main()
LANGUAGE SQL
SPECIFIC mainprocedure
LOOP:
BEGIN
DECLARE v_sno integer default 1;
DECLARE v_stmt VARCHAR(100);
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE v_sql STATEMENT;
DECLARE cur_slctfrmstrt CURSOR FOR SELECT sno FROM t_street;
OPEN cur_slctfrmstrt;
WHILE(SQLSTATE = '000000') DO
FETCH cur_slctfrmstrt INTO v_sno;
SET v_stmt = 'CALL myprocedure(?)';
PREPARE v_sql from v_stmt;
EXECUTE v_sql USING v_sno;
CLOSE cur_slctfrmstrt;
END WHILE;
END LOOP

DB20000I The SQL command completed successfully.
------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
CALLED
--------------------------------------------------------------------------------------------
CREATE PROCEDURE myprocedure(IN a_sno INTEGER)
LANGUAGE SQL
SPECIFIC myprocedure
BEGIN
DECLARE v_sno integer default 0;
SET v_sno = a_sno;
end

DB20000I The SQL command completed successfully.
-------------------------------------------------------------------------------------------------

db2 call proc_main()
Return Status = 0

Regards,
nsd

Nov 12 '05 #2
OK, I see ...

i have to correct my positing -> it's a function not a procedure (its
diffrent in DB2) - my mistake! sorry!

Ok, problem is, that the function returns simple out of passed arrays.
such as a weighted arverage. i pass an array to the function an get a
weighted average of the arrays data. i have a lot of those functions
and a lot of uses (thats why i change to db2). if your way is the only
way, i have to develop n caller-functions and it's unpossible to pass
dynamic data, i had to create a caller first for each query.

is there any other/easier way? i tried user difined data types - but
the compiler sais that he don't want to operate with user defined types
like mine (not distinct).

Nov 12 '05 #3
to*******@freesurf.fr wrote:
OK, I see ...

i have to correct my positing -> it's a function not a procedure (its
diffrent in DB2) - my mistake! sorry!

Ok, problem is, that the function returns simple out of passed arrays.
such as a weighted arverage. i pass an array to the function an get a
weighted average of the arrays data. i have a lot of those functions
and a lot of uses (thats why i change to db2). if your way is the only
way, i have to develop n caller-functions and it's unpossible to pass
dynamic data, i had to create a caller first for each query.

is there any other/easier way? i tried user difined data types - but
the compiler sais that he don't want to operate with user defined types
like mine (not distinct).


If I got this right, you want to implement your own aggregate function (aka
column function). Have a look here for some ideas:
http://www.ibm.com/developerworks/db...309stolze.html

http://www-106.ibm.com/developerwork...lze/index.html

--
Knut Stolze
Information Integration Development
IBM Germany / University of Jena
Nov 12 '05 #4
yes but rolling aggregate functions instead of sum over the whole
column i need functions with sum of the last tree - for example.
To do this I pass subqueries with a fetch first n rows only statement.

ok read your links and as far as good, now one last question.

i have
create type mine as (i double) with funktion access mdode db2sql;
--> query OK

then i have
create testfunc(test mine) returns double
language sql
begin atomic
return 1.3; -- just to do something
end
--> Query OK

then i have
select testfunc(mine()..((select nr from street))) from street;

-> Query OK, But the result ist 1.3 as defined(!)

Question now is, how to access values of test with datatype mine() ??
I tried some queries kinds like select i from test()

thank you!!

Christian

Nov 12 '05 #5
to*******@freesurf.fr wrote:
yes but rolling aggregate functions instead of sum over the whole
column i need functions with sum of the last tree - for example.
That raises immediately the question "what are the last three"? After all,
SQL is set-oriented and there is no order within a set. So there are no
"last three" rows. (Granted, you could use an ORDER BY somewhere to
enforce a certain order.)
ok read your links and as far as good, now one last question.

i have
create type mine as (i double) with funktion access mdode db2sql;
--> query OK
Which query?
then i have
create testfunc(test mine) returns double
language sql
begin atomic
return 1.3; -- just to do something
end
--> Query OK
testfunc() gets a single value of type "mine" as input parameter, processes
it and returns a single value of type "double" as output parameter.
then i have
select testfunc(mine()..((select nr from street))) from street;

-> Query OK, But the result ist 1.3 as defined(!)
I doubt that the query runs ok because it isn't even syntactically correct.

What did you actually expect to happen?

Also, the query did only work because you have at most 1 row in your table
"street", correct? Otherwise you run into the following case:

A value of type "mine" is constructed and its attribute "i" (a scalar value)
is modified/mutated. So whatever you want to set "i" to must be a scalar
value, which implies that your subselect must be a scalar subselect (only
one row, one column --> one value).

Btw, you could probably simplify the above query to:

SELECT testfunc(mine()..i(nr)) FROM street
Question now is, how to access values of test with datatype mine() ??
I tried some queries kinds like select i from test()


What should that do? "testfunc()" (I assume that's the same as "test()" is
a function that returns a scalar value - not a table - of type "double".
You should have a look at table functions if your function is to return
something more complex.

--
Knut Stolze
Information Integration Development
IBM Germany / University of Jena
Nov 12 '05 #6
yes the thing is, that the input variable contains more than one row,
but returns a single value. table functions are retunring tables thats
not that what i need. I need somithing like sum, avg, min,max, ...

how can i do this?

THX!
Christian

Nov 12 '05 #7
to*******@freesurf.fr wrote:
yes the thing is, that the input variable contains more than one row,
but returns a single value. table functions are retunring tables thats
not that what i need. I need somithing like sum, avg, min,max, ...

how can i do this?


As I said before, you want to have user-defined aggregates (multiple
rows/values in, single row/value out). There is no native support in DB2
for that kind of feature yet. But the links I provided in the other post
show you a way to achieve what you want.

--
Knut Stolze
Information Integration Development
IBM Germany / University of Jena
Nov 12 '05 #8
I see ...
So I do have some Java Code ..

Thanks!!!

Christian

Nov 12 '05 #9

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

Similar topics

5
by: Bruno Alexandre | last post by:
Hi guys, withou using SP, I want to be able to add a Parameter to the SQL Query and retrive the Recordset so I can use the Paging property under the recorset object.... how can I do this? I'm...
2
by: djharrison | last post by:
Greetings, I was wondering if anyone could help me with a project involving MS Acces as a front-end to an SQL Server 2000 database. I am running a program that currently populates the Access...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
3
by: ILCSP | last post by:
Hello, I'm fairly new to the concept of running action pass through queries (insert, update, etc.) from Access 2000. I have a SQL Server 2000 database and I'm using a Access 2K database as my...
12
by: Scott | last post by:
Front-end Access 2000 I have a stored procedure that has 2 parameters BusinessUnitID and Year. It returns multiple record sets (5 to be exact). I thought I could use a Pass through query but...
3
by: Joseph Lu | last post by:
Hi, all I have a stored procedure created in SQL Server like the following lines. // stored proceudre code starts here CREATE PROCEDURE sp_insertdata @strdata varchar(250) , @rsult BIT...
2
by: Jim M | last post by:
I rarely deal with recordsets directly with code, since I usually use Access queries, so be patient with this question. I want to open a recordset with various default variables used by my program....
1
by: tjjones70 | last post by:
I am trying to load list boxes from an Access database. I'm looking at 3 tables and for each table I'm loading a list box that has current information and another list box that has expired...
0
by: cephal0n | last post by:
Hi All! I have two table tblHome1, contains all the unique PinNo and tblHome2 contains a duplicated PinNo and description. I put an automatic numbering (ProdID) and set it as my index. What I want...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...

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.