SQL Execute Immediate Command with Input-Output Parameters on HANA Database
SQLScript Execute Immediate command enables to pass input and output parameters to SQL commands running on SAP HANA database for developers with Using and Into clause.
In this HANA database tutorial, I want to show how SQL programmers can pass input parameters to Execute Immediate SQLScript command which enables dynamic SQL programming for developers.
Additionally, using the same case database developers will see how to read output parameter values provided to SQLScript Execute Immediate command.
For this SQLScript tutorial demonstration of Execute Immediate command with input and output parameters by using "INTO" and "USING" clauses, I create following table on a development SAP HANA database and populate it with sample data by running INSERT commands
I create transaction codes sample column table in my development schema named TCodes.
HANA database table TCodes, has 3 columns. First column is an identity column which is automatically generated for each row inserted into the table and starts from 1 and increases by 1 with each record insert.
Second column is transaction code column, tcode. And the last column ttext, is for description of the transaction code.
After our sample column table is created on the HANA database, we can now create some sample data for this tutorial.
Here is our sample column table
Now, assume that SQLScript programmer wants to insert a new row by using parameters for tcode and transaction code text. Also assume that SQL developer requires the ID value of the new row.
The SQLScript code for solving this requirement is as follows:
Here is the output. Please note that I have two input parameters here. And one output parameter which I had its value by using SQLScript current_identity_value() function.
This time assume that HANA database developer want to parameterize the SQLScript code
In following SQL code, the INSERT statement is converted into a parameterized SQLScript command.
The tcode and ttext parameters (respectively :tcode and :ttext) are replaced with "?,?"
HANA database developers can pass values to Execute Immediate SQL command with USING clause. Right after USING clause corresponding parameter values are provided.
To run HANA SQL command read output values from "Execute Immediate", "INTO" clause is used.
The values in the SELECT field list are mapped into output parameters which are defined right after INTO clause.
As I tried to show with a SQL example in this HANA database tutorial, SQLScript developers can run "Execute Immediate" command with input parameters by using "USING" clause and with output parameters by using "INTO" clause.