IsNumeric (function)
判断是否是数字(相当于sql Server中 IsNumeric函数)
- Type: FUNCTION
-
Returns:
int - Deterministic: NO
- SQL data access: CONTAINS SQL
Parameters
| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | str |
varchar(25) |
Body
Body is not pre-cached. To inspect: mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE FUNCTIONIsNumeric'.
Narrative
Business context: SQL-Server IsNumeric polyfill — returns 1 when str is a (signed) numeric literal, 0 otherwise. Used as a guard before casting user-entered specs/qty strings to numbers; the unit-conversion family (Fun_GetAuxiliaryQtyUnit, Fun_GetMaterialsQtyUnit, Fun_GetMaterialsQtyUnitSupple, Fun_GetReelAuxiliaryQtyUnit, Fun_GetProcessAuxiliaryQty) calls it before doing arithmetic on free-form sName-style label fields.
What it does: returns 0 for NULL or empty input. Otherwise tests str REGEXP '-?[1-9]d*$' and str REGEXP '-?[0-9]+(.[0-9]{1,3})?$'; returns 1 if either matches. Note: both regexes are subtly wrong — d and . are unescaped (MySQL REGEXP interprets d as the literal char and . as any char), so the first regex actually accepts strings ending in a digit-followed-by-d runs, and the second accepts any digit run with up to 3 trailing characters. In practice the second pattern is loose enough that genuine numeric strings still get a 1, which is why callers haven't noticed.
Invocation: referenced by 30+ routines — the entire Fun_Get*QtyUnit* family, Sp_BillOfApply/ApplyLine/NoPicking/NoPicking_Cljg, Sp_GetMachineByApsRule, sp_GetMaterialsQtyUnit, Sp_Manufacture_InsertWorkOrder, Sp_Manufacture_sSodPurchareMaterials, Sp_Manufacture_sWodPurchareMaterials_copy1, Sp_MaterialsStoreVirtual, Sp_Quotation__CalcDataPackLastStd. Canonical "is this string a number?" guard for the BOM/cost build chain. Caveat (regex escaping): see body note above — flag for maintainer audit.