PolarDB supports parsers for compiling functions and stored procedures. Parsers verify that the CREATE statement and the program body (the program portion following the AS keyword) conform to the SPL and SQL syntax. If a parser detects an error, the server automatically stops the compilation process.
Note that the parser detects syntax errors in expressions, rather than semantic errors. For example, if an expression references a nonexistent column, table, function, or a value of the incorrect type, an exception is thrown.
You can instruct the server to stop parsing if the parser finds one or more errors in SPL code or an error in SQL code. You can specify the spl.max_error_count parameter to control the maximum number of errors that are allowed in SPL code. The default value of the spl.max_error_count parameter is 10. The maximum value is 1000. You can set the value of spl.max_error_count to 1, which instructs the server to stop parsing when the first error in SPL or SQL code occurs.
SET spl.max_error_count = number_of_errors
SET spl.max_error_count = 6
In this example, the server continues parsing regardless of the first five SPL code errors. When the sixth error occurs, the server stops parsing, and the six detailed error messages and an error summary are displayed.
When developing new code or importing existing code from other sources, you can set the spl.max_error_count parameter to a large value to save time.
CREATE FUNCTION computeBonus(baseSalary number) RETURN number AS
BEGIN
bonus := baseSalary * 1.10;
total := bonus + 100;
RETURN bonus;
END;
ERROR: "bonus" is not a known variable
LINE 4: bonus := baseSalary * 1.10;
^
ERROR: "total" is not a known variable
LINE 5: total: = bonus + 100;
^
ERROR: compilation of SPL function/procedure "computebonus" failed due to 2 errors
CREATE FUNCTION computeBonus(employeeName number) RETURN number AS
BEGIN
SELECT salary INTO baseSalary FROM emp
WHERE ename = employeeName;
bonus := baseSalary * 1.10;
total := bonus + 100;
RETURN bonus;
END;
ERROR: "basesalary" is not a known variable
LINE 3: SELECT salary INTO baseSalary FROM emp WHERE ename = emp...