所有由小于固定数字的数字组成的表格
All tables consisting of numbers less than a fixed number
我试图找出所有 table,其中 table 名称由小于固定数字 16284961 的数字组成下划线,例如 LOG_16282961.
示例 User_segments table:
Segment_name Bytes
---------------------------------------
LOG_16282961 34
BAL1_16282961 78
BIN$xIDte/qXAFbgU4IeBEeQpw==[=10=] 12
EXCH_16282961 28
C$_0LOG_16282961 17
LOG_16283961 89
BAL1_16283961 10
BIN$xIDte/qWAFbgU4IeBEeQpw==[=10=] 19
EXCH_16283961 90
C$_0LOG_16283961 45
LOG_16284961 21
BAL1_16284961 81
BIN$w1RLAvSeAWjgU4IeBEe2Mw==[=10=] 33
EXCH_16284961 67
C$_0LOG_16284961 39
.......................................
.......................................
预期输出:
Segment_name Bytes
----------------------
LOG_16282961 34
BAL1_16282961 78
EXCH_16282961 28
C$_0LOG_16282961 17
LOG_16283961 89
BAL1_16283961 10
EXCH_16283961 90
C$_0LOG_16283961 45
.......................
.......................
查询:
SELECT segment_name, bytes/1024/1024 AS "SIZE in MB" FROM user_segments WHERE segment_type='TABLE' AND to_number(regexp_substr(segment_name, '[0-9]+')) < 16284961;
使用上面的查询,虽然我得到了我的结果,但另外它还包括以下 tables,它们在我的输出中不是必需的:
BIN$xIDte/qXAFbgU4IeBEeQpw==[=13=] 12
BIN$xIDte/qWAFbgU4IeBEeQpw==[=13=] 19
BIN$w1RLAvSeAWjgU4IeBEe2Mw==[=13=] 33
能否请您帮助修复我的查询以获得所需的输出?谢谢
如果您编写的查询 有效,只需省略您不需要的表格即可。你提到的那些已经丢弃,现在在回收站。因此,在 运行 查询之前 purge recyclebin
,或者使用附加条件,例如
SELECT segment_name, bytes / 1024 / 1024 AS "SIZE in MB"
FROM user_segments
WHERE segment_type = 'TABLE'
AND substr(segment_name, 1, 4) <> 'BIN$' --> this
AND TO_NUMBER (REGEXP_SUBSTR (segment_name, '[0-9]+')) < 16284961;
这是一种方法 - 使用 regexp_substr
来隔离输入字符串末尾的一个或多个连续数字,前提是紧接其前的是下划线。 (如果字符串不具有该结构,regexp_substr
returns null
并且过滤条件变为 null < [something]
,永远不会是 true
。)
创建模型 table 进行测试:
create table test_data (segment_name, bytes) as
select 'LOG_16282961' , 34 from dual union all
select 'BAL1_16282961' , 78 from dual union all
select 'BIN$xIDte/qXAFbgU4IeBEeQpw==[=10=]', 12 from dual union all
select 'EXCH_16282961' , 28 from dual union all
select 'C$_0LOG_16282961' , 17 from dual union all
select 'LOG_16283961' , 89 from dual union all
select 'BAL1_16283961' , 10 from dual union all
select 'BIN$xIDte/qWAFbgU4IeBEeQpw==[=10=]', 19 from dual union all
select 'EXCH_16283961' , 90 from dual union all
select 'C$_0LOG_16283961' , 45 from dual union all
select 'LOG_16284961' , 21 from dual union all
select 'BAL1_16284961' , 81 from dual union all
select 'BIN$w1RLAvSeAWjgU4IeBEe2Mw==[=10=]', 33 from dual union all
select 'EXCH_16284961' , 67 from dual union all
select 'C$_0LOG_16284961' , 39 from dual
;
查询和输出:
select *
from test_data
where to_number(regexp_substr(segment_name, '_(\d+)$', 1, 1, null, 1))
< 16284961
;
SEGMENT_NAME BYTES
------------------------------ ----------
LOG_16282961 34
BAL1_16282961 78
EXCH_16282961 28
C$_0LOG_16282961 17
LOG_16283961 89
BAL1_16283961 10
EXCH_16283961 90
C$_0LOG_16283961 45
我试图找出所有 table,其中 table 名称由小于固定数字 16284961 的数字组成下划线,例如 LOG_16282961.
示例 User_segments table:
Segment_name Bytes
---------------------------------------
LOG_16282961 34
BAL1_16282961 78
BIN$xIDte/qXAFbgU4IeBEeQpw==[=10=] 12
EXCH_16282961 28
C$_0LOG_16282961 17
LOG_16283961 89
BAL1_16283961 10
BIN$xIDte/qWAFbgU4IeBEeQpw==[=10=] 19
EXCH_16283961 90
C$_0LOG_16283961 45
LOG_16284961 21
BAL1_16284961 81
BIN$w1RLAvSeAWjgU4IeBEe2Mw==[=10=] 33
EXCH_16284961 67
C$_0LOG_16284961 39
.......................................
.......................................
预期输出:
Segment_name Bytes
----------------------
LOG_16282961 34
BAL1_16282961 78
EXCH_16282961 28
C$_0LOG_16282961 17
LOG_16283961 89
BAL1_16283961 10
EXCH_16283961 90
C$_0LOG_16283961 45
.......................
.......................
查询:
SELECT segment_name, bytes/1024/1024 AS "SIZE in MB" FROM user_segments WHERE segment_type='TABLE' AND to_number(regexp_substr(segment_name, '[0-9]+')) < 16284961;
使用上面的查询,虽然我得到了我的结果,但另外它还包括以下 tables,它们在我的输出中不是必需的:
BIN$xIDte/qXAFbgU4IeBEeQpw==[=13=] 12
BIN$xIDte/qWAFbgU4IeBEeQpw==[=13=] 19
BIN$w1RLAvSeAWjgU4IeBEe2Mw==[=13=] 33
能否请您帮助修复我的查询以获得所需的输出?谢谢
如果您编写的查询 有效,只需省略您不需要的表格即可。你提到的那些已经丢弃,现在在回收站。因此,在 运行 查询之前 purge recyclebin
,或者使用附加条件,例如
SELECT segment_name, bytes / 1024 / 1024 AS "SIZE in MB"
FROM user_segments
WHERE segment_type = 'TABLE'
AND substr(segment_name, 1, 4) <> 'BIN$' --> this
AND TO_NUMBER (REGEXP_SUBSTR (segment_name, '[0-9]+')) < 16284961;
这是一种方法 - 使用 regexp_substr
来隔离输入字符串末尾的一个或多个连续数字,前提是紧接其前的是下划线。 (如果字符串不具有该结构,regexp_substr
returns null
并且过滤条件变为 null < [something]
,永远不会是 true
。)
创建模型 table 进行测试:
create table test_data (segment_name, bytes) as
select 'LOG_16282961' , 34 from dual union all
select 'BAL1_16282961' , 78 from dual union all
select 'BIN$xIDte/qXAFbgU4IeBEeQpw==[=10=]', 12 from dual union all
select 'EXCH_16282961' , 28 from dual union all
select 'C$_0LOG_16282961' , 17 from dual union all
select 'LOG_16283961' , 89 from dual union all
select 'BAL1_16283961' , 10 from dual union all
select 'BIN$xIDte/qWAFbgU4IeBEeQpw==[=10=]', 19 from dual union all
select 'EXCH_16283961' , 90 from dual union all
select 'C$_0LOG_16283961' , 45 from dual union all
select 'LOG_16284961' , 21 from dual union all
select 'BAL1_16284961' , 81 from dual union all
select 'BIN$w1RLAvSeAWjgU4IeBEe2Mw==[=10=]', 33 from dual union all
select 'EXCH_16284961' , 67 from dual union all
select 'C$_0LOG_16284961' , 39 from dual
;
查询和输出:
select *
from test_data
where to_number(regexp_substr(segment_name, '_(\d+)$', 1, 1, null, 1))
< 16284961
;
SEGMENT_NAME BYTES
------------------------------ ----------
LOG_16282961 34
BAL1_16282961 78
EXCH_16282961 28
C$_0LOG_16282961 17
LOG_16283961 89
BAL1_16283961 10
EXCH_16283961 90
C$_0LOG_16283961 45