1. SQL / Говнокод #3546

    −857

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    procedure xxx_procedure
    is
    --   lngIDVidPP Number;
       sSQL       varchar2(4000);
    begin
    sSQL := '';
    sSQL := sSQL || ' Declare ';
    sSQL := sSQL || '    lngIDVidPP Number; ';
    sSQL := sSQL || '    lngColRec  Number; ';
    sSQL := sSQL || '    strTypeProc Varchar2(255); ';
    sSQL := sSQL || ' BEGIN ';
    sSQL := sSQL || ' for rec in (select f.param2 , A.idpp, pp.crastr, pp.cvector, a.param1, a.et, a.tet ';
    sSQL := sSQL || '  from table1 e, T_IDPP@' || 'app' || '_' ||'xxx' || ' a, table2 f, ';
    sSQL := sSQL || '   t_pp_card@' || 'app' || '_' || 'xxx' || ' pp,  refitem r';
    sSQL := sSQL || '  where ';
    sSQL := sSQL || '   e.param1 = a.param1 ';
    sSQL := sSQL || '   and e.id_building = F.ID_BUILDING ';
    sSQL := sSQL || '   and F.FLOOR_NUMBER = a.et ';
    sSQL := sSQL || '   and R.REFERENCEID = 2019 and R.ITEMID = F.ID_FLOOR_TYPE';
    sSQL := sSQL || '   and R.CODE = a.tet';
    sSQL := sSQL || '   and a.idpp = pp.cidpp)';
    sSQL := sSQL || '  loop ';
    sSQL := sSQL || '     lngColRec := 0; ';
    sSQL := sSQL || '     lngIDVidPP := 0; ';
    sSQL := sSQL || '     SELECT COUNT(*) INTO lngColRec FROM T_PROCESS_PP@' || 'app' || '_' || 'xxx || ' Z ';
    sSQL := sSQL || '                     WHERE Z.PPP_UNOM = rec.param1 AND Z.PPP_ET = rec.et AND Z.PPP_TET = rec.tet; ';
    sSQL := sSQL || '     if lngColRec = 0 then ';
    sSQL := sSQL || '        if BITAND(rec.crastr, 8) <> 0 and BITAND(rec.cvector, 8) <> 0 then ';
    sSQL := sSQL || '           lngIDVidPP := 50868; ';
    sSQL := sSQL || '        else ';
    sSQL := sSQL || '           if BITAND(rec.crastr, 8) <> 0 then ';
    sSQL := sSQL || '              lngIDVidPP := 50866; ';
    sSQL := sSQL || '           else ';
    sSQL := sSQL || '              lngIDVidPP := 50867; ';
    sSQL := sSQL || '           end if; ';
    sSQL := sSQL || '        end if; ';
    sSQL := sSQL || '        update table2 f ';
    sSQL := sSQL || '            set f.xx      = rec.idpp, ';
    sSQL := sSQL || '                f.xxx   = lngIDVidPP, ';
    sSQL := sSQL || '                f.xxxx = 54554 ';
    sSQL := sSQL || '          where f.xxxxx = rec.id_floor; ';
    sSQL := sSQL || '     else  '; --if lngColRec > 0 then
    sSQL := sSQL || '          strTypeProc := Null; ';
    sSQL := sSQL || '          SELECT Y.PH_ACTION_KEY INTO strTypeProc ';
    sSQL := sSQL || '            FROM T_PROCESS_HEAD@' || 'app' || '_' || 'SGP' || ' Y ';
    sSQL := sSQL || '            WHERE ';
    sSQL := sSQL || '                 Y.PHID IN (SELECT X.PPP_PHID ';
    ...... 10 строк вырезано из-за ограничения 4000символов
    sSQL := sSQL || '               if BITAND(rec.crastr, 8) <> 0 and BITAND(rec.cvector, 8) <> 0 then ';
    sSQL := sSQL || '                  lngIDVidPP := 50868; ';
    sSQL := sSQL || '               else ';
    sSQL := sSQL || '                  if BITAND(rec.crastr, 8) <> 0 then ';
    sSQL := sSQL || '                     lngIDVidPP := 50866; ';
    sSQL := sSQL || '                  else ';
    sSQL := sSQL || '                     lngIDVidPP := 50867; ';
    sSQL := sSQL || '                  end if; ';
    sSQL := sSQL || '               end if; ';
    sSQL := sSQL || '                  update table3 f ';
    sSQL := sSQL || '                     set f.ID_PLANE_G = rec.idpp, ';
    sSQL := sSQL || '                     f.id_plane_scan = lngIDVidPP, ';
    sSQL := sSQL || '                     f.id_status_plane = 54552 ';
    sSQL := sSQL || '               where f.param1 = rec.param1; ';
    sSQL := sSQL || '           ELSE ';
    sSQL := sSQL || '                  update table3 f ';
    sSQL := sSQL || '                 set f.id_status_plane = 54552 ';
    sSQL := sSQL || '               where f.param1 = rec.param1; ';
    sSQL := sSQL || '           END IF; ';
    sSQL := sSQL || '     end if; ';  --if lngColRec > 0 then
    sSQL := sSQL || '   end loop;';
    sSQL := sSQL || '  null;';
    sSQL := sSQL || '  end;';
    
    EXECUTE IMMEDIATE sSQL;
            dbms_output.put_line ('Процедура xxx_procedure успешно создана');
    EXCEPTION
      WHEN OTHERS THEN dbms_output.put_line('Ошибка создания xxx_procedure. ' || SQLERRM);
    end;

    В связи с NDA названия изменены.

    Запостил: kamapcuc, 23 Июня 2010

    Комментарии (98) RSS

    Добавить комментарий