SQL Script Basics
Applications benefit most from the potential of SAP HANA if they perform as many data-intensive computations in the database as possible. This avoids loading large amounts of data into an application server separate from SAP HANA, and leverages fast column operations, query optimization, and parallel execution. This can be achieved to a certain extent if the applications use advanced SQL statements, but sometimes you may want to push more logic into the database than possible using individual SQL statements, or make the logic more readable and maintainable.
SQL script has been introduced to assist with this task.
SQL Script Definition and Goal
This is helpful for the following reasons:
SQL Script Advantages
Compared to plain SQL, SQL Scripts provides the following advantages:
SQL User-Defined Functions
The simplest database objects for which you can make use of SQL Scripts are scalar user-defined functions (Scalar UDFs).
Scalar UDFs allow you to define functions that take several input parameters and return scalar values. Only expressions are allowed in the body of the UDFs, so no table operations, CE functions or array operations.
Scalar UDFs support the following:
Options Used to Define UDFs in SAP HANA
The following are some options used to define UDFs in SAP HANA:
The SQL statement to define UDFs is CREATE FUNCTION. The basic syntax to define a scalar UDF using the direct SQL method is as follows:
Basic Syntax to define a scalar UDF
CREATE FUNCTION <function name>
(< List of input parameters with type>)
RETURNS <scalar result parameter name and type>
AS
BEGIN
<function body>
END;
Deleting UDFs
DROP FUNCTION <function name>