Thanks Lankar.
n_i you'r right, i have a big error in the script, now this is the corrected version... Builds ok, but when i run it, have the followin error.
[IBM][CLI Driver][DB2/NT] SQL0198N The statement string of the PREPARE or EXECUTE IMMEDIATE statement is blank or empty. SQLSTATE=42617
When debug it, stmt variable it's empty, before to
PREPARE S2 FROM stmt;
Any idea?
Thanks in advance.
CREATE PROCEDURE PSFT.Contar ( )
LANGUAGE SQL
BEGIN
DECLARE SQLCODE INTEGER DEFAULT 0;
DECLARE SQLSTATE CHAR(5);
DECLARE vTableName VARCHAR(25);
DECLARE vTableSchema VARCHAR(10);
DECLARE vTableCount INTEGER;
DECLARE stmt varchar(2000);
DECLARE not_found CONDITION FOR SQLSTATE '02000';
DECLARE c1 CURSOR FOR
SELECT tabname, tabschema from syscat.tables where tabschema in ('SY811', 'PD811', 'OL811', 'DD811', 'PS811', 'SVM811');
DECLARE C2 CURSOR FOR S2;
DECLARE CONTINUE HANDLER FOR not_found
SET stmt = '';
-- No Commitment Control
--Set Transaction Isolation Level NC;
Delete from PSFT.COUNTERS;
OPEN c1;
getRows:
LOOP
FETCH c1 INTO vTableName, vTableSchema;
IF SQLCODE = 0 THEN
SET stmt ='SELECT Count(*) FROM ' || vTableSchema || '.' || vTableName;
PREPARE S2 FROM stmt;
OPEN C2;
SET vTableCount = 0;
FETCH C2 INTO vTableCount;
INSERT INTO PSFT.COUNTERS (tableName, tableCount, tableSchema) VALUES (vTableName, vTableCount, vTableSchema);
CLOSE C2;
ELSE
LEAVE getRows;
END IF;
END LOOP getRows;
CLOSE c1;
END