日期:2014-05-17 浏览次数:21168 次
--执行SQL语句 PROCEDURE P_EXECUTE_SQL(A_OBJECT_NAME VARCHAR2, A_CONTENT VARCHAR2, A_SQL CLOB) IS V_CURSOR NUMBER; V_INDEX NUMBER := 1; V_COUNT_EXECUTE NUMBER; --V_SQL_SUB VARCHAR2(32767); V_SQLS DBMS_SQL.VARCHAR2A; BEGIN IF A_SQL IS NOT NULL THEN /*EXECUTE IMMEDIATE V_SQL_SUB; P_WRITE_LOG_SEGMENTS(A_OBJECT_NAME, A_CONTENT || '(' || SQL%ROWCOUNT || ')', A_SQL); COMMIT;*/ --生成要执行的动态SQL BEGIN LOOP V_SQLS(V_INDEX) := SUBSTR(A_SQL, (V_INDEX - 1) * 4000 + 1, 4000); IF LENGTH(V_SQLS(V_INDEX)) < 4000 THEN EXIT; ELSE V_INDEX := V_INDEX + 1; END IF; END LOOP; V_CURSOR := DBMS_SQL.OPEN_CURSOR; FOR I IN 1 .. V_SQLS.LAST LOOP P_WRITE_LOG_SEGMENTS(A_OBJECT_NAME, A_CONTENT, V_SQLS(I)); END LOOP; DBMS_SQL.PARSE(C => V_CURSOR, STATEMENT => V_SQLS, LB => V_SQLS.FIRST, UB => V_SQLS.LAST, LFFLG => TRUE, LANGUAGE_FLAG => DBMS_SQL.NATIVE); V_COUNT_EXECUTE := DBMS_SQL.EXECUTE(V_CURSOR); P_WRITE_LOG_SEGMENTS(A_OBJECT_NAME, A_CONTENT || '(' || V_COUNT_EXECUTE || ':' || SQL%ROWCOUNT || ')', A_SQL); DBMS_SQL.CLOSE_CURSOR(C => V_CURSOR); EXCEPTION WHEN OTHERS THEN IF DBMS_SQL.IS_OPEN(C => V_CURSOR) THEN DBMS_SQL.CLOSE_CURSOR(C => V_CURSOR); END IF; RAISE; END; END IF; END P_EXECUTE_SQL;