petek, 29. september 2006

DB2 "Virtual" tables

In DB2 you sometimes need a virtual table. I call table a virtual if you don't know in advance what the structure of it will be and you don't need the virtual table to be persistent.
Let's say that you have a table on you GUI form that has three columns (C1, C2, C3) and the data there are: (1, 2, 3) (4, 5, 6) (7, 8, 9) and you would like to do some SELECT statements over this table:
SELECT * FROM TABLE(VALUES((1, 2, 3), (4, 5, 6), (7, 8, 9))) T(C1, C2, C3)
With T(C1, C2, C3) you say that table T has columns named C1, C2 and C3. This table T acts like any other ordinary table. You can so SUMs, GROUP BYs, .... on it.

I've heard this is DB2 v2 stuff, but I still find it powerful. :)))
Objavite komentar