MySQL DROP FUNCTION
Summary: in this tutorial, you will learn how to use the MySQL DROP FUNCTION
statement to drop a stored function.
Introduction to MySQL DROP FUNCTION
statement
The DROP FUNCTION
statement drops a stored function. Here is the syntax of the DROP FUNCTION
statement:
DROP FUNCTION [IF EXISTS] function_name;
In this syntax, you specify the name of the stored function that you want to drop after the DROP FUNCTION
keywords.
The IF EXISTS
the option allows you to conditionally drop a stored function if it exists. It prevents an error from arising if the function does not exist.
MySQL DROP FUNCTION
example
We’ll use the orders
the table in the sample database for the demonstration.
First, create a new function called OrderLeadTime
that calculates the number of days between the ordered date and required date:
DELIMITER $$
CREATE FUNCTION OrderLeadTime (
orderDate DATE,
requiredDate DATE
)
RETURNS INT
DETERMINISTIC
BEGIN
RETURN requiredDate - orderDate;
END$$
DELIMITER ;
Second, use the DROP FUNCTION
statement to drop the function OrderLeadTime
:
DROP FUNCTION OrderLeadTime;
Third, use the DROP FUNCTION
to drop a non-existing function:
DROP FUNCTION IF EXISTS NonExistingFunction;
MySQL issued a warning:
0 row(s) affected, 1 warning(s): 1305 FUNCTION classicmodels.NonExistingFunction does not exist
If you want to view the warning in detail, use the SHOW WARNINGS
statement:
SHOW WARNINGS;
In this tutorial, you will learn how to use the DROP FUNCTION
statement to drop a stored function.
0 Comments
CAN FEEDBACK
Emoji