从报告中排除数值
Exclude numeric values from report
我在 table TB_ORDERS
中有一个名为 statu
的字段。
如果字段状态具有数值,我应该从报告中排除该记录 - 只应显示字母顺序。
我该怎么做?
I should exclude that record from report - only alphabetical should be shown.
您可以在过滤谓词中使用 REGEXP_LIKE。
NOT REGEXP_LIKE(status, '[[:digit:]]+')
或者,
NOT REGEXP_LIKE(status, '\d+')
或者,
NOT REGEXP_LIKE(status, '[0-9]+')
例如,
SELECT * FROM TB_ORDERS
WHERE NOT REGEXP_LIKE(status, '[[:digit:]]+');
演示
SQL> WITH TB_ORDERS AS(
2 SELECT 'abc123abc' status FROM dual UNION ALL
3 SELECT 'abcabc' status FROM dual UNION ALL
4 SELECT 'abcabc123' status FROM dual UNION ALL
5 SELECT '123abcabc123' status FROM dual
6 )
7 SELECT * FROM TB_ORDERS
8 WHERE NOT REGEXP_LIKE(status, '[[:digit:]]+');
STATUS
------------
abcabc
SQL>
或者,
SQL> WITH TB_ORDERS AS(
2 SELECT 'abc123abc' status FROM dual UNION ALL
3 SELECT 'abcabc' status FROM dual UNION ALL
4 SELECT 'abcabc123' status FROM dual UNION ALL
5 SELECT '123abcabc123' status FROM dual
6 )
7 SELECT * FROM TB_ORDERS
8 WHERE NOT REGEXP_LIKE(status, '\d+');
STATUS
------------
abcabc
SQL>
或者,
SQL> WITH TB_ORDERS AS(
2 SELECT 'abc123abc' status FROM dual UNION ALL
3 SELECT 'abcabc' status FROM dual UNION ALL
4 SELECT 'abcabc123' status FROM dual UNION ALL
5 SELECT '123abcabc123' status FROM dual
6 )
7 SELECT * FROM TB_ORDERS
8 WHERE NOT REGEXP_LIKE(status, '[0-9]+');
STATUS
------------
abcabc
SQL>
更新 根据 OP 的要求
SQL> WITH TB_ORDERS AS(
2 SELECT '*abc123abc' status FROM dual UNION ALL
3 SELECT 'ab*cabc' status FROM dual UNION ALL
4 SELECT '****' status FROM dual UNION ALL
5 SELECT '123abcabc123' status FROM dual
6 )
7 SELECT * FROM TB_ORDERS
8 WHERE NOT REGEXP_LIKE(status, '[0-9]+');
STATUS
------------
ab*cabc
****
SQL>
我在 table TB_ORDERS
中有一个名为 statu
的字段。
如果字段状态具有数值,我应该从报告中排除该记录 - 只应显示字母顺序。
我该怎么做?
I should exclude that record from report - only alphabetical should be shown.
您可以在过滤谓词中使用 REGEXP_LIKE。
NOT REGEXP_LIKE(status, '[[:digit:]]+')
或者,
NOT REGEXP_LIKE(status, '\d+')
或者,
NOT REGEXP_LIKE(status, '[0-9]+')
例如,
SELECT * FROM TB_ORDERS
WHERE NOT REGEXP_LIKE(status, '[[:digit:]]+');
演示
SQL> WITH TB_ORDERS AS(
2 SELECT 'abc123abc' status FROM dual UNION ALL
3 SELECT 'abcabc' status FROM dual UNION ALL
4 SELECT 'abcabc123' status FROM dual UNION ALL
5 SELECT '123abcabc123' status FROM dual
6 )
7 SELECT * FROM TB_ORDERS
8 WHERE NOT REGEXP_LIKE(status, '[[:digit:]]+');
STATUS
------------
abcabc
SQL>
或者,
SQL> WITH TB_ORDERS AS(
2 SELECT 'abc123abc' status FROM dual UNION ALL
3 SELECT 'abcabc' status FROM dual UNION ALL
4 SELECT 'abcabc123' status FROM dual UNION ALL
5 SELECT '123abcabc123' status FROM dual
6 )
7 SELECT * FROM TB_ORDERS
8 WHERE NOT REGEXP_LIKE(status, '\d+');
STATUS
------------
abcabc
SQL>
或者,
SQL> WITH TB_ORDERS AS(
2 SELECT 'abc123abc' status FROM dual UNION ALL
3 SELECT 'abcabc' status FROM dual UNION ALL
4 SELECT 'abcabc123' status FROM dual UNION ALL
5 SELECT '123abcabc123' status FROM dual
6 )
7 SELECT * FROM TB_ORDERS
8 WHERE NOT REGEXP_LIKE(status, '[0-9]+');
STATUS
------------
abcabc
SQL>
更新 根据 OP 的要求
SQL> WITH TB_ORDERS AS(
2 SELECT '*abc123abc' status FROM dual UNION ALL
3 SELECT 'ab*cabc' status FROM dual UNION ALL
4 SELECT '****' status FROM dual UNION ALL
5 SELECT '123abcabc123' status FROM dual
6 )
7 SELECT * FROM TB_ORDERS
8 WHERE NOT REGEXP_LIKE(status, '[0-9]+');
STATUS
------------
ab*cabc
****
SQL>