I'm using PLSQL to create a procedure to update a table based on querying another table, and I'm using a loop for the purpose. FOr testing, I'm holding off on the procedure code, and just trying to make the following script work. But it keeps throwing errors including "Encountered the symbol "end-of-file"" or "invalid SQL statement", based on minor tweaks. Where am I going wrong?
DECLARE CURSOR cur IS
SELECT * FROM Summary;
BEGIN
FOR rec in cur
LOOP
UPDATE Award
SET monthly_sales = (
SELECT COUNT(*)
FROM Sales
WHERE employee_id = rec.employee_id
AND to_char(Sales.SALES_DATE,'YY/MM')=to_char(SYSDATE,'YY/MM')
)
WHERE Summary.employee_id = rec.employee_id
END LOOP
END;
/
AND trunc(Sales.SALES_DATE,'month') = trunc(SYSDATE,'month')then theto_charfunctions with two digit years in the format string. If your sales table ever contained > 100 years of data you could get counts from more than one century, though this bug will take a long time to show up.