1305ERRORTier 2 — Caution✅ HIGH confidence

FUNCTION or PROCEDURE does not exist

Category: Stored RoutinesVersions: All MariaDB / MySQL versions

What this means

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.

Why it happens

  1. 1Calling a function that was never created
  2. 2Calling a function in the wrong database — it exists in another schema
  3. 3Case-sensitive naming mismatch on case-sensitive file systems
  4. 4The routine was dropped and not recreated after a schema migration
  5. 5Misspelled function name

How to reproduce

Calling a stored function that does not exist.

trigger — this will ERROR
SELECT calculate_tax(total) FROM invoices;
-- Function calculate_tax does not exist in current db
ERROR 1305 (42000): FUNCTION mydb.calculate_tax does not exist

Fix 1: Verify the function exists and which database it is in

Before any other action — confirm the routine name and schema.

fix
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 the function exists in a different database.

fix
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 the function was dropped or never created.

fix
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.

Sources

📚 Official docs: https://mariadb.com/kb/en/stored-function-overview/

🔧 Source ref: MariaDB Server error code 1305 / ER_SP_DOES_NOT_EXIST

📖 Further reading: MariaDB Stored Functions

📖 Further reading: MariaDB information_schema ROUTINES

Confidence assessment

✅ HIGH confidence

Stable.

See also

📄 Reference pages

information_schema.ROUTINESstored functionstored procedure
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →