In an Oracle DB I have the following two tables:
Task (TaskID, ..., AuthorID)
Author (AuthorID, level)
where AuthorID in Task represents the author that wrote the task. Now I wrote the following procedure, that is supposed to update level-Attribute based on the number of tasks the author has written.
CREATE OR REPLACE PROCEDURE profil_level
IS
CURSOR c1 IS SELECT AuthorID, COUNT(AuthorID) as Total FROM Task
GROUP BY AuthorID;
result c1%ROWTYPE;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO result;
EXIT WHEN c1%NOTFOUND;
IF(result.Total = 2 OR result.Total = 3) THEN
UPDATE TABLE Author SET level = 'advanced'
WHERE AuthorID = result.AuthorID;
END IF;
IF(result.Total >= 4) THEN
UPDATE TABLE Author SET level= 'proficient'
WHERE AuthorID = result.AuthorID;
END IF;
END LOOP;
CLOSE c1;
END;
Trying to execute this statement, I get tons of errors like
invalid SQL Statement
e.g. for the line result c1%ROWTYPE or FETCH c1 into result. Additionally, I get the error
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ...
for the line BEGIN OPEN c1. I cannot figure out, what the problem is with my code. I've read tutorials from Oracle and on other sites, but in every example I've seen so far, they have used the exact same syntax. Do I need to change the 'delimiter' (like e.g. in MySQL)?
Thanks for your help!
create tablewith a/(on a single line)create tablestatement or is it just a typo and you meantcreate procedure? edit: Yes, I am aware of that (but there are people who want me to specifically create a procedure ;-))create procedure. See the link I posted and click on build schema.