> Hi,
>
[quoted text clipped - 59 lines]
> as literal to be opened as a cursor and then ith is stored in a GTT and
> then query the GTT thus RETURNING the TABLE.
Like swimming in quick sand.. Everytime you move you go deeper...
What about starting at the other end:
Why does your application drop and recreate tables?
SQL Functions in DB2 UDB are essentially macros.
To do anything complex (like dynamic SQL and DDL!) with them you must
use the CALL statement.
Having said that this works great for SQL Scalar functions, but for
table functions you have to problem of linking the result set of teh
proc with the result of the table function. No joy.
So what you would have to do is use an external table function (C, JAVA,
CLR)
Anyway.. fix you orginal problem. Applications don't do DDL!
DBA's do DDL.
Cheers
Serge

Signature
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Mark A - 08 Dec 2005 07:39 GMT
> Anyway.. fix you orginal problem. Applications don't do DDL!
> DBA's do DDL.
> Cheers
> Serge
Some applications create tables, such a separate audit table for each day.
purushneel@gmail.com - 08 Dec 2005 16:42 GMT
Serge,
Thanks for the reply.
Here is the reason why we need to drop and recreate tables in DB2?
This application is a metadata repository and allows users to update
that metadata. User might create new columns or drop a metadata table.
The changes in the metadata needs to be reflected into a main database
which will contain other tables too. To do this, we need to create,
drop and populate the data. Users does not need to be connected to the
main database. Just a small footprint of the main database is necessary
on the user machine and user can do changes any time and when ready,
apply the changes to the main DB. There might more than one way to
approach this solution. But, at present, we need to resolve the current
issue and think later about changing the way the application works.
I was confident that DB2 had some thing in the store for this issue. It
tried a similar logic in Oracle and SQL Server. It works like a charm.
Now, just for DB2, I need to think of a External Table function for
DB2. I was hoping to have a FUNCTION based solution for the above issue
for all the 3 DB's. Now, I need to do some coding in Java/C/.NET to
make it work in DB2!!! more maintainance of the application!!!
Thanks,
Purush
Thanks,
Purush
Serge Rielau - 08 Dec 2005 22:38 GMT
> Serge,
>
[quoted text clipped - 18 lines]
> for all the 3 DB's. Now, I need to do some coding in Java/C/.NET to
> make it work in DB2!!! more maintainance of the application!!!
What about recreating the view. Note that the view text will still be in
the catalog, it's just marked as invalid.
Cheers
Serge

Signature
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Why didn't you use a simple RETURN statement for the Function Body?
Like this:
CREATE FUNCTION GetRecursiveCDOs()
RETURNS TABLE(CDODefId INTEGER)
READS SQL DATA
RETURN
WITH RecursiveCDOs (CDODefId) AS (
SELECT Parent.CDODefId
FROM CDODefinition Parent
WHERE Parent.CDODefId IN ( 1020, 1050 )
UNION ALL
SELECT Child.CDODefId
FROM RecursiveCDOs Parent
, CDODefinition Child
WHERE Child.ParentCDOId = Parent.CDODefId
)
SELECT CDODefId FROM RecursiveCDOs'
;
Another point:
When you use the function, you should write a column name for
correlation name or remove "()" from correlation name.
SELECT CDODefChain
FROM TABLE(GetRecursiveCDOs()) AS RecursiveCDOs(CDODefChain);
or
SELECT CDODefId
FROM TABLE(GetRecursiveCDOs()) AS RecursiveCDOs;
Tonkuma - 10 Dec 2005 16:13 GMT
I made mistake.
I should remove a quotation from last SELECT of the function
CREATE FUNCTION ...
...
...
SELECT CDODefId FROM RecursiveCDOs
;
You might want to get a copy of TREES & HIERARCHIES IN SQL. For
example, the nested sets model does not require procedural code at all
to model a tree structure.