Examples - Teradata Database

SQL Data Manipulation Language

Product
Teradata Database
Release Number
15.10
Language
English (United States)
Last Update
2018-10-06
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata® Database

Example : Named Parameter List

This request uses a named parameter list to execute macro new_emp1. See “CREATE MACRO” in SQL Data Definition Language. Named parameters can be listed in any order.

     EXECUTE new_emp1(number=10015, dept=500, name='Omura H', sex='M',
             position='Programmer');

The row for new employee Omura is inserted in the employee table.

Example : Positional Parameter List

This example uses a positional parameter list to execute macro new_emp2. See “CREATE MACRO” in SQL Data Definition Language. Note that a value is not specified for the dept parameter, which has a macro‑defined default value. A comma is entered in the dept position to maintain the integrity of the positional sequence.

     EXECUTE new_emp2 (10021, 'Smith T', , 'Manager', 'F', 'May 8, 1959',
             16);

Example : Automatically Inserted Value

When the following request is processed, the default value for the dept parameter (900) is inserted automatically. The row for new employee Smith is added to the employee table, and then the department table is updated by incrementing the value for Department 900 in the emp_count column. The request uses a named parameter list to execute a macro named new_hire. Note that the value of the DOH (Date of Hire) column is an expression involving the DATE constant.

     EXECUTE new_hire (fl_name='Toby Smith', title='Programmer', 
             doh=DATE -1);

Example : Invoking an SQL UDF as an Argument to Macro Execution

The following example invokes the SQL UDF value_expression as an argument to the macro m1.

     EXECUTE m1 (test.value_expression(1,2), 2, 3);

See SQL Stored Procedures and Embedded SQL for information about the embedded SQL EXEC statement, which is used to run macros from embedded SQL applications.