17.10.2015 Views

Getting Started with IBM Data Studio for DB2

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

266 <strong>Getting</strong> <strong>Started</strong> <strong>with</strong> <strong>IBM</strong> <strong>Data</strong> <strong>Studio</strong> <strong>for</strong> <strong>DB2</strong><br />

Scalar functions are widely used in SQL statements to do processing of individual or<br />

aggregate values. UDFs that receive multiple values as input and return a scalar value are<br />

called aggregate functions.<br />

Here is an example of using the built-in scalar function concat():<br />

db2 => values CONCAT('Hello', ' World')<br />

1<br />

-----------<br />

Hello World<br />

1 record(s) selected.<br />

You can use table functions in several different ways. You can use a table function to<br />

operate (<strong>with</strong> SQL language) on data that is not stored in a database table, or even to<br />

convert such data into a table. You can use them to read data from files, from the Web, or<br />

from Lotus Notes databases, and return a result table. The in<strong>for</strong>mation resulting from a<br />

table function can be joined <strong>with</strong> in<strong>for</strong>mation from other tables in the database, or from<br />

other table functions.<br />

9.2 Creating a user-defined function<br />

<strong>Data</strong> <strong>Studio</strong> supports template based user-defined function creation. There are many<br />

predefined routine templates that allow the user to create user-defined functions easily. A<br />

routine template is a predefined text <strong>with</strong> some standard code, comments, best practices,<br />

etc. that makes it easy <strong>for</strong> developers to start creating new user-defined functions.<br />

To create a UDF, follow these steps:<br />

1. Create a new data development project as you learned to do in Chapter 8. Name the<br />

projectUDF Project.<br />

2. Right-click on the User-Defined Functions folder under UDF Project, and select New -><br />

User-Defined Function as shown in Figure 9.1.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!