【问题标题】:Sql to find character on the stringSql在字符串上查找字符
【发布时间】:2023-03-19 18:15:01
【问题描述】:

我有如图所示的字符串,我需要获取“INTERNAL_INSTRUCTION_NUM”旁边的值意味着我需要获取值“9076”意味着在我的表 INTERNAL_INSTURCTION_NUM 中具有值 9076。我需要从字符串中检索。放在星号内的是我需要的字符串。我需要将参数作为 INTERNAL_INSTURCTION_NUM 传递,并将值返回为“9076”

字符串附在下面的链接中。 https://drive.google.com/open?id=0BypBdg0gwa3Bb3FlakFVY29QTGc

【问题讨论】:

  • 无法附加字符串。使用下面的下拉框作为字符串附加的文本文件。
  • 似乎是产品特定问题。您使用的是哪个 dbms?
  • 你有没有尝试过?
  • 您使用的是哪个 DBMS?后格雷斯?甲骨文? DB2?火鸟?

标签: sql substring charindex


【解决方案1】:

这是一个 SQL Server 版本:

declare @param nvarchar(max) = N'INTERNAL_INSTRUCTION_NUM';

declare 
    @pos int,
    @temp nvarchar(max);

set @pos = charindex(@param, @test);

set @temp = substring(@test, @pos + len(@param), len(@test) 
                 - @pos - len(@param));

-- find first # after param
set @pos = charindex('#', @temp);
set @temp = substring(@temp, @pos+1, len(@temp) - @pos);

-- find second # after param
set @pos = charindex('#', @temp);
set @temp = substring(@temp, @pos+1, len(@temp) - @pos);

-- find the value we are looking for assuming it is enclosed between ",+" and "?%"
select substring(@temp, 3, len(@temp) - 4)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-13
    • 2018-01-02
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多