返回空格前后的字符

时间:2019-07-15 09:04:29

标签: oracle oracle-sqldeveloper

所以我正在尝试检索地址数据。当前数据存在问题,地址将显示两次门牌号码。例如“ 9 9 House Road”。我想标识所有以“ 9 9”开头的两个数字的街道地址。因此,仅在前两个字符相同且两个都是数字的情况下,我才想返回它。有提示吗?

因此,我在oracle SQL开发人员上运行它。版本17.4.1.054

SELECT ACCOUNT_ID,
       STREET_NAME,
       substr((STREET_NAME), 1, instr(ADDR_STREET_NAME, ' ')),
       substr((STREET_NAME), instr(STREET_NAME, ' '), instr(STREET_NAME, ' '))
FROM ACOUNT_TBL
WHERE REPLACE(substr((STREET_NAME), 1, instr(STREET_NAME, ' ')), ' ', '') = REPLACE(substr((STREET_NAME), instr(STREET_NAME, ' '), instr(STREET_NAME, ' ')), ' ', '')
  AND REPLACE(substr((ADDR_STREET_NAME), 1, instr(ADDR_STREET_NAME, ' ')), ' ', '')NOT LIKE '[^0-9]%';

这是结果

ACCOUNT_ID  STREET NAME       BEFORE SPACE        AFTER SPACE
1           Far Farm          Far                 Far
2           3 3 Station Road  3                   3

远距离农场不应该出现,因为我只设置了类似的数字。但是确实如此。

2 个答案:

答案 0 :(得分:0)

也许是这样?

const data = JSON.parse(localStorage.getItem('storedText'));

答案 1 :(得分:0)

假设您想在开头匹配一个数字,然后是一个空格,然后再匹配一个相同的数字,则可以使用

CREATE PROCEDURE `Analysis`()
BEGIN
declare v_date datetime;
declare v_sensor varchar(50);
DECLARE datecursHandler,sensorCursHandler BOOLEAN DEFAULT FALSE;

Block1: BEGIN 
declare datecursor CURSOR for 
select  distinct date from dateTable;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET datecursHandler = TRUE;

select  distinct date from dateTable; #what is the result set you are getting?

Open datecursor;
datecurs: loop

FETCH datecursor into v_date;
IF datecursHandler THEN
        LEAVE datecurs;
END IF;

        Block2: BEGIN 

        declare sensorCursor CURSOR for
        select distinct sensor from sensorTable ;
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET sensorCursHandler = TRUE;

        Open sensorCursor;
        senscurs: loop
        FETCH  sensorCursor into v_sensor;

          IF sensorCursHandler THEN
    SET sensorCursHandler  = false;
       LEAVE senscurs;
          END IF;

        Insert into temptable(
        sensorValue,
        DateID,
        TimeID, 
        TotalCount,
        TotalDistinctCount
        )
        SELECT 
            sensor AS sensorValue,
            DATE_FORMAT(firstdate, '%Y%m%d') AS DateID,
            HOUR(firstdate) + 1 AS TimeID,
            COUNT(*) AS totalcount,
            COUNT(DISTINCT sensor) AS sensordistinctcount
        FROM
            (SELECT 
                    sensor AS sensor,
                    first_seen AS DeviceFirstSeen,
                    last_seen AS DeviceLastSeen,
                    DATE_FORMAT(FROM_UNIXTIME(first_seen), '%Y/%m/%d %k:%i:%s.%f') AS firstdate,
                    DATE_FORMAT(FROM_UNIXTIME(last_seen), '%Y/%m/%d %k:%i:%s.%f') AS lastdate,          
            FROM
                sensorTable
            INNER JOIN sensorTable2 ON sensorTable.ID = sensorTable2.ID
            WHERE sensorTable.DeviceFirstSeen BETWEEN date_format(date_sub(date,interval 1 day),'%Y-%m-%d 15:00:00') AND date_format(date,'%Y-%m-%d 14:59:59')) a
        GROUP BY DATE_FORMAT(firstdate, '%Y%m%d') , HOUR(firstdate) + 1;

        end loop senscurs;
        close sensorCursor;
        END Block2;

END loop datecurs;
close datecursor;
END Block1;
END

DEMO