[20221216]建立修改表統計資訊minmaxtab.sql指令碼.txt
[20221216]建立修改表統計資訊minmaxtab.sql指令碼.txt
--//修改表欄位的最大最小為NULL.
$ cat minmaxtab.sql
set verify off
set termout 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,
nvl(upper(CASE WHEN INSTR('&1','.') > 0 THEN
UPPER(SUBSTR('&1',1,INSTR('&1','.')-1))
ELSE
user
END),user) v_owner
from dual;
set termout on
prompt
prompt modify table:&1 column=&2 stats min and max = NULL
prompt input argument list : owner.table_name column_name
prompt
DECLARE
CURSOR c1
IS
SELECT *
FROM all_tab_col_statistics
WHERE owner = upper('&&v_owner')
AND table_name = upper('&&v_table')
AND column_name = upper('&&2')
AND histogram = 'NONE'
AND last_analyzed IS NOT NULL;
v_num_distinct all_tab_col_statistics.num_distinct%TYPE;
z_distcnt NUMBER;
z_density NUMBER;
z_nullcnt NUMBER;
z_srec DBMS_STATS.statrec;
z_avgclen NUMBER;
BEGIN
FOR r IN c1
LOOP
DBMS_STATS.get_column_stats
(
ownname => r.owner
,tabname => r.table_name
,colname => r.column_name
,distcnt => z_distcnt
,density => z_density
,nullcnt => z_nullcnt
,srec => z_srec
,avgclen => z_avgclen
);
DBMS_STATS.delete_column_stats
(
ownname => r.owner
,tabname => r.table_name
,colname => r.column_name
,cascade_parts => TRUE
,no_invalidate => TRUE
,force => TRUE
);
z_srec.minval := NULL;
z_srec.maxval := NULL;
IF r.num_distinct = 1
THEN
v_num_distinct := 1 + 1e-14;
ELSE
v_num_distinct := r.num_distinct;
END IF;
IF r.num_distinct <> 0
THEN
DBMS_STATS.set_column_stats
(
ownname => r.owner
,tabname => r.table_name
,colname => r.column_name
,distcnt => v_num_distinct
,density => 1 / v_num_distinct
,nullcnt => r.num_nulls
,srec => z_srec -- No HIGH_VALUE/LOW_VALUE
,avgclen => r.avg_col_len
,no_invalidate => FALSE
,force => TRUE
);
END IF;
END LOOP;
END;
/
1.環境:
SCOTT@test01p> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.2.0.1.0 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
2.測試:
SCOTT@test01p> @ descz scott.empx HIREDATE
eXtended describe of scott.empx
DISPLAY TABLE_NAME OF COLUMN_NAME INFORMATION.
INPUT OWNER.TABLE_NAME <filters>
SAMPLE : @ desczz TABLE_NAME column_name1,column_name2
IF NOT INPUT <filters> ,USE "" or 1=1 or 1.
Sample Distinct Number Number
Owner Table_Name Size LAST_ANALYZED Col# Column Name Null? Type Values Density Nulls HISTOGRAM Buckets Low_value High_value
---------- -------------------- -------------- ------------------- ---- -------------------- ---------- -------------------- ------------ -------------- ---------- --------------- ------- ---------------------------------------- ----------------------------------------
SCOTT EMPX 14 2022-10-10 20:40:34 5 HIREDATE TIMESTAMP(6)(11) 13 .07692307692 0 1 1972-10-22 20:39:27. 2022-10-10 20:35:42.536000000
SCOTT@test01p> @ minmaxtab scott.empx hiredate
modify table:scott.empx column=hiredate stats min and max = NULL
input argument list : owner.table_name column_name
SCOTT@test01p> @ descz scott.empx HIREDATE
eXtended describe of scott.empx
DISPLAY TABLE_NAME OF COLUMN_NAME INFORMATION.
INPUT OWNER.TABLE_NAME <filters>
SAMPLE : @ desczz TABLE_NAME column_name1,column_name2
IF NOT INPUT <filters> ,USE "" or 1=1 or 1.
Sample Distinct Number Number
Owner Table_Name Size LAST_ANALYZED Col# Column Name Null? Type Values Density Nulls HISTOGRAM Buckets Low_value High_value
---------- -------------------- -------------- ------------------- ---- -------------------- ---------- -------------------- ------------ -------------- ---------- --------------- ------- ---------------------------------------- ----------------------------------------
SCOTT EMPX 2023-01-17 22:08:06 5 HIREDATE TIMESTAMP(6)(11) 13 .07692307692 0 1 -- ::. -- ::.
--//已經清空了最大最小值.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2932709/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20221216]建立修改表統計資訊modtab.sql指令碼.txtSQL指令碼
- [20221216]建立修改表欄位統計資訊modcol.sql指令碼.txtSQL指令碼
- python指令碼批次建立資料表Python指令碼
- [20221012]修改統計資訊最佳化sql語句.txtSQL
- MySQL對所有表收集統計資訊(Python 2指令碼)MySqlPython指令碼
- [20190510]快速建立執行指令碼.txt指令碼
- Oracle運維指令碼-收集統計資訊Oracle運維指令碼
- [20230210]建立完善swcnm.sql指令碼.txtSQL指令碼
- 【TABLE】Oracle表資訊收集指令碼Oracle指令碼
- 【STAT】Oracle 表統計資訊被鎖,如何建立索引Oracle索引
- [20241114]建立完善ext_kglob.sh指令碼.txt指令碼
- 修改oracle 的統計資訊Oracle
- ORACLE表統計資訊與列統計資訊、索引統計資訊Oracle索引
- [20230302]建立完善tpt o2.sql指令碼.txtSQL指令碼
- [20230203]建立完善sp1x.sql指令碼.txtSQL指令碼
- [20231204]建立監測索引ind_m.sql指令碼.txt索引SQL指令碼
- Shell 系統資訊監控指令碼指令碼
- 資料統計指令碼(彙總)指令碼
- [20181024]修改awr收集資訊設定.txt
- 如何在linux中建立特定的指令碼註釋資訊Linux指令碼
- LLIconVersioning-一個可以建立app版本資訊icon的指令碼APP指令碼
- Oracle 建立表空間和使用者指令碼Oracle指令碼
- [20210506]完善tix指令碼.txt指令碼
- [20201202]完善sosi指令碼.txt指令碼
- [20190505]關於latch 一些統計資訊.txt
- 【STATS】Oracle遷移表統計資訊Oracle
- 資料字典和固定表統計資訊更新
- [MYSQL][1]建立,修改,刪除表MySql
- [20180322]檢視統計資訊的儲存歷史.txt
- 【統計資訊】Oracle統計資訊Oracle
- [20210623]完善清除aud指令碼.txt指令碼
- [20181108]with temp as 建立臨時表嗎.txt
- 【資訊採集】IBM AIX系統硬體資訊檢視命令(shell指令碼)IBMAI指令碼
- 簡單介紹Shell指令碼之檔案批次建立與修改的方法指令碼
- [20220421]完善查詢表分析的歷史th.sql指令碼.txtSQL指令碼
- 使用KPI儀表板,建立完整的資訊資料生態系統KPI
- [20201106]11g修改表無需修改許可權.txt
- [20190410]dg建立臨時表檔案資料檔案.txt