0

我有以下运行良好的 oracle 查询

SELECT c.customercode, s.sales_id 
FROM customers c 
LEFT JOIN sales s ON c.customercode = s.sales_id
WHERE c.address IS NOT NULL

它返回的结果看起来像这样:

customercode        sales_id
12345678            456
34534534            678
23423423            X123

我想做的是排除 sales_id 包含除数字字符以外的任何内容的行。所以上面的结果不包括第三行。

4

2 回答 2

4

您可以使用正则表达式。在这种情况下,regexp_like( sales_id, '^[[:digit:]]*$' )

SQL> with x as (select 12345678 code, '456' sales_id from dual union all
  2             select 34534534, '678' from dual union all
  3             select 23423423, 'X123' from dual)
  4  select *
  5    from x
  6   where regexp_like( sales_id, '^[[:digit:]]*$' );

      CODE SALE
---------- ----
  12345678 456
  34534534 678
于 2012-05-09T16:13:04.477 回答
1

TRANSLATE也可以:

WITH q AS (
SELECT '12345678' customercode,'456' sales_id FROM dual
UNION ALL
SELECT '34534534','678' FROM dual
UNION ALL
SELECT '23423423','X123' FROM dual
)
SELECT *
  FROM q
 WHERE TRANSLATE(sales_id,'A1234567890','A') IS NULL;
于 2012-05-09T16:25:00.467 回答