I am trying to write a block of SQL code that compares two dates from two tables. One table shows when an item was acquired (ci_acquired_date). Another table shows when an item was an assigned to an employee (date_acquired). My goal is to use a loop that loops through the inventory and compare the dates and see if any of the dates assigned to an employee is less than the date the item was acquired (because it is impossible to assign an employee an item that was never bought) and use DBMS to show me which item ID it is and the dates it was acquired and assigned.
This is my code:
declare
cursor task_five is
select a.date_assigned, a.ci_inv_id, b.ci_acquired_date
from jaherna42.employee_ci a
join jaherna42.ci_inventory b
on a.ci_inv_id = b.ci_inv_id
where a.user_or_support = 'USER';
row_one jaherna42.employee_ci%rowtype;
row_two jaherna42.ci_inventory%rowtype;
begin
for row_one in task_five
loop
if(row_one.date_assigned < row_two.ci_acquired_date)
then
dbms_output.put_line('The error is: ' || row_one.ci_inv_id);
dbms_output.put_line('The date assigned is: ' || row_one.date_assigned);
dbms_output.put_line('The date acquired is: ' || row_two.ci_acquired_date);
end if;
end loop;
end;
When I run it, the script output box would show
PL/SQL procedure successfully completed.
But there would be nothing showing up in my dbms output box. What is the error?