Fn_spit_length.md 1.28 KB

Fn_spit_length (function)

根据分隔符 获取分割后对象个数

  • Type: FUNCTION
  • Returns: int
  • Deterministic: NO
  • SQL data access: CONTAINS SQL

Parameters

# Mode Name Type
1 IN str longtext
2 IN splitstr varchar(5)

Body

Body is not pre-cached. To inspect: mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE FUNCTIONFnspit_length'._

Narrative

Business context: Counts how many tokens a delimited string would produce when split on splitstr. Building block used throughout the save-return / before-save-return validation procs (Sp_saveReturn_*, Sp_beforeSaveReturn_*) — those procs iterate over comma-joined id lists coming from the FROUNT save payload, and this gives them the loop bound.

What it does: length(str) - length(replace(str, splitstr, '')) + 1 — one-liner that subtracts the trimmed length from the original to count delimiters, then adds one. Returns 1 even when the input has no delimiter at all.

Invocation: called from ~80 production procs, dominated by the Sp_saveReturn_* and Sp_beforeSaveReturn_* document save flows (sales order _sSod, work order _sWod, quotation _sQtt, packing _sPkg, etc.) and a handful of cost-calc / reporting procs.