# `Fn_split_string` (function)

> 根据分隔符，取第几个截取字符串


- **Type:** FUNCTION
- **Returns:** `varchar(255)`
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `str` | `longtext` |
| 2 | IN | `splitstr` | `varchar(5)` |
| 3 | IN | `strindex` | `int` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE FUNCTION `Fn_split_string`'`._

## Narrative

**Business context:** Returns the Nth token from a delimited string — the indexed-access companion to `Fn_spit_length`'s count. The pair is the standard string-list iteration kit used across the save-return validation flows and many reports.

**What it does:** `reverse(substring_index(reverse(substring_index(str, splitstr, strindex)), splitstr, 1))` — slices off the first `strindex` tokens, reverses, slices off the last one, reverses back. Returns the 1-based Nth token.

**Invocation:** called from ~100 production procs, including all `Sp_saveReturn_*` / `Sp_beforeSaveReturn_*` document save flows, the work-order cost-calc data-pack procs (`Sp_WorkOrder_CalcDataPack*`), the AutoOrder production-plan procs (`Sp_productionPlan_BtnEventAutoOrder*`), and a handful of utility funcs (`Fun_bFilter_toWhere`, `Fun_getPartNameStatus`, `Fun_getPlanDate`).
