DROP FUNCTION (SQL)
Synopsis
DROP FUNCTION [IF EXISTS] name [ FROM className ]
Description
The DROP FUNCTION command deletes a function. When you drop a function, InterSystems IRIS revokes it from all users and roles to whom it has been granted and removes it from the database.
In order to drop a function, you must have %DROP_FUNCTION administrative privilege, as specified by the GRANT command. Otherwise, the system generates an SQLCODE -99 error (Privilege Violation).
You cannot drop a function if the class definition that contains that function definition is a deployed class. This operation fails with an SQLCODE -400 error with the %msg Unable to execute DDL that modifies a deployed class: 'classname'.
The following combinations of name and FROM className are supported. Note that the FROM clause specifies the class package name and function name, not the SQL names. In these examples, the system-wide default schema name is SQLUser, which corresponds to the User class package:
-
DROP FUNCTION BonusCalc FROM funcBonusCalc: drops the function SQLUser.BonusCalc().
-
DROP FUNCTION BonusCalc FROM User.funcBonusCalc: drops the function SQLUser.BonusCalc().
-
DROP FUNCTION Test.BonusCalc FROM funcBonusCalc: drops the function SQLUser.BonusCalc().
-
DROP FUNCTION BonusCalc FROM Employees.funcBonusCalc: drops the function Employees.BonusCalc().
-
DROP FUNCTION Test.BonusCalc FROM Employees.funcBonusCalc: drops the function Employees.BonusCalc().
If the specified function does not exist, DROP FUNCTION generates an SQLCODE -362 error. If the specified class does not exist, DROP FUNCTION generates an SQLCODE -360 error. If the specified function could refer to two or more functions, DROP FUNCTION generates an SQLCODE -361 error; you must specify a className to resolve this ambiguity.
Arguments
IF EXISTS
An optional argument that suppresses the error if the command is executed on a nonexistent function.
name
The name of the function to be deleted. The name is an identifier. Do not specify the function’s parameter parentheses. A name can be qualified (schema.name), or unqualified (name). An unqualified function name takes the system-wide default schema name, unless the FROM className clause is specified.
FROM className
If specified, the FROM className clause deletes the function from the given class. Note that you must specify the className of a function (funcBonusCalc), not the SQL name (BonusCalc). If the FROM clause is not specified, InterSystems IRIS searches all classes of the schema for the function, and deletes it. However, if no function of this name is found, or more than one function of this name is found, an error code is returned. If the deletion of the function results in an empty class, DROP FUNCTION deletes the class as well
Examples
The following example attempts to delete myfunc from the class User.Employee. (Refer to CREATE TABLE for an example that creates class User.Employee.)
DROP FUNCTION myfunc FROM User.Employee