| SQL> create table t as select * from all_objects; SQL> select count(1) from t; COUNT(1) ---------- 50020 |
| create or replace procedure test2 is cursor mycursor is select OWNER , CREATED,LAST_DDL_TIME from t ; --v_number number(8); v_owner varchar2(30); v_created date; v_ddl_time date; v_sql varchar2(1000); begin -- DBMS_OUTPUT.PUT_LINE('hello0'); execute immediate 'TRUNCATE TABLE ttest'; execute immediate 'insert into retime values(to_date(''' || to_char(sysdate, 'yyyy-mm-dd HH24:mi:ss') || ''',''yyyy-mm-dd HH24:mi:ss''))' ; COMMIT; -- DBMS_OUTPUT.PUT_LINE('hello1'); for v_pos in mycursor loop -- DBMS_OUTPUT.PUT_LINE('hello2'); v_owner:=v_pos.owner; v_created:=v_pos.created; v_ddl_time:=v_pos.last_ddl_time; --DBMS_OUTPUT.PUT_LINE(v_owner); v_sql:='insert into ttest values('''|| v_owner || ''',to_date('''|| to_char(v_created, 'yyyy-mm-dd HH24:mi:ss') || ''',''yyyy-mm-dd HH24:mi:ss''), to_date(''' || to_char(v_ddl_time, 'yyyy-mm-dd HH24:mi:ss') || ''',''yyyy-mm-dd HH24:mi:ss''))' ; --DBMS_OUTPUT.PUT_LINE(v_sql); execute immediate v_sql; -- COMMIT; --每次提交用commit -- DBMS_OUTPUT.PUT_LINE('hello3'); end loop; --DBMS_OUTPUT.PUT_LINE('hello4'); execute immediate 'insert into retime values(to_date(''' || to_char(sysdate, 'yyyy-mm-dd HH24:mi:ss') || ''',''yyyy-mm-dd HH24:mi:ss''))' ; commit; exception when others then -- DBMS_OUTPUT.PUT_LINE('hello5'); if v_sql <> '' then execute immediate 'insert into retime values(to_date(''' || to_char(sysdate, 'yyyy-mm-dd HH24:mi:ss') || ''',''yyyy-mm-dd HH24:mi:ss''))' ; end if; end test2; |
| SQL> select to_char(retime,'yyyy-mm-dd HH24:mi:ss') from retime; TO_CHAR(RETIME,'YYYY-MM-DDHH24:MI:SS') -------------------------------------- 2010-09-03 16:49:42 2010-09-03 16:50:11 2010-09-03 16:48:18 |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24419958/viewspace-672506/ ,如需转载,请注明出处,否则将追究法律责任。