sql 编译无效对象
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 编译无效对象相关的知识,希望对你有一定的参考价值。
CREATE OR REPLACE FUNCTION -- Version Control -- Repository path: $HeadURL$ -- Last committed: $Revision$ -- Last changed by: $Author$ -- Last changed date: $Date$ -- File ID: $Id$ Recursive_Validation(pi_func_or_pack_or_all NUMBER) RETURN NUMBER AS var_l_invalid_count NUMBER; var_l_invalid_count_new NUMBER; var_l_validate_command VARCHAR2(500); var_l_compile_count NUMBER := 0; var_l_rowid rowid; var_l_current_object_status VARCHAR2(10); var_l_obj_name VARCHAR2(80); var_l_obj_type VARCHAR2(20); var_l_obj_id NUMBER;BEGIN BEGIN EXECUTE IMMEDIATE ('TRUNCATE TABLE RECURSIVE_VALIDATE_TABLE'); END; WHILE (1 = 1) LOOP BEGIN var_l_compile_count := 0; BEGIN EXECUTE IMMEDIATE ('TRUNCATE TABLE RECURSIVE_VALIDATE_TABLE'); SELECT COUNT(1) INTO var_l_invalid_count FROM USER_OBJECTS WHERE status = 'INVALID'; EXCEPTION WHEN NO_DATA_FOUND THEN NULL; RETURN 0; WHEN OTHERS THEN ora_raiserror(SQLCODE, 'Select Failed from user object in invalid object count', 104); END; BEGIN IF (var_l_invalid_count > 0) THEN BEGIN INSERT INTO RECURSIVE_VALIDATE_TABLE (NAME, OBJ_TYPE, OBJ_ID) SELECT OBJECT_NAME, OBJECT_TYPE, OBJECT_ID FROM USER_OBJECTS WHERE STATUS = 'INVALID'; EXCEPTION WHEN OTHERS THEN ora_raiserror(SQLCODE, 'Insert Failed for RECURSIVE_VALIDATE_TABLE', 127); END; ELSE RETURN 0; END IF; END; WHILE (1 = 1) LOOP BEGIN IF (var_l_invalid_count > 0 and var_l_compile_count <> var_l_invalid_count) THEN BEGIN BEGIN SELECT OBJ_TYPE, NAME, OBJ_ID, ROWID INTO var_l_obj_type, var_l_obj_name, var_l_obj_id, var_l_rowid FROM RECURSIVE_VALIDATE_TABLE WHERE rownum < 2; EXCEPTION WHEN NO_DATA_FOUND THEN NULL; WHEN OTHERS THEN NULL; END; BEGIN IF (var_l_obj_type = 'PACKAGE BODY') THEN var_l_validate_command := 'ALTER ' || 'PACKAGE ' || var_l_obj_name || ' COMPILE' || ' BODY'; ELSIF (var_l_obj_type = 'TYPE BODY') THEN var_l_validate_command := 'ALTER ' || 'TYPE ' || var_l_obj_name || ' COMPILE ' || ' BODY'; ELSE var_l_validate_command := 'ALTER ' || var_l_obj_type || ' ' || var_l_obj_name || ' COMPILE'; END IF; END; BEGIN SELECT STATUS INTO var_l_current_object_status FROM USER_OBJECTS WHERE OBJECT_ID = var_l_obj_id; EXCEPTION WHEN NO_DATA_FOUND THEN ora_raiserror(SQLCODE, 'Object Missing', 190); WHEN OTHERS THEN ora_raiserror(SQLCODE, 'Object Missing', 193); END; IF (var_l_current_object_status = 'INVALID') THEN BEGIN EXECUTE IMMEDIATE (var_l_validate_command); EXCEPTION WHEN OTHERS THEN BEGIN DELETE FROM RECURSIVE_VALIDATE_TABLE WHERE rowid = var_l_rowid; END; END; END IF; BEGIN DELETE FROM RECURSIVE_VALIDATE_TABLE WHERE rowid = var_l_rowid; EXCEPTION WHEN OTHERS THEN ora_raiserror(SQLCODE, 'Delete Failed from RECURSIVE_VALIDATE_TABLE', 218); END; var_l_compile_count := var_l_compile_count + 1; END; ELSE BEGIN EXIT; END; END IF; END; END LOOP; BEGIN SELECT COUNT(1) INTO var_l_invalid_count_new FROM USER_OBJECTS WHERE status = 'INVALID'; END; IF var_l_invalid_count_new = var_l_invalid_count THEN EXIT; END IF; END; END LOOP; EXECUTE IMMEDIATE ('TRUNCATE TABLE RECURSIVE_VALIDATE_TABLE'); RETURN 0;EXCEPTION WHEN others THEN ora_raiserror(SQLCODE, 'Execution of recursive_validate', 1); RETURN 95;END;
以上是关于sql 编译无效对象的主要内容,如果未能解决你的问题,请参考以下文章
雪花; SQL 编译错误:无效的对象类型:GET_DDL 上的“EXTERNAL_TABLE”(“DATABASE”,“MyDb”)