You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Kusto Query Language中截取指定子字符串?

在KQL中提取指定子串起始的部分内容

你可以结合使用substring()和indexof()函数来实现需求:

  1. 先用indexof()定位目标子串的起始位置
  2. 再用substring()从该位置开始截取到字符串末尾

示例代码:

let errorString = 'Execution fail against sql server. Please contact SQL Server team if you need further support. Sql error number: 50000. Error Message: Invalid length parameter passed to the LEFT or SUBSTRING function.';
print extractedPart = substring(errorString, indexof(errorString, 'Error Message:'))

执行这段代码后,输出结果就是你需要的:

Error Message: Invalid length parameter passed to the LEFT or SUBSTRING function.

如果担心目标子串不存在导致报错,可以用iif()做容错处理:

let errorString = 'Execution fail against sql server. Please contact SQL Server team if you need further support. Sql error number: 50000.';
print extractedPart = iif(indexof(errorString, 'Error Message:') != -1, substring(errorString, indexof(errorString, 'Error Message:')), '未找到Error Message部分')

内容的提问来源于stack exchange,提问作者AndreasB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 09:13:10