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

字符串解析技术求助:如何提取14=标识后的目标文本内容?

Extract Target Substring from Delimited Key-Value String in SQL

Got it, I see where you're stuck right now. Your current query only gets the starting position of 14= using CHARINDEX, but doesn't actually extract the text that follows it. Let's fix that with an adjusted SQL statement tailored to your string's structure (key-value pairs separated by ^).

First, let's recap your target string structure for context:

1=BETA.1.02=1753=8124=R5=N9=112=113=0003214=REP NOT FOUND ON REP TABLE, CANNOT INSERT TO REPRGR.10=107~117~265~1114~3143~3505~3506~3513~571711=SA161WYWYAS20100210001SE62^-omitted due to existing Rep Not Found

You need the text after 14= and before the next ^ (or the end of the string if 14= is the last pair). Here's the working SQL query for SQL Server (since your original query uses CONVERT(VARCHAR, ...) which is SQL Server syntax):

SELECT 
    SUBSTRING(
        YourColumnName, -- Replace with your actual column name
        CHARINDEX('14=', YourColumnName) + 3, -- Skip the '14=' characters to start at the message
        ISNULL(
            CHARINDEX('^', YourColumnName, CHARINDEX('14=', YourColumnName) + 3),
            LEN(YourColumnName) + 1
        ) - (CHARINDEX('14=', YourColumnName) + 3)
    ) AS ExtractedErrorMessage
FROM YourTableName; -- Replace with your actual table name

Let's break down how this works:

  • CHARINDEX('14=', YourColumnName) finds the starting index of the 14= marker. Adding 3 skips those 3 characters so we start at the actual error message text.
  • The inner CHARINDEX('^', ...) looks for the next ^ delimiter starting right after 14=. If there's no ^ after 14= (meaning it's the last key-value pair), ISNULL uses LEN(YourColumnName) + 1 to ensure we grab all text until the end of the string.
  • The final calculation subtracts the start position from the end position to get the exact length of the text we need to extract.

When you run this against your sample string, it will return exactly:

REP NOT FOUND ON REP TABLE, CANNOT INSERT TO REPRGR.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:08:24