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

Function invocation

Hi,

I created a function, but I don't know to call this function.

CREATE FUNCTION NAMEEMPLOYEE (DEPTO CHAR(3))
RETURNS TABLE (EMPID INTEGER, NAME VARCHAR(60), PHONE CHAR(8))
LANGUAGE SQL
READS SQL DATA
NO EXTERNAL ACTION
DETERMINISTIC
RETURN
SELECT EMPID, NAME, PHONE
FROM BEST.EMPLOYEES
WHERE DEPTO = BEST.DEPTO

Is my function correct?
I'm running DB2 7.1.

Thanks

Anderson Borges.

May 3 '07 #1
7 1906
Ian
Aborges wrote:
Hi,

I created a function, but I don't know to call this function.

CREATE FUNCTION NAMEEMPLOYEE (DEPTO CHAR(3))
RETURNS TABLE (EMPID INTEGER, NAME VARCHAR(60), PHONE CHAR(8))
LANGUAGE SQL
READS SQL DATA
NO EXTERNAL ACTION
DETERMINISTIC
RETURN
SELECT EMPID, NAME, PHONE
FROM BEST.EMPLOYEES
WHERE DEPTO = BEST.DEPTO

Is my function correct?
I'm running DB2 7.1.
You don't say what platform you are on, but typically the
call would look like:

select * from table(nameemployee('D00')) as x

May 3 '07 #2
Ian wrote:
Aborges wrote:
>Hi,

I created a function, but I don't know to call this function.

CREATE FUNCTION NAMEEMPLOYEE (DEPTO CHAR(3))
RETURNS TABLE (EMPID INTEGER, NAME VARCHAR(60), PHONE CHAR(8))
LANGUAGE SQL
READS SQL DATA
NO EXTERNAL ACTION
DETERMINISTIC
RETURN
SELECT EMPID, NAME, PHONE
FROM BEST.EMPLOYEES
WHERE DEPTO = BEST.DEPTO

Is my function correct?
I'm running DB2 7.1.

You don't say what platform you are on, but typically the
call would look like:

select * from table(nameemployee('D00')) as x
Actually there is a trap hidden here:
select * from table(nameemployee(CAST('D00' AS CHAR(3)))) as x

Literals are defined as VARCHAR in the standard (who knows why.,...)
In general I don't recommend defining functions with SMALLINT and CHAR
parameters for that reason...

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 3 '07 #3
What would be the purpose/advantage of returning something as a table
(I assume a temp table?) as opposed to a resultset? Have not seen
such before.

thanks

Phil
On May 3, 3:17 pm, Serge Rielau <srie...@ca.ibm.comwrote:
Ian wrote:
Aborges wrote:
Hi,
I created a function, but I don't know to call this function.
CREATE FUNCTION NAMEEMPLOYEE (DEPTO CHAR(3))
RETURNS TABLE (EMPID INTEGER, NAME VARCHAR(60), PHONE CHAR(8))
LANGUAGE SQL
READS SQL DATA
NO EXTERNAL ACTION
DETERMINISTIC
RETURN
SELECT EMPID, NAME, PHONE
FROM BEST.EMPLOYEES
WHERE DEPTO = BEST.DEPTO
Is my function correct?
I'm running DB2 7.1.
You don't say what platform you are on, but typically the
call would look like:
select * from table(nameemployee('D00')) as x

Actually there is a trap hidden here:
select * from table(nameemployee(CAST('D00' AS CHAR(3)))) as x

Literals are defined as VARCHAR in the standard (who knows why.,...)
In general I don't recommend defining functions with SMALLINT and CHAR
parameters for that reason...

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

May 4 '07 #4
PJ******@txfb-ins.com wrote:
What would be the purpose/advantage of returning something as a table
(I assume a temp table?) as opposed to a resultset? Have not seen
such before.
Result sets are the means to communicate things from DB2 to the application.
Tables are the construct used internally in DB2. (Granted, result sets are
available today as well within stored procedures.)

Also, result sets are much more dynamic (# of columns, data types, ...).
This is not very favorable for the optimizer because it can't apply many
optimizations for which the structure of the data is needed. Table
functions provide that structural information.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
May 4 '07 #5
PJ******@txfb-ins.com wrote:
What would be the purpose/advantage of returning something as a table
(I assume a temp table?) as opposed to a resultset? Have not seen
such before.
SQL Table functions are sometimes called "parameterized views"
That is they have all the benefits and properties of views, but also
allow correlation.
When combining result sets you are stuck literally with nested loop joins.
SQL Table functions extend SQL and hence allow the optimizer to do a
whole lot of interesting stuff.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 4 '07 #6
Many thanks to you all for the good into - fascinating! Would such a
thing work for an SQL PL stored procedure or even a COBOL stored
procedure? We have 8.2 on UDB (where SQL PL would run) and 8.1 I
think on Z/OS where any cobal stuff would run. So what is the scope
of this "table" - treated like a global temp table and confined to
that "session"? The newest IBM book on SQL Pl arrived recently and I
don't recall anything returning results as anything other than result
sets by opening a cursor...
many thanks,

Phil
On May 4, 7:02 am, Serge Rielau <srie...@ca.ibm.comwrote:
PJack...@txfb-ins.com wrote:
What would be the purpose/advantage of returning something as a table
(I assume a temp table?) as opposed to a resultset? Have not seen
such before.

SQL Table functions are sometimes called "parameterized views"
That is they have all the benefits and properties of views, but also
allow correlation.
When combining result sets you are stuck literally with nested loop joins.
SQL Table functions extend SQL and hence allow the optimizer to do a
whole lot of interesting stuff.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

May 5 '07 #7
PJ******@txfb-ins.com wrote:
Many thanks to you all for the good into - fascinating! Would such a
thing work for an SQL PL stored procedure or even a COBOL stored
procedure? We have 8.2 on UDB (where SQL PL would run) and 8.1 I
think on Z/OS where any cobal stuff would run. So what is the scope
of this "table" - treated like a global temp table and confined to
that "session"? The newest IBM book on SQL Pl arrived recently and I
don't recall anything returning results as anything other than result
sets by opening a cursor...
many thanks,
It's like a view. The optimizer may chose to represnt as a temp or
simply pipe the reuslts back.
Keep in mind that this is a FUNCTION that is it is part of an SQL statement.
This is different from a PROCEDURE which is invoked by a CALL statement
What the optimizer does is independent on where this SQL statement is
executed from (SQL PL, Cobol, Java...)

I know that DB2 V8 zOS supports scalar SQL UDF. Not sure about table UDF.
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 5 '07 #8

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

Similar topics

10
by: Michael | last post by:
Guys, I'm interested in how the compiler implements function calls, can anyone correct my understanding/point me towards some good articles. When a function is called, is the stack pointer...
4
by: deko | last post by:
When I loop through this function, it works fine until it hits End Function - then it jumps to End Select. Very strange... This behavior occurs when Case = 255. Any ideas why this is happening? ...
7
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead....
4
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. ...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
10
by: Nitin | last post by:
Ppl , Want to have ur opinions on having function calls like the one stated below: function funcA ( struct A *st_A , struct B *st_B ) { st_A->a = st_B->a
6
by: Larry Menard | last post by:
Folks, I know that DB2 does not (yet?) support this, but I wonder if anyone can suggest a work-around. I've seen article...
3
by: wernerf | last post by:
Hi all. Here's my problem: Consider a package MY_PKG with the following two functions FUNCTION get_number_by_rowid( p_table_name IN VARCHAR2, ...
5
by: Peter Olcott | last post by:
Does anyone know of any good software that automatically produces a function call invocation diagram for C/C++ programs? I think that this would be very useful for determining the possible...
15
by: asm23 | last post by:
Hi, everyone, I'm studying the <<Thinking in C++>volume Two. In Chapter One, the example code : Auto_ptr.cpp //------------------------------------------------------- #include <memory> #include...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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,...

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.