ALTER FUNCTION

Function

ALTER FUNCTION modifies the attributes of a customized function.

Precautions

Only the owner of a function or a system administrator can run this statement. The user who wants to change the owner of a function must be a direct or indirect member of the new owner role. If a function involves operations on temporary tables, the ALTER FUNCTION cannot be used.

Syntax

Parameter Description

Example

Create a function that calculates the sum of two integers and returns the result. If the input is null, null will be returned.

1
2
3
4
5
6
7
DROP FUNCTION IF EXISTS func_add_sql2; 
CREATE FUNCTION func_add_sql2(num1 integer, num2 integer) RETURN integer
AS
BEGIN 
RETURN num1 + num2;
END;
/

Alter the execution rule of function add to IMMUTABLE (that is, the same result is returned if the parameter remains unchanged):

1
ALTER FUNCTION func_add_sql2(INTEGER, INTEGER) IMMUTABLE;

Rename the func_add_sql2 function as add_two_number:

1
ALTER FUNCTION func_add_sql2(INTEGER, INTEGER) RENAME TO add_two_number;

Change the owner of function add_two_number to dbadmin:

1
ALTER FUNCTION add_two_number(INTEGER, INTEGER) OWNER TO dbadmin;

Helpful Links

CREATE FUNCTION, DROP FUNCTION