DB2 PL/SQL Example: Runstats
This stored procedure example is performing a runstats on all tables in the database.
The two output parameters are the total number of tables on the database and the number of successful runstats.
The procedure don't have any condition handlers and will stop immediately after an error occurs.
The runstats will be performed by the ADMIN_CMD procedure.
create procedure runstats (out nr_tables integer, out nr_ok integer)
begin
declare SQLCODE integer;
declare stmt varchar(100);
set nr_tables = 0;
set nr_ok = 0;
for line as select tabschema, tabname from syscat.tables where type='T' and tabschema='SPODEN'
do
set nr_tables = nr_tables + 1;
set stmt = 'CALL SYSPROC.ADMIN_CMD (RUNSTATS ON TABLE ' concat rtrim(line.tabschema) concat '.' concat line.tabname concat ')';
execute immediate stmt;
if SQLCODE = 0 then
set nr_ok = nr_ok + 1;
end if;
end for;
end!
The two output parameters are the total number of tables on the database and the number of successful runstats.
The procedure don't have any condition handlers and will stop immediately after an error occurs.
The runstats will be performed by the ADMIN_CMD procedure.
create procedure runstats (out nr_tables integer, out nr_ok integer)
begin
declare SQLCODE integer;
declare stmt varchar(100);
set nr_tables = 0;
set nr_ok = 0;
for line as select tabschema, tabname from syscat.tables where type='T' and tabschema='SPODEN'
do
set nr_tables = nr_tables + 1;
set stmt = 'CALL SYSPROC.ADMIN_CMD (RUNSTATS ON TABLE ' concat rtrim(line.tabschema) concat '.' concat line.tabname concat ')';
execute immediate stmt;
if SQLCODE = 0 then
set nr_ok = nr_ok + 1;
end if;
end for;
end!
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22661144/viewspace-1477096/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- DB2 PL/SQL Example: Sleep ProcedureDB2SQL
- DB2 PL/SQL Example: bonus_increaseDB2SQL
- db2 reorg,runstatsDB2
- DB2 PL/SQL How much reorganisations are recommended on a specific schemaDB2SQL
- SQL最佳化好助手:RunstatsSQL
- PL/SQLSQL
- SQL&PL/SQL (轉)SQL
- PL/SQL 宣告SQL
- PL/SQL cursorSQL
- PL/SQL打包SQL
- PL/SQL DEVSQLdev
- Oracle PL/SQLOracleSQL
- 使用PL/Scope分析PL/SQL程式碼SQL
- PLSQL Language Reference-PL/SQL概覽-PL/SQL架構SQL架構
- [PL/SQL]10g PL/SQL學習筆記(一)SQL筆記
- [PL/SQL]10g PL/SQL學習筆記(二)SQL筆記
- [PL/SQL]10g PL/SQL學習筆記(三)SQL筆記
- PL/SQL 迴圈SQL
- PL/SQL 遊標SQL
- PL/SQL 運算子SQL
- PL/SQL 條件SQL
- pl/sql to_dateSQL
- PL/SQL 基礎SQL
- Oracle PL/SQL INDICESOracleSQL
- PL/SQl Developer使用SQLDeveloper
- pl/sql陣列SQL陣列
- pl/sql練習SQL
- oracle PL/SQL示例OracleSQL
- 淺談pl/sqlSQL
- PL/SQL 索引表SQL索引
- pl/sql 練習SQL
- [pl sql] where current ofSQL
- pl/sql功能特性SQL
- PL/SQL Developer 使用SQLDeveloper
- PL/SQL小結SQL
- steven's pl/sqlSQL
- PL/SQL入門SQL
- PL/SQL 設定SQL