如何提取字符串的一部分并将其转换为整数?

时间:2017-09-13 06:22:26

标签: sql oracle obiee

例如 - 如果我有如下所述的字符串: -

摘要:开始量(每月)= 2结束量(每月)= 0减量量(年)= 13效率增益= 100日志:09/13/2017

我只想在列中显示减少体积的值。我应该写什么查询?

2 个答案:

答案 0 :(得分:0)

试试这个

SELECT SUBSTR(COL,S1,INSTR(COL,' ',S1)-S1) X
FROM  (SELECT COL, INSTR( COL, 'Volume Reduction (year) = ',1)+LEN('Volume Reduction (year) = ') AS S1
       FROM (SELECT 'Summary: Start Volume (monthly) = 2 End Volume (monthly) = 0 Volume Reduction (year) = 13 Efficiency Gains = 100 Log: 09/13/2017' AS COL 
             FROM DUAL) A
        ) B;

输出:

X
13

答案 1 :(得分:0)

试试这个:

DECLARE @DATA VARCHAR(256);
DECLARE @DATA1 VARCHAR(256);

SET @DATA = 'Summary: Start Volume (monthly) = 2 End Volume (monthly) = 0 Volume Reduction (year) = 13 Efficiency Gains = 100 Log: 09/13/2017'

SELECT @DATA1 = RIGHT(@DATA,LEN(@DATA)-CHARINDEX(' 13',@DATA))

SELECT SUBSTRING(@DATA1, PATINDEX('%[1-9]%', @DATA1), LEN(120)) AS DATA