User Tools

Site Tools


**HPL/SQL is included to Apache Hive since version 2.0** * [[home|Home]]\\ * [[why|Why HPL/SQL]]\\ * [[features|Key Features]]\\ * [[start|Get Started]]\\ * [[doc|HPL/SQL Reference]]\\ * [[download|Download]]\\ * [[new|What's New]]\\ * [[about|About]]


====== CREATE FUNCTION Statement ====== CREATE FUNCTION statement allows you to create a user-defined SQL function. **Syntax**: <code language=sql> ALTER | CREATE [OR REPLACE] | REPLACE FUNCTION function_name ( [parameters] ) RETURNS | RETURN data_type [AS | IS] body parameters: [IN] name data_type, ... | name [IN] data_type, ... body: statement | expression | BEGIN statements END </code> **Example 1**: Create a function without parameters: <code language=sql> CREATE FUNCTION hello() RETURNS STRING BEGIN RETURN 'Hello, world'; END; -- Call the function PRINT hello(); </code> **Example 2**: Create a function with a parameter: <code language=sql> CREATE FUNCTION hello2(text STRING) RETURNS STRING BEGIN RETURN 'Hello, ' || text || '!'; END; -- Call the function PRINT hello2('world'); </code> **Compatibility:** Oracle, Teradata, IBM DB2, Microsoft SQL Server, PostgreSQL, MySQL and Netezza **Version**: HPL/HQL 0.3.1 See also: * [[udf-sproc|User-Defined Functions and Stored Procedures]] * [[call|CALL]] * [[create-package|CREATE PACKAGE]] * [[create-procedure|CREATE PROCEDURE]] * [[include|INCLUDE]]