Create Macro in Teradata

Macro is a set of SQL statements which are stored and executed by calling the Macro name. The definition of Macros is stored in Data Dictionary. Users only need EXEC privilege to execute the Macro. Users don't need separate privileges on the database objects used inside the Macro. 

  • Macro statements are executed as a single transaction. If one of the SQL statements in Macro fails, then all the statements are rolled back
  • Macros can accept parameters
  • Macros can contain DDL statements, but that should be the last statement in Macro

Syntax:

CREATE MACRO macroname(parameter1, parameter2,..) (

<sql statements>

);

Example:

CREATE MACRO Get_Emp_Salary(EmployeeNo INTEGER) AS (

SELECT * FROM Salary WHERE EmployeeNo = :EmployeeNo;

);

nVector

posted on 13 May 18

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds