DECLARE
CURSOR TEMP IS SELECT CREDITZS_CODE,ATTRIBUTE_CODE,ATTRIBUTE_INFO_TYPE,T.ID FROM CREDIT_DIRECTORY_ATTRIBUTE T,CREDIT_DIRECTORY_TREE E WHERE T.TREE_ID=E.ID AND ATTRIBUTE_INFO_TYPE=‘number‘AND ATTRIBUTE_CODE IN(‘CF_NR_FK‘,‘CF_NR_WFFF‘);
STR VARCHAR2(100) := ‘‘;
ATT NUMBER;
BEGIN
FOR S IN TEMP LOOP
STR := ‘ALTER TABLE ‘||S.CREDITZS_CODE||‘ MODIFY(‘||S.ATTRIBUTE_CODE||‘ NUMBER(30,4))‘;
ATT :=1;
BEGIN
EXECUTE IMMEDIATE STR ;
EXCEPTION
WHEN OTHERS THEN
ATT :=0;
END;
IF ATT=1 THEN
UPDATE CREDIT_DIRECTORY_ATTRIBUTE SET ATTRIBUTE_PRECISION=4 WHERE ID=S.ID;
END IF ;
END LOOP;
END;
大致解释:1.先查询语句。2.将语句拼接后赋值给STR。3. 正常运行的语句则返回ATT :=1。4.如果有错误数据则跳过错误语句继续执行(EXCEPTION WHEN OTHERS THEN),且返回ATT :=0。 5. 当 ATT=1 时,则执行另外一个语句。