# CREATE FUNCTION

{% hint style="info" %}
**Note** Only valid for approved organizations. Please [contact us to enable functions](https://console.deltastream.io/support-center).
{% endhint %}

## Syntax <a href="#synopsis" id="synopsis"></a>

```sql
CREATE FUNCTION
    function_name (arg_name arg_type [, ...])
    RETURNS return_type
    LANGUAGE language_name
WITH (function_parameter = value [, ...]);
```

## Description

Defines a new [user-defined function](/overview/core-concepts/function.md) (UDF), an executable routine defined in a supported language, which accepts an ordered list of input arguments, performs a computation, and generates a result value.

The name and parameter types of a function’s signature must be unique within an organization. The signature is a combination of the name, parameter types, and return type of the function.

See the [Creating a Function](/how-do-i.../creating-a-function.md) tutorial for a full example of adding a [function](/overview/core-concepts/function.md).

### Arguments

#### function\_name

Name of the function to create. If the name is case-sensitive, you must wrap it in double quotes; otherwise, the system uses the lower case name.

#### (arg\_name arg\_type \[,…​])

An ordered list of function argument names and types.

#### return\_type

Data type for a function’s result value.

#### language\_name

Language in which the function was created. Supports `JAVA`.

#### WITH (function\_parameter = value \[, …​ ])

This clause specifies the [function parameters](#function-parameters).

### Function Parameters

| Parameter Name      | Description                                                                                                                                                                                                                                                                                                                                                          |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `source.name`       | <p>Required. Specifies an existing function Source to use for the content of the function. See <a data-mention href="/pages/5o95WTlsGL7ik3CAigJC">/pages/5o95WTlsGL7ik3CAigJC</a>.<br><br>Type: String<br>Valid values: A function\_source to which the user has access. See <a data-mention href="/pages/5o95WTlsGL7ik3CAigJC">/pages/5o95WTlsGL7ik3CAigJC</a>.</p> |
| `class.name`        | <p>Required. Specifies the fully-qualified class name defined within a function source.<br><br>Type: String<br>Valid values: A valid class name in the function\_source.</p>                                                                                                                                                                                         |
| `egress.allow.uris` | Optional. Specifies a comma delimited list of `host:port` endpoints that the `function` can send requests. This is only needed if a function needs to call a remote service.                                                                                                                                                                                         |

### Example

#### Create user-defined function with single input argument

The below DDL statement creates a new user-defined function with the name `toUpperCase`. The function accepts one argument of the data type `VARCHAR;` the data type of its return value is also `VARCHAR`. The function's executable code is in a Java class with the name `util.UpperCase` available in the `mysrc` function source. Check [CREATE FUNCTION SOURCE](/reference/sql-syntax/ddl/create-function_source.md) for details on how to add a function source.

```sql
CREATE FUNCTION
    "toUpperCase" (s VARCHAR)
    RETURNS VARCHAR
    LANGUAGE JAVA
    WITH ( 'source.name' = 'mysrc', 'class.name' = 'util.UpperCase' );
```

You can use [LIST FUNCTIONS](/reference/sql-syntax/command/list-functions.md) command to get a list of created functions.

#### Create user-defined function with multiple input arguments

The below DDL statement creates a new user-defined function called `getrate` from a Java class with the name `accounting.Exchange` available in the `finance` function source. This function receives two input arguments of data types `VARCHAR` and `BIGINT`, and generates an output of the data type `DECIMAL`.

```sql
CREATE FUNCTION
    getrate (name VARCHAR, amount BIGINT)
    RETURNS DECIMAL
    LANGUAGE JAVA
    WITH ( 'source.name' = 'finance', 'class.name' = 'accounting.Exchange' );
```

#### Create user-defined function with egress.allow\.uris property

The below DDL statement creates a new user-defined function called `getrate` from a Java class with the name `accounting.Exchange` available in the `finance` function source. This function receives two input arguments of data types `VARCHAR` and `BIGINT`, and generates an output of the data type `DECIMAL`.

This function will can also make remote calls to `myhost1:9090` and `myhost2:80`. Without the `egress.allow.uris` property, the function calls are blocked.

```sql
CREATE FUNCTION
    getrate (name VARCHAR, amount BIGINT)
    RETURNS DECIMAL
    LANGUAGE JAVA
    WITH ( 'source.name' = 'finance', 'class.name' = 'accounting.Exchange', 'egress.allow.uris'='myhost1:9090,myhost2:80' );
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.deltastream.io/reference/sql-syntax/ddl/create-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
