PL/SQL Stored Procedure for Student Grading
PL/SQL Stored Procedure for Student Grading
To determine the number of students in the 'Distinction' category, the query would be: `select tot_stud('Distinction');`. This query utilizes the `tot_stud` function to count the distinct entries in the `result` table where the class equals 'Distinction'.
Adjusting the `log_bin_trust_function_creators` variable is necessary when creating functions like `tot_stud` because MySQL requires additional security measures for functions affecting data that can alter binary logs if they are not marked as deterministic. Enabling this variable bypasses such restrictions.
While creating the function `tot_stud`, an error related to binary logging was encountered due to the absence of `DETERMINISTIC`, `NO SQL`, or `READS SQL DATA` in its declaration. This was resolved by setting the `log_bin_trust_function_creators` variable to 1 globally, allowing the non-safe function creation.
The `DELIMITER` command is used to change the statement delimiter from the default semicolon to another character or string temporarily. This permits programming in multi-line SQL statements or stored procedures until they are completed, at which point the delimiter is usually reset.
A developer may encounter errors due to MySQL's binary logging restrictions which prevent creating non-deterministic functions without specific flags. This is remedied by altering the `log_bin_trust_function_creators` setting, effectively allowing such operations in a more flexible environment.
Stored procedures like `proc_Grade` offer modularity, improved performance by reducing client-server communication, and maintainable logic encapsulation. However, they can lead to complexity in debugging, reduced portability across different database systems, and sometimes obscure performance optimizations.
The proc_Grade stored procedure classifies student marks into the following categories: 'Distinction' for marks between 990 and 1500, 'First Class' for marks between 900 and 989, 'Second Class' for marks between 825 and 899, 'Pass' for marks between 700 and 824, and 'Fail' for marks below 700.
MySQL error code 1064 indicates a syntax error usually caused by incorrect SQL statement structure or missing elements like the wrong DELIMITER setting for stored procedures. Prevention entails careful review of syntax rules and ensuring all statements, delimiters, and procedure steps are correctly declared.
The `proc_grade` stored procedure classifies a student with exactly 890 marks as 'First Class' since it checks conditions from the highest to the lowest. The marks are evaluated against 989 to 900, which includes 890, thereby falling within the 'First Class' bracket.
The `proc_Grade` procedure inserts records into the `studmarks` table with the student's name and total marks, and into the `result` table with the student's roll number, name, and classified class based on their marks. This integration updates both tables with new data of the student provided to the procedure.