EXECUTE (Macro Form) - Teradata Database

SQL Data Manipulation Language

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

EXECUTE (Macro Form)

Purpose  

Performs a macro.

Syntax  

where:

 

Syntax Element …

Specifies …

macro_name

the name of the macro that is to be executed.

constant_expression

a constant or an expression involving constants that specifies a parameter value.

Values are listed in left‑to‑right order according to the order in which parameter names were specified in the CREATE MACRO request definition. You can specify nulls by typing successive COMMA characters, for example, (a, , b).

This is referred to as a positional parameter list.

If a value is not supplied for a parameter, a comma must be entered to account for the missing parameter.

Any default value defined for that parameter is inserted automatically.

parameter_name
= constant_expression

a parameter name as defined in the CREATE MACRO request, and supplies the value for that parameter.

This is referred to as a named parameter list.

The value can be a constant, or an expression involving constants.

If a parameter is omitted, any default value defined for that parameter is inserted automatically.

ANSI Compliance

EXECUTE is a Teradata extension to the ANSI SQL:2011 standard.

Required Privileges

You must have EXECUTE privilege on the macro. The creator or any owner of the macro can grant the EXECUTE privilege to another. In addition, the immediate owner of the macro (the database in which the macro resides) must have the necessary privileges on objects named in the request set that are contained in the macro.

For more information, see SQL Data Definition Language and Database Administration.

Recommendation

A data definition request in a macro is not fully resolved until the macro is submitted for execution. Unqualified references to database objects are resolved at that time using the default database of the executing user.

Because of this, object references in data definition statements should always be fully qualified (as databasename.tablename) in the body of the macro.

Rules for Performing Macros

The following rules apply to performing macros.

  • The number of commas must match the macro definition if you do not use the parameter_name syntax.
  • Any value in the EXECUTE constant expression list form without a specified parameter name can be a constant or an expression involving constants. In this context, DATE, TIME, and USER are considered constants.
  • If an error message is returned when a macro is executed, it can be caused by an SQL request in the macro.
  • The number of parameters used in the calling sequence must be equal to the number of parameters defined.
  • When, for example, two parameters are defined and used, if they are both null, the following requests are all valid unless defaults are specified in the macro definition:
  •      EXECUTE macro_1 '(, 1);
         EXECUTE macro_1 (,);
         EXECUTE macro_1 (NULL, NULL);

    Access Logging and Errors

    Any syntactic or semantic error identified and reported by the SQL parser results in an error being returned to you without logging the request.

    Example  

    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  

    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  

    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);

    Related Topics

    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.