---
title: "DB2 LOCATE Function Advanced Examples"
description: "LOCATE SCALAR - Function returns first occurrence position in first string, second string: Example 1 : SELECT LOCATE('I','MINE STRING') FROM SYSIBM.SYDUMMY1. It returns value 2. Since first occurrence..."
url: https://srinimf.com/2014/08/15/db2-locate-scalar-function/
date: 2014-08-15
modified: 2021-04-19
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2014/08/pexels-photo-310452.jpeg?fit=1880%2C1253&ssl=1
categories: ["DB2 V11"]
tags: ["LOCATE function DB2"]
type: post
lang: en
---

# DB2 LOCATE Function Advanced Examples

LOCATE SCALAR – Function returns first occurrence position in first string, second string:

**Example 1****:**

SELECT LOCATE(‘I’,’MINE STRING’) FROM SYSIBM.SYDUMMY1

It returns value 2. Since first occurrence is 2.

**Example 2****:**

SELECT LOCATE(‘I’,’MINE STRING’,3) FROM SYSIBM.SYDUMMY1

Now the answer will be 9. Since after third position it starts searching for ‘I’.

Read my post on [DB2 functions](http://srinimf.com/2015/07/15/mainframe-simplify-your-db2-sql-query-with-these-built-in-functions/).

Reference [link here](http://www.informit.com/articles/article.aspx?p=174097&seqNum=2).

### 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%2F08%2F15%2Fdb2-locate-scalar-function%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2014%2F08%2Fpexels-photo-310452.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=DB2%20LOCATE%20Function%20Advanced%20Examples)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2014/08/15/db2-locate-scalar-function/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2014/08/15/db2-locate-scalar-function/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2014/08/15/db2-locate-scalar-function/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2014/08/15/db2-locate-scalar-function/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20DB2%20LOCATE%20Function%20Advanced%20Examples&body=https%3A%2F%2Fsrinimf.com%2F2014%2F08%2F15%2Fdb2-locate-scalar-function%2F&share=email)
-

### Like this:

Like Loading…
