FUNCTION or PROCEDURE does not exist
Error 1305 (SQLSTATE 42000) is raised when a call to a stored function, stored procedure, or user-defined function references a name that does not exist in the current database or in the specified schema.
- 1Calling a function that was never created
- 2Calling a function in the wrong database — it exists in another schema
- 3Case-sensitive naming mismatch on case-sensitive file systems
- 4The routine was dropped and not recreated after a schema migration
- 5Misspelled function name
Calling a stored function that does not exist.
SELECT calculate_tax(total) FROM invoices; -- Function calculate_tax does not exist in current db
expected output
ERROR 1305 (42000): FUNCTION mydb.calculate_tax does not exist
Fix 1
Verify the function exists and which database it is in
WHEN Before any other action — confirm the routine name and schema.
SELECT ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE FROM information_schema.ROUTINES WHERE ROUTINE_NAME LIKE '%calculate%';
Why this works
information_schema.ROUTINES lists all stored procedures and functions visible to the current user across all databases.
Fix 2
Qualify the function name with the correct schema
WHEN When the function exists in a different database.
SELECT utils.calculate_tax(total) FROM invoices;
Why this works
Qualifying with the schema name (utils.calculate_tax) resolves cross-database routine calls without changing the session database.
Fix 3
Create or recreate the missing function
WHEN When the function was dropped or never created.
CREATE FUNCTION calculate_tax(amount DECIMAL(10,2)) RETURNS DECIMAL(10,2) DETERMINISTIC BEGIN RETURN amount * 0.23; END;
Why this works
Recreating the function restores it. If using migrations, ensure the routine creation is part of the deployment script.
MariaDB Server error code 1305 / ER_SP_DOES_NOT_EXIST
MariaDB Stored Functions ↗MariaDB information_schema ROUTINES ↗Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev