0

我需要找出带有尾随空格的记录。我尝试使用 构建查询Length(rtrim),但它没有返回所需的记录。

例如

abc "
abc       "
abc                                                               "

请协助

4

1 回答 1

5

我认为你在正确的轨道上。以下示例将返回第二个和第三个文本,但不返回第一个。

SELECT * FROM
    (SELECT 'abc' AS text FROM DUAL
     UNION ALL
     SELECT 'abc       ' AS text FROM DUAL
     UNION ALL
     SELECT 'abc                        ' AS text FROM DUAL)
WHERE LENGTH(RTRIM(text)) != LENGTH(text);

或者对于包含可能带有尾随空格的文本YOURTABLE的列的表:YOURCOLUMN

SELECT * FROM
YOURTABLE
WHERE LENGTH(RTRIM(YOURCOLUMN)) != LENGTH(YOURCOLUMN);

如果您也有HORIZONTAL TAB, LINE FEED, 或者CARRIAGE RETURN您可以使用该TRANSLATE函数将这些视为普通空格:

SELECT * FROM
    (SELECT 'abc' AS text FROM DUAL
     UNION ALL
     SELECT 'abc' || CHR(09) AS text FROM DUAL
     UNION ALL
     SELECT 'abc' || CHR(10) AS text FROM DUAL
     UNION ALL
     SELECT 'abc' || CHR(13) AS text FROM DUAL
     UNION ALL
     SELECT 'abc           ' AS text FROM DUAL)
WHERE LENGTH(RTRIM(TRANSLATE(text, CHR(09) || CHR(10) || CHR(13), ' '))) != LENGTH(text);
于 2016-06-20T06:39:16.590 回答