

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# POSITION 函數
<a name="POSITION"></a>

傳回指定子字串在一個字串內的位置。

## 語法
<a name="position-synopsis"></a>

```
POSITION(substring IN string )
```

## 引數
<a name="POSITION-arguments"></a>

 *substring*   
在 *string* 內要搜尋的子字串。

 *string*   
要搜尋的字串或欄。

## 傳回類型
<a name="position-return-type"></a>

POSITION 函數傳回對應於子字串位置的整數 (以 1 開始，不是以零開始)。位置以字元數為基礎，而不是位元組，所以多位元組字元視為單一字元。

## 使用須知
<a name="POSITION_usage_notes"></a>

如果在字串內找不到子字串，POSITION 會傳回 0：

```
select position('dog' in 'fish');

position
----------
 0
(1 row)
```

## 範例
<a name="sub-POSITION_usage_notes-examples"></a>

下列範例顯示字串 `fish` 在單字 `dogfish` 內的位置：

```
select position('fish' in 'dogfish');

position
----------
 4
(1 row)
```

下列範例從 SALES 資料表中傳回 COMMISSION 超過 999.00 的銷售交易次數：

```
select distinct position('.' in commission), count (position('.' in commission))
from sales where position('.' in commission) > 4 group by position('.' in commission)
order by 1,2;

position | count
---------+-------
       5 |    629
(1 row)
```