Anyone know why its not deleting the records from the student table. When the table is empty and i first run the anonymous block it runs fine, but then when i run it again i get
"doesnt my function carry out the deleting?"
It would if you called it, but alas you don't.
This is not a SQL problem, it's a logic problem. If we don't do the washing up the dishes remain dirty. Similarly if you don't call the routine which deletes the records the records are not deleted.
You need to call the function in the procedure. Not sure why you've made it a function, and it won't compile anyway, because it doesn't have a RETURN clause. So, let's fix that too.
CREATE OR REPLACE FUNCTION DELETE_ALL_STUDENTS RETURN NUMBER AS
BEGIN
DELETE FROM STUDENTS;
return sql%rowcount; -- how many rows were deleted
END;
/
Now we call it:
create or replace PROCEDURE DELETE_ALL_STUDENTS_VIASQLDEV AS
n number;
BEGIN
dbms_output.put_line('--------------------------------------------');
dbms_output.put_line('Deleting all student rows');
n := DELETE_ALL_STUDENTS;
dbms_output.put_line('No of students deleted = '|| to_char(n));
END;
So, when you run your anonymous block the existing students will be deleted and replaced with the new ones.