orcle 根據時間 動態刪除原表數據,調用動態創建表函數。插入新表數據

create or replace procedure exportnew(ddate string) authid current_user is

  newname   varchar2(30);

  strsql varchar2(2000);

  cnt       int;

Begin

 

  select count(*)

    into cnt

    from hy_sczb_data

   where v_lrsj like '%' || ddate || '%';

 

  if cnt = 0 then

    --沒有結果時不處理

   Dbms_output.Put_line('不處理');

 

  Else

    creat_sczb_data(ddate); -- 創建新表 表名爲hy_sczb_data_16_08

     newname := 'sczb_data_' || replace(ddate, '-', '_'); --新表名

 

     strsql := 'Insert into ' ||newname|| ' select * fromhy_sczb_data where v_lrsj like :key';

     execute immediate strsql

     using '%' || ddate || '%';

 

     strsql := 'DELETE FROM hy_sczb_data WHERE  v_lrsj like :key';

     execute immediate strsql

     using '%' || ddate || '%';

    

     strsql := 'DELETE FROM hy_srzb_data WHERE  v_lrsj like :key';

     execute immediate strsql

     using '%' || ddate || '%';

 

  End if;

End exportnew;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章