---
title: "Top DB2 UDF Interview Questions"
description: "Really useful UDF example you can use it for your DB2 project. Added interview questions."
url: https://srinimf.com/2018/06/22/db2-udf-sample-function-read-now-with-awesome-interview-question/
date: 2018-06-22
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2018/06/schultute-zuckertute-back-to-school-training-159590-e1529656482910.jpeg?fit=500%2C375&ssl=1
categories: ["DB2"]
tags: ["User defined functions"]
type: post
lang: en
---

# Top DB2 UDF Interview Questions

DB2 functions and [stored procedure](https://srinimf.com/2025/09/10/pyspark-stored-procedure-alternative-explained-for-interview-prep/)s reside in the Database. When you invoke them they will trigger. You can write UDFs ([User Defined Function](https://srinimf.com/2020/07/25/db2-user-defined-function-syntax-to-create-drop/)s) using any language like **SQL, C or COBOL**. You can access UDFs from DB2 local, or remote server.

## DB2 scalar user defined function.

*UDF: Function is basically something repeatedly you are using in your SQL query. Then, you can call your function in main SQL query to avoid complexity*

DB2 scalar user defined function using SQL.

## Example

```
create function emp_current_votes
(employee_id char(6))
returns integer
specific emp_curr_votes_int
not deterministic
language sql
return select count(*)from emp_votes where empno = emp
```

In the above function you are getting votes from votes table. Here the function is **emp_currrent_votes.**

## How to run user defined function in DB2

```
db2 =&gt; select firstnme, lastname, emp_current_votes(empno)
from employee;
```

```
FIRSTNME LASTNAME 3
------------ ----------
CHRISTINE HAAS 1
MICHAEL THOMPSON 0
SALLY KWAN 0
...
WING LEE 0
JASON GOUNOT 0
DIAN HEMMINGER 2
GREG ORLANDO 0
KIM NATZ 0
KIYOSHI YAMAMOTO 0
```

**Interview Question**

- One important limitation is the use of user-defined scalar functions in an order by clause. To provide a usable ordering function, the UDF must be deterministic. If you attempt to order by a nondeterministic scalar function, you’ll get error code SQL0583N.

**Also read**

- [How to CREATE and DROP User-defined Function in DB2](https://srinimf.com/2020/07/25/db2-user-defined-function-syntax-to-create-drop/)DateJuly 25, 2020
- [How to Create UDF in DB2](https://srinimf.com/2010/04/12/db2-udf/)DateApril 12, 2010
- [SQL: Column Vs Table Vs Row Vs Table Functions](https://srinimf.com/2016/10/12/the-ultimate-notes-on-sql-functions-to-make-you-stronger/)DateOctober 12, 2016

### 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%2F2018%2F06%2F22%2Fdb2-udf-sample-function-read-now-with-awesome-interview-question%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2018%2F06%2Fschultute-zuckertute-back-to-school-training-159590-e1529656482910.jpeg%3Ffit%3D500%252C375%26ssl%3D1&description=Top%20DB2%20UDF%20Interview%20Questions)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2018/06/22/db2-udf-sample-function-read-now-with-awesome-interview-question/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2018/06/22/db2-udf-sample-function-read-now-with-awesome-interview-question/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2018/06/22/db2-udf-sample-function-read-now-with-awesome-interview-question/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2018/06/22/db2-udf-sample-function-read-now-with-awesome-interview-question/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Top%20DB2%20UDF%20Interview%20Questions&body=https%3A%2F%2Fsrinimf.com%2F2018%2F06%2F22%2Fdb2-udf-sample-function-read-now-with-awesome-interview-question%2F&share=email)
-

### Like this:

Like Loading…
