[20251124]建立完善tpt的tab2.sql脚本.txt --//在tab2.sql脚本的基础上修改支持正则表达式,这样查询时更加方便灵活。 $ cat tpt/tab2z.sql -- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com -- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions. column tab_owner heading OWNER format a20 column tab_table_name heading TABLE_NAME format a30 column tab_type heading TYPE format a4 column tab_num_rows heading NUM_ROWS format 99999999999 column tab_blocks heading BLOCKS format 999999999999 column tab_empty_blocks heading EMPTY format 99999999 column tab_avg_space heading AVGSPC format 99999 column tab_avg_row_len heading ROWLEN format 99999 set term off column v_owner new_value v_owner column v_table new_value v_table select upper(CASE WHEN INSTR('&1','.') > 0 THEN SUBSTR('&1',INSTR('&1','.')+1) ELSE '&1' END ) v_table, CASE WHEN INSTR('&1','.') > 0 THEN UPPER(SUBSTR('&1',1,INSTR('&1','.')-1)) ELSE user END v_owner from dual; select decode('&v_table',null,'*',replace('&v_table','%','*')) v_table ,replace('&v_owner','%','*') v_owner from dual; set term on prompt Show tables matching condition "&1" (if schema is not specified then current user's tables only are shown)... select owner tab_owner, table_name tab_table_name, case when cluster_name is not null then 'CLU' when partitioned = 'NO' and iot_name is not null then 'IOT' when partitioned = 'YES' and iot_name is not null then 'PIOT' when partitioned = 'NO' and iot_name is null then 'TAB' when partitioned = 'YES' and iot_name is null then 'PTAB' when temporary = 'Y' then 'TEMP' else 'OTHR' end tab_type, num_rows tab_num_rows, blocks tab_blocks, empty_blocks tab_empty_blocks, avg_space tab_avg_space, -- chain_cnt tab_chain_cnt, avg_row_len tab_avg_row_len, -- avg_space_freelist_blocks tab_avg_space_freelist_blocks, -- num_freelist_blocks tab_num_freelist_blocks, -- sample_size tab_sample_size, last_analyzed tab_last_analyzed, degree, compression -- , compress_for -- 11.2 from dba_tables where -- upper(table_name) LIKE -- upper(CASE -- WHEN INSTR('&1','.') > 0 THEN -- SUBSTR('&1',INSTR('&1','.')+1) -- ELSE -- '&1' -- END -- ) ESCAPE '\' --AND owner LIKE -- CASE WHEN INSTR('&1','.') > 0 THEN -- UPPER(SUBSTR('&1',1,INSTR('&1','.')-1)) -- ELSE -- user -- END ESCAPE '\' regexp_like (table_name ,'&v_table') and regexp_like (owner ,'&v_owner') / --//许多情况可能还是习惯性输入%,为了更加灵活可以使用%代替*. --//测试: SCOTT@book01p> @ tab2z sys|scott.^ts\$|t[1|2] Show tables matching condition "sys|scott.^ts\$|t[1|2]" (if schema is not specified then current user's tables only are shown)... OWNER TABLE_NAME TYPE NUM_ROWS BLOCKS EMPTY AVGSPC ROWLEN TAB_LAST_ANALYZED DEGREE COMPRESS ----- ---------- ---- ------------ ------------- --------- ------ ------ ------------------- ---------- -------- SYS TS$ CLU 6 7 0 0 90 2024-08-11 08:50:50 1 DISABLED SCOTT T1 TAB 4 4 0 0 20 2025-11-18 08:54:33 1 DISABLED SCOTT T2 TAB 4 5 0 0 9 2025-11-24 09:02:14 1 DISABLED --//显示ts$,里面的$要转义一下。 SCOTT@book01p> @ tab2z scott. Show tables matching condition "scott." (if schema is not specified then current user's tables only are shown)... OWNER TABLE_NAME TYPE NUM_ROWS BLOCKS EMPTY AVGSPC ROWLEN TAB_LAST_ANALYZED DEGREE COMPRESS ----- ---------- ---- ------------ ------------- --------- ------ ------ ------------------- ---------- -------- SCOTT BONUS TAB 0 0 0 0 0 2024-08-18 09:02:54 1 DISABLED SCOTT DEPT TAB 4 5 0 0 20 2025-11-23 16:04:28 1 DISABLED SCOTT EMP TAB 14 5 0 0 38 2025-08-13 16:55:21 1 DISABLED SCOTT JOB_TIMES TAB 0 5 0 0 0 2025-10-30 10:27:54 1 DISABLED SCOTT SALGRADE TAB 5 5 0 0 10 2024-08-18 09:02:55 1 DISABLED SCOTT T1 TAB 4 4 0 0 20 2025-11-18 08:54:33 1 DISABLED SCOTT T2 TAB 4 5 0 0 9 2025-11-24 09:02:14 1 DISABLED SCOTT T3 TAB 4 4 0 0 12 2025-11-24 08:53:01 1 DISABLED 8 rows selected. SCOTT@book01p> @ tab2z t% Show tables matching condition "t%" (if schema is not specified then current user's tables only are shown)... OWNER TABLE_NAME TYPE NUM_ROWS BLOCKS EMPTY AVGSPC ROWLEN TAB_LAST_ANALYZED DEGREE COMPRESS ----- ---------- ---- ------------ ------------- --------- ------ ------ ------------------- ---------- -------- SCOTT BONUS TAB 0 0 0 0 0 2024-08-18 09:02:54 1 DISABLED SCOTT DEPT TAB 4 5 0 0 20 2025-11-23 16:04:28 1 DISABLED SCOTT EMP TAB 14 5 0 0 38 2025-08-13 16:55:21 1 DISABLED SCOTT JOB_TIMES TAB 0 5 0 0 0 2025-10-30 10:27:54 1 DISABLED SCOTT SALGRADE TAB 5 5 0 0 10 2024-08-18 09:02:55 1 DISABLED SCOTT T1 TAB 4 4 0 0 20 2025-11-18 08:54:33 1 DISABLED SCOTT T2 TAB 4 5 0 0 9 2025-11-24 09:02:14 1 DISABLED SCOTT T3 TAB 4 4 0 0 12 2025-11-24 08:53:01 1 DISABLED 8 rows selected. SCOTT@book01p> define v_table DEFINE V_TABLE = "T*" (CHAR) --//查询T*,这里*表示0次或者多次出现,这样输出全部。 --//查询含有T的表,直接输入T就可以了。 --//也可以输入t+,+表示1或者多次出现。 SCOTT@book01p> rename t3 to tt; Table renamed. SCOTT@book01p> @ tab2z t+ Show tables matching condition "t+" (if schema is not specified then current user's tables only are shown)... OWNER TABLE_NAME TYPE NUM_ROWS BLOCKS EMPTY AVGSPC ROWLEN TAB_LAST_ANALYZED DEGREE COMPRESS ----- ---------- ---- ------------ ------------- --------- ------ ------ ------------------- ---------- -------- SCOTT DEPT TAB 4 5 0 0 20 2025-11-23 16:04:28 1 DISABLED SCOTT JOB_TIMES TAB 0 5 0 0 0 2025-10-30 10:27:54 1 DISABLED SCOTT T1 TAB 4 4 0 0 20 2025-11-18 08:54:33 1 DISABLED SCOTT T2 TAB 4 5 0 0 9 2025-11-24 09:02:14 1 DISABLED SCOTT TT TAB 4 4 0 0 12 2025-11-24 08:53:01 1 DISABLED SCOTT@book01p> @ tab2z ^t+ Show tables matching condition "^t+" (if schema is not specified then current user's tables only are shown)... OWNER TABLE_NAME TYPE NUM_ROWS BLOCKS EMPTY AVGSPC ROWLEN TAB_LAST_ANALYZED DEGREE COMPRESS ----- ---------- ---- ------------ ------------- --------- ------ ------ ------------------- ---------- -------- SCOTT T1 TAB 4 4 0 0 20 2025-11-18 08:54:33 1 DISABLED SCOTT T2 TAB 4 5 0 0 9 2025-11-24 09:02:14 1 DISABLED SCOTT TT TAB 4 4 0 0 12 2025-11-24 08:53:01 1 DISABLED SCOTT@book01p> @ tab2z t{2} Show tables matching condition "t{2}" (if schema is not specified then current user's tables only are shown)... OWNER TABLE_NAME TYPE NUM_ROWS BLOCKS EMPTY AVGSPC ROWLEN TAB_LAST_ANALYZED DEGREE COMPRESS ----- ---------- ---- ------------ ------------- --------- ------ ------ ------------------- ---------- -------- SCOTT TT TAB 4 4 0 0 12 2025-11-24 08:53:01 1 DISABLED SCOTT@book01p> @ tab2z dept|emp|^t[1|2] Show tables matching condition "dept|emp|^t[1|2]" (if schema is not specified then current user's tables only are shown)... OWNER TABLE_NAME TYPE NUM_ROWS BLOCKS EMPTY AVGSPC ROWLEN TAB_LAST_ANALYZED DEGREE COMPRESS ----- ---------- ---- ------------ ------------- --------- ------ ------ ------------------- ---------- -------- SCOTT DEPT TAB 4 5 0 0 20 2025-11-23 16:04:28 1 DISABLED SCOTT EMP TAB 14 5 0 0 38 2025-08-13 16:55:21 1 DISABLED SCOTT T1 TAB 4 4 0 0 20 2025-11-18 08:54:33 1 DISABLED SCOTT T2 TAB 4 5 0 0 9 2025-11-24 09:02:14 1 DISABLED --//只要输入正则表达式,可以非常容易组合输出自己需要的结果。
[20251124]建立完善tpt的tab2.sql脚本.txt
来源:这里教程网
时间:2026-03-03 22:56:11
作者:
编辑推荐:
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- 四川冷链物流升级加码 以数智化筑牢连锁餐饮冻品供应链
四川冷链物流升级加码 以数智化筑牢连锁餐饮冻品供应链
26-03-03 - MongoDB数据库:现代应用开发的首选数据存储平台
MongoDB数据库:现代应用开发的首选数据存储平台
26-03-03 - Oracle的锁机制:Enqueue详解
Oracle的锁机制:Enqueue详解
26-03-03 - 2025年精选数据治理厂家推荐榜单:行业核心发展趋势
2025年精选数据治理厂家推荐榜单:行业核心发展趋势
26-03-03 - 2025年数据资产管理平台排行榜:国产崛起与国际格局下的品牌全景
2025年数据资产管理平台排行榜:国产崛起与国际格局下的品牌全景
26-03-03 - 【服务器数据恢复】华为云Stack虚拟化快照损坏导致民生数据丢失数据恢复案例
- 国际配售超额认购40余倍,创新实业“高成长+现金牛”双爆点
国际配售超额认购40余倍,创新实业“高成长+现金牛”双爆点
26-03-03 - 实战系列之向量索引覆盖字段优化
实战系列之向量索引覆盖字段优化
26-03-03 - 数据库管理-第389期 Oracle SQLcl MCP Server实战(20251113)
- 走向全球,安得智联如何为中国制造打造新通路
走向全球,安得智联如何为中国制造打造新通路
26-03-03
