Creating Db2 user-defined table functions
Use the New UDTF Definitions in DB2 Wizard to create user-defined table functions (UDTFs) in Db2 for z/OS for access to any supported data source type.
Before you begin
To use this wizard, virtual tables should already exist for your data sources. See Creating virtual tables.
About this task
Procedure
- Expand the node, where SSID is the name of your server.
- In the Virtual Tables node, right-click one or more virtual tables, and select Create UDTF Definitions in DB2.
-
In the New UDTF Definitions in DB2 Wizard, on the Generate
DDL with user-defined table functions page, complete the following fields:
Field Action General DB2 Settings Specify information about the Db2 subsystem where the UDTFs and views will be created. - Subsystem: Select the Db2 subsystem ID from the drop-down list.
- Schema: Select the schema from the drop-down list, or enter a new schema name.
- GRANT TO: Specify to whom privileges are granted for the generated UDTFs and views. Clear this field to not include the GRANT TO statement in the generated DDL.
- UDTF Module: This value defaults to the UDTF module in use for your
system. If you need to change this value, enter the name of another UDTF module. The
following modules are available:
- AVZUDT9N
- AVZUDTAN
- AVZUDTBN
- AVZUDTCN
- WLM Environment: The address space Db2 starts to run user-defined functions. Leave this field blank to omit the WLM ENVIRONMENT clause in the generated DDL.
"Generate" Actions Specify whether to execute or save the DDL, or both. - Execute generated DDL in DB2: Select this option to execute the generated DDL on the specified Db2 subsystem.
- Save DDL to file: Optionally, enter a file name (with
.sql extension) where to save the DDL. This step might be required if you do
not have authorization to execute the DDL. Or, you might want to review the DDL in the
SQL Editor first, before running it in Db2.
- Append to file: Select to append the generated DDL to an existing file.
- Open file in SQL Editor: Select to open the generated DDL in the SQL Editor.
Naming Patterns Specify the format to use for the generated function and view names. Use the following variables to create naming patterns: - {Server}: Data Virtualization Manager server name
- {Table}: Virtual table name
Note: If Views is blank, views will not be generated. - Click Generate.
Results
The DDL for creating UDTFs and corresponding views is generated. For more information, see Generated DDL for UDTFs.
After the DDL is executed, a UDTF and a corresponding view are created for each selected virtual
table. In the Server tab, locate the new objects by expanding , and then the appropriate nodes, as follows:
- The Db2 views are located in the Views node.
- The Db2 UDTFs are located in the node.
What to do next
- Using the new Db2 views, compose and execute SQL queries to access the data. You can do this from the Data Virtualization Manager studio or from a Db2 client.
- Using the new Db2 UDTFs, compose and execute SQL queries to select data from the virtual table. Queries can be generated for a specific UDTF function or for a subset of columns within a UDTF.