在我意识到存在重新验证对象的过程(SYSPROC.ADMIN_REVALIDATE_DB_OBJECTS)之前,我编写了自己的过程。现在,我尝试将其替换为标准的,但似乎对 SYSPROC.ADMIN_REVALIDATE_DB_OBJECTS 的调用破坏了我正在循环的游标。旧程序示例:
db2 -td@ +c "BEGIN FOR v AS c1 CURSOR FOR SELECT SCHEMANAME FROM NYA.VALIDATION_SCHEMAS DO CALL TOOLBOX.COMPILE_SCHEMA2(v.schemaname); END FOR; END @"
DB20000I The SQL command completed successfully.
使用 ADMISN_REVALIDATE_DB_OBJECTS 的示例
db2 "CALL SYSPROC.ADMIN_REVALIDATE_DB_OBJECTS(object_schema=>'TMP')"
Return Status = 0
db2 "CALL SYSPROC.ADMIN_REVALIDATE_DB_OBJECTS(object_schema=>'TMP')"
Return Status = 0
尝试在光标上循环使用它:
db2 -td@ +c "BEGIN FOR v AS c1 CURSOR FOR SELECT SCHEMANAME FROM NYA.VALIDATION_SCHEMAS DO CALL SYSPROC.ADMIN_REVALIDATE_DB_OBJECTS(object_schema=>v.schemaname); END FOR; END @"
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0501N The cursor specified in a FETCH statement or CLOSE statement is not
open or a cursor variable in a cursor scalar function reference is not open.
SQLSTATE=24501
请注意,它对硬连接架构没有帮助:
db2 -td@ +c "BEGIN FOR v AS c1 CURSOR FOR SELECT SCHEMANAME FROM NYA.VALIDATION_SCHEMAS DO CALL SYSPROC.ADMIN_REVALIDATE_DB_OBJECTS(object_schema=>'TMP')
[...]
也会产生错误。我尝试了在光标上循环的变体:
BEGIN
DECLARE s VARCHAR(128);
DECLARE v_at_end INTEGER default 0;
DECLARE not_found CONDITION FOR SQLSTATE '02000';
DECLARE C1 CURSOR for
SELECT SCHEMANAME FROM NYA.VALIDATION_SCHEMAS;
DECLARE CONTINUE HANDLER FOR not_found SET v_at_end = 1 ;
OPEN C1;
fetch_loop:
LOOP
FETCH FROM C1 INTO s;
IF v_at_end <>0 THEN LEAVE fetch_loop; END IF;
CALL SYSPROC.ADMIN_REVALIDATE_DB_OBJECTS(object_schema=>s);
END LOOP;
CLOSE C1;
END
@
但它也不起作用。任何线索,需要做什么才能在循环中调用 ADMIN_REVALIDATE_DB_OBJECTS ?
因此,必须声明游标
WITH HOLD
以使其在提交之间保持有效。