Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.24 KB | None | 0 0
  1. CREATE OR REPLACE PROCEDURE make_report(start_date IN DATE, end_date IN  DATE)
  2. IS
  3.        first_name_old VARCHAR2(50 CHAR);
  4.        last_name_old VARCHAR2(50 CHAR);
  5.        age_old NUMBER(2);
  6.        phone_old VARCHAR2(11 CHAR);
  7. BEGIN
  8.   DELETE FROM operation_date_tmp;
  9.  
  10.   FOR R1 IN (
  11.     SELECT woman_id FROM women_log WHERE date_log BETWEEN start_date AND end_date GROUP BY woman_id
  12.    ) LOOP
  13.     FOR R3 IN (
  14.       SELECT woman_id, first_name, last_name, age, phone, date_log, username, operation FROM women_log
  15.       ORDER BY date_log
  16.       ) LOOP
  17.  
  18.       IF R3.operation = 'inserting' THEN
  19.          INSERT INTO operation_date_tmp(old_value, new_value, date_op, operation)
  20.            VALUES('', R3.woman_id || '  ' || R3.first_name || '  ' || R3.last_name || '  ' || R3.age || '  ' || R3.phone, R3.date_log, R3.operation);
  21.       END IF;
  22.  
  23.       IF R3.operation = 'deleting' THEN
  24.          INSERT INTO operation_date_tmp(old_value, new_value, date_op, operation)
  25.            VALUES(R3.woman_id || '  ' || R3.first_name || '  ' || R3.last_name || '  ' || R3.age || '  ' || R3.phone, '', R3.date_log, R3.operation);
  26.       END IF;
  27.  
  28.   IF R3.operation = 'updating' THEN
  29.  
  30.     IF R3.first_name != first_name_old THEN
  31.       INSERT INTO operation_date_tmp(old_value, new_value, field_name, date_op, operation)
  32.              VALUES(first_name_old, R3.first_name, 'first_name', R3.date_log, R3.operation);
  33.     END IF;
  34.     IF R3.last_name != last_name_old THEN
  35.       INSERT INTO operation_date_tmp(old_value, new_value, field_name, date_op, operation)
  36.              VALUES(last_name_old, R3.last_name, 'last_name', R3.date_log, R3.operation);
  37.     END IF;
  38.     IF R3.age != age_old THEN
  39.       INSERT INTO operation_date_tmp(old_value, new_value, field_name, date_op, operation)
  40.              VALUES(age_old, R3.age, 'age', R3.date_log, R3.operation);
  41.     END IF;
  42.     IF R3.phone != phone_old THEN
  43.       INSERT INTO operation_date_tmp(old_value, new_value, field_name, date_op, operation)
  44.              VALUES(phone_old, R3.phone, 'phone', R3.date_log, R3.operation);
  45.     END IF;
  46.  
  47.   END IF;
  48.          first_name_old := R3.first_name;
  49.          last_name_old := R3.last_name;
  50.          age_old := R3.age;
  51.          phone_old := R3.phone;
  52.       END LOOP;
  53.   END LOOP;
  54.  
  55. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement