gdufo

           

          ad 刪除一個(gè)實(shí)體的SQL語句

          DECLARE
              /**
               * Please change this one to any client id you want to delete
               **/
              v_Client_ID                                                 NUMBER      := 1000014;
              
              v_SQL1                               VARCHAR2(1024);
              
              CURSOR Cur_Contraints  IS
                          select  table_name,constraint_name
                         from user_constraints  
                          where  status='ENABLED'  AND constraint_type='R' ;
                  
               CURSOR Cur_Contraints2  IS
                          select table_name,constraint_name
                          from user_constraints
                          where status='DISABLED' AND constraint_type='R';
                          
                  CURSOR Cur_Triggers  IS
                          select TRIGGER_NAME
                          from user_triggers
                          where status='ENABLED';
                                  
             CURSOR Cur_RemoveData  IS
                      select 'delete from '|| TABLENAME ||' where AD_Client_ID=' || v_Client_ID
                      AS v_SQL
                          from AD_Table a where a.ISVIEW='N'
                          AND exists ( select AD_Column_ID from AD_Column c where

          a.AD_Table_ID=c.AD_Table_ID
                          and upper(c.COLUMNNAME)= upper('AD_Client_ID') );
                      
                          
          BEGIN
              
              DBMS_OUTPUT.PUT_LINE('  Delete Client Where AD_Client_ID=' || v_Client_ID);
              
              /****************************************************************
               *  Disable all the constraints one by one
               ****************************************************************/
               DBMS_OUTPUT.PUT_LINE(' Disable the contraints ');
               FOR p IN Cur_Contraints  LOOP
                 BEGIN
                 v_SQL1 := 'alter table '|| p.table_name ||' disable constraint '|| p.constraint_name;
                  EXECUTE IMMEDIATE v_SQL1;        
                 END;  
               END LOOP;        --        Disable contraints
               
               
               DBMS_OUTPUT.PUT_LINE(' Disable the triggers ');
               FOR p IN Cur_Triggers  LOOP
                 v_SQL1 := 'alter trigger '|| p.TRIGGER_NAME ||' disable ';
                  EXECUTE IMMEDIATE v_SQL1;
               END LOOP;        --        Disable contraints
               
               /****************************************************************
               *  Remove all the records belongs to that client
               ****************************************************************/
              FOR p IN Cur_RemoveData LOOP
                  v_SQL1 := p.v_SQL;
                  EXECUTE IMMEDIATE v_SQL1;
                  
               END LOOP;        --        Remove data
               
               
               /****************************************************************
               *  Disable all the constraints one by one
               ****************************************************************/
               DBMS_OUTPUT.PUT_LINE(' Enable the contraints ');
              FOR p IN Cur_Contraints2  LOOP
                  BEGIN
                  v_SQL1 := 'alter table '|| p.table_name ||' enable constraint '|| p.constraint_name;
                  EXECUTE IMMEDIATE v_SQL1;        
                  END;
               END LOOP;        --        Enable contraints
               
               DBMS_OUTPUT.PUT_LINE(' Enable the triggers ');
               FOR p IN Cur_Triggers  LOOP
                 v_SQL1 := 'alter trigger '|| p.TRIGGER_NAME ||' enabled ';
                  EXECUTE IMMEDIATE v_SQL1;
               END LOOP;        --        Enable contraints
               
               COMMIT;


          END;

          posted on 2012-05-26 16:57 gdufo 閱讀(571) 評(píng)論(0)  編輯  收藏 所屬分類: idempiere Adempiere empiere

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          Hibernate

          友情鏈接

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 黄大仙区| 正蓝旗| 佛坪县| 宝清县| 屏东市| 瑞金市| 商城县| 宾川县| 中卫市| 康马县| 疏附县| 房山区| 师宗县| 瓮安县| 天门市| 金乡县| 津南区| 乃东县| 南京市| 平湖市| 娱乐| 利津县| 伊吾县| 米易县| 扎鲁特旗| 张家界市| 张家港市| 六枝特区| 五家渠市| 霍山县| 社旗县| 绿春县| 洛扎县| 弥渡县| 天等县| 昌吉市| 璧山县| 河池市| 泰州市| 赤城县| 当雄县|