---
title: "How to Use DB2 LOCATE Built-in Function"
description: "Checkout here my earlier post on built-in functions. LOCATE is a Scalar function. Here is my ideas how to use correctly . Below is the Syntax for LOCATE function. SELECT LOCATE('String to be searched'..."
url: https://srinimf.com/2015/07/17/mainframe-db2-locate-built-in-function/
date: 2015-07-17
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2015/07/pexels-photo.jpg?fit=1880%2C1253&ssl=1
categories: ["DB2"]
tags: ["LOCATE function DB2"]
type: post
lang: en
---

# How to Use DB2 LOCATE Built-in Function

Checkout here my [earlier post](http://srinimf.com/2012/07/04/db2-sql-ltrim-rtrim-and-trim/) on built-in functions. LOCATE is a Scalar function. Here is my ideas how [to use correctly](https://srinimf.com/2015/08/20/db2-max-column-function-best-example/).

## Below is the Syntax for [LOCATE function](https://srinimf.com/2014/08/15/db2-locate-scalar-function/)

SELECT LOCATE(‘String to be searched’, Source string’, Start position)
FROM SYSIBM.SYSDUMMY1;

## Key points in LOCATE function

- The LOCATE function returns the starting position of search-string within source-string.
- If search-string is not found and neither argument is null, the **result is zero.**
- If search-string is found, the **result is a number from 1 to the actual length of source-string**.
- If search-string has a length of zero, the **result returned by the function is 1.**
- If the optional start is specified, it indicates the character position in source-string at which the search is to begin.
- An optional string unit can be specified to indicate in what units the start and result of the function are expressed.

## Best Example of LOCATE Function

SELECT LOCATE(‘N’, ‘DINING’)
FROM SYSIBM.SYSDUMMY1;

Result is : 3

Below examples is just to select columns, such that  word ‘GOOD’ to be present in NOTE_TEXT.

SELECT RECEIVED, SUBJECT, LOCATE(‘GOOD’, NOTE_TEXT)
FROM IN_TRAY
WHERE LOCATE(‘GOOD’, NOTE_TEXT) <> 0;

**Using SET commands**

```
SET :LOCATION = LOCATE('ß','Jürgen lives on Hegelstraße',1,CODEUNITS32); 
Result is "26"
SET :LOCATION = LOCATE('ß','Jürgen lives on Hegelstraße',1,OCTETS); 
REsult is "27"
```

Keep Reading

Related[Substring in DB2 Quick Tutorial](https://srinimf.com/2017/01/02/the-best-substring-example-in-db2-for-quick-use/)

- [DB2 Functions POSSTR Alternative to LOCATE](https://srinimf.com/2014/09/04/db2-functions-posstr-and-locate/)DateSeptember 4, 2014
- [DB2 LOCATE Function Advanced Examples](https://srinimf.com/2014/08/15/db2-locate-scalar-function/)DateAugust 15, 2014
- [SQL Query: How to Use LOCATE and Substring Correctly](https://srinimf.com/2021/04/18/sql-query-how-to-use-locate-and-substring-correctly/)DateApril 18, 2021

### 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%2F2015%2F07%2F17%2Fmainframe-db2-locate-built-in-function%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2015%2F07%2Fpexels-photo.jpg%3Ffit%3D1200%252C800%26ssl%3D1&description=How%20to%20Use%20DB2%20LOCATE%20Built-in%20Function)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2015/07/17/mainframe-db2-locate-built-in-function/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2015/07/17/mainframe-db2-locate-built-in-function/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2015/07/17/mainframe-db2-locate-built-in-function/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2015/07/17/mainframe-db2-locate-built-in-function/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Use%20DB2%20LOCATE%20Built-in%20Function&body=https%3A%2F%2Fsrinimf.com%2F2015%2F07%2F17%2Fmainframe-db2-locate-built-in-function%2F&share=email)
-

### Like this:

Like Loading…
