---
title: "How to Create UDF in C Language"
description: "User defined functions you can create using SQL or any other supported language. Read more."
url: https://srinimf.com/2014/06/04/creating-udf-in-db2-zos/
date: 2014-06-04
modified: 2021-01-21
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2014/06/pexels-photo-5945892.jpeg?fit=1880%2C1129&ssl=1
categories: ["DB2"]
tags: ["DB2 Tips and Solutions"]
type: post
lang: en
---

# How to Create UDF in C Language

Simple UDF code, it is written in ‘C’ Language. UDFs are small programs that you can write to perform an operation. You can write [user defined functions in SQL, C or any other supported language](https://srinimf.com/2018/06/22/db2-udf-sample-function-read-now-with-awesome-interview-question/).

## Sample UDF Create Function

CREATE FUNCTION DAYSINMONTH(DATE)

RETURNS INTEGER

EXTERNAL NAME ‘DAYMTH’

LANGUAGE C;

This statement creates a UDF named DAYSINMONTH, with one parameter of DATE data type. It returns a single value of INTEGER data type. The external name for the function, that is the actual program name, is DAYMTH and it is coded in C.

Most of the parameters have been omitted from this simple CREATE FUNCTION example. Once the user-defined function has been created, and the appropriate authority has been Granted, the UDF can be used in an SQL statement,

for example:

SELECT EMPNO, LASTNME,

BIRTHDATE, DAYSINMONTH(BIRTHDATE)

FROM PAYROLL.EMP

WHERE DAYSINMONTH(BIRTHDATE) < 31;

The results of this statement would be a list of employees whose birth date falls in a month having fewer than 31 days (that is, February, April, June, September, and November). This assumes that the program for the user-defined function, DAYSINMONTH, is correctly coded to examine the date specified as input and return the actual number of days in the month.

References

- **[User defined functions from IBM](http://www-01.ibm.com/support/knowledgecenter/SSEPEK_10.0.0/com.ibm.db2z10.doc.apsg/src/tpc/db2z_defineudf.dita?lang=en)**

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2014%2F06%2F04%2Fcreating-udf-in-db2-zos%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2014%2F06%2Fpexels-photo-5945892.jpeg%3Ffit%3D1200%252C721%26ssl%3D1&description=How%20to%20Create%20UDF%20in%20C%20Language)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2014/06/04/creating-udf-in-db2-zos/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2014/06/04/creating-udf-in-db2-zos/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2014/06/04/creating-udf-in-db2-zos/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2014/06/04/creating-udf-in-db2-zos/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Create%20UDF%20in%20C%20Language&body=https%3A%2F%2Fsrinimf.com%2F2014%2F06%2F04%2Fcreating-udf-in-db2-zos%2F&share=email)
-

### Like this:

Like Loading…
