Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE PROCEDURE make_report(start_date IN DATE, end_date IN DATE)
- IS
- first_name_old VARCHAR2(50 CHAR);
- last_name_old VARCHAR2(50 CHAR);
- age_old NUMBER(2);
- phone_old VARCHAR2(11 CHAR);
- BEGIN
- DELETE FROM operation_date_tmp;
- FOR R1 IN (
- SELECT woman_id FROM women_log WHERE date_log BETWEEN start_date AND end_date GROUP BY woman_id
- ) LOOP
- FOR R3 IN (
- SELECT woman_id, first_name, last_name, age, phone, date_log, username, operation FROM women_log
- ORDER BY date_log
- ) LOOP
- IF R3.operation = 'inserting' THEN
- INSERT INTO operation_date_tmp(old_value, new_value, date_op, operation)
- VALUES('', R3.woman_id || ' ' || R3.first_name || ' ' || R3.last_name || ' ' || R3.age || ' ' || R3.phone, R3.date_log, R3.operation);
- END IF;
- IF R3.operation = 'deleting' THEN
- INSERT INTO operation_date_tmp(old_value, new_value, date_op, operation)
- VALUES(R3.woman_id || ' ' || R3.first_name || ' ' || R3.last_name || ' ' || R3.age || ' ' || R3.phone, '', R3.date_log, R3.operation);
- END IF;
- IF R3.operation = 'updating' THEN
- IF R3.first_name != first_name_old THEN
- INSERT INTO operation_date_tmp(old_value, new_value, field_name, date_op, operation)
- VALUES(first_name_old, R3.first_name, 'first_name', R3.date_log, R3.operation);
- END IF;
- IF R3.last_name != last_name_old THEN
- INSERT INTO operation_date_tmp(old_value, new_value, field_name, date_op, operation)
- VALUES(last_name_old, R3.last_name, 'last_name', R3.date_log, R3.operation);
- END IF;
- IF R3.age != age_old THEN
- INSERT INTO operation_date_tmp(old_value, new_value, field_name, date_op, operation)
- VALUES(age_old, R3.age, 'age', R3.date_log, R3.operation);
- END IF;
- IF R3.phone != phone_old THEN
- INSERT INTO operation_date_tmp(old_value, new_value, field_name, date_op, operation)
- VALUES(phone_old, R3.phone, 'phone', R3.date_log, R3.operation);
- END IF;
- END IF;
- first_name_old := R3.first_name;
- last_name_old := R3.last_name;
- age_old := R3.age;
- phone_old := R3.phone;
- END LOOP;
- END LOOP;
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement