我試圖找出所有的表,其中的表名由少于固定數字16284961的數字組成,前面是下劃線,例如LOG_16282961。
示例 User_segments 表:
Segment_name Bytes
---------------------------------------
LOG_1628296134
BAL1_16282961 78 78
BIN$xIDte/qXAFbgU4IeBEeQpw==$0 12
EXCH_16282961 28
C$_0LOG_16282961 17 16282961
LOG_16283961 89 89
BAL1_1628396110
BIN$xIDte/qWAFbgU4IeBEeQpw==$0 19
EXCH_16283961 90
C$_0LOG_16283961 45 45
LOG_16284961 21 21
BAL1_16284961 81==$0 33
EXCH_16284961 67 33
C$_0LOG_1628496139
.......................................
.......................................
預期輸出:
Segment_name Bytes
----------------------
LOG_1628296134
BAL1_16282961 78 78
EXCH_16282961 28 28
C$_0LOG_16282961 17 16282961
LOG_16283961 89 89
BAL1_16283961 10 10
EXCH_16283961 90 90
C$_0LOG_16283961 45 45
.......................
.......................
查詢:
SELECT segment_name, bytes/1024/ AS "SIZE in MB" FROM user_segments WHERE segment_type='TABLE' AND to_number(regexp_substr(segment_name, '[0-9] ')) < 16284961;
使用上述查詢,雖然我得到了我的結果,但另外它還包括以下表格,這些表格在我的輸出中是不需要的:
BIN$xIDte/qXAFbgU4IeBEeQpw==$0 12
BIN$xIDte/qWAFbgU4IeBEeQpw==$0 19
BIN$w1RLAvSeAWjgU4IeBEe2Mw==$0 33
能否請您幫助修改我的查詢,以獲得所需的輸出?謝謝。
uj5u.com熱心網友回復:
如果你寫的查詢有效,只需省略你不需要的表。你提到的那些表已經被洗掉了,現在在回收站。所以,要么在運行查詢前purge recyclebin,要么使用額外的條件,例如
SELECT segment_name, bytes / 1024 / 1024 as "SIZE in MB"
FROM user_segments
WHERE segment_type = 'TABLE'/span>
AND substr(segment_name, 1, 4) <> 'BIN$' -> this
AND TO_NUMBER (REGEXP_SUBSTR (segment_name, '[0-9] '/span>)) < 16284961;
uj5u.com熱心網友回復:
這里有一個方法--使用regexp_substr在輸入字串的末尾分離出一個或多個連續的數字,只有在緊接著下劃線的情況下。(如果字串沒有這種結構,regexp_substr就會回傳null,過濾條件就變成了null < [something],這永遠不會是true。)
創建一個模擬程式。
創建用于測驗的模擬表:
創建用于測驗的模擬表。
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==$0'/span>, 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==$0'/span>, 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==$0'/span>。33 from dual union all
select 'EXCH_16284961' , 67 from dual union all >。
select 'C$_0LOG_16284961' , 39 from double
;
查詢和輸出:
select *
from test_data
where to_number(regexp_substr(segment_name, '_(d )$', 1, 1, null, 1)
< 16284961)
;
segment_name bytes
------------------------------ ----------
LOG_16282961 34 ; segment_name bytesp
BAL1_16282961 78 78
EXCH_16282961 28 28
C$_0LOG_16282961 17 16282961
LOG_16283961 89 89
BAL1_16283961 10 10
EXCH_16283961 90 90
C$_0LOG_1628396145
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/324987.html
標籤:
