Creating Stored Procedures - Teradata VantageCloud Lake

Lake - Working with SQL

Deployment
VantageCloud
Edition
Lake
Product
Teradata VantageCloud Lake
Release Number
Published
February 2025
ft:locale
en-US
ft:lastEdition
2025-11-21
dita:mapPath
jbe1714339405530.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
jbe1714339405530
You can create a stored procedure using either of the following:
  • SQL CREATE PROCEDURE or REPLACE PROCEDURE statement in Teradata Studio Express.
  • COMPILE command with the BTEQ utility.

The procedures are stored in the user database space as objects and are run on the server.

The stored procedure definitions in the next examples are designed only to demonstrate the usage of the feature, and are not recommended for use.

Example: Defining a Stored Procedure for New Employees

Assume you want to define a stored procedure NewProc to add new employees to the Employee table and retrieve the name of the department to which the employee belongs.

You can also report an error, in case the row that you are trying to insert already exists, and handle that error condition.

The CREATE PROCEDURE statement looks like this:

CREATE PROCEDURE NewProc (IN name CHAR(12),
                          IN number INTEGER,
                          IN dept INTEGER,
                          OUT dname CHAR(10))
BEGIN
   INSERT INTO Employee (EmpName, EmpNo, DeptNo )
      VALUES (name, number, dept);
   SELECT DeptName
      INTO dname FROM Department
         WHERE DeptNo = dept;
END;

This stored procedure defines parameters that must be provided for each call.

Related Information

For information on CREATE PROCEDURE and REPLACE PROCEDURE, see CREATE PROCEDURE and REPLACE PROCEDURE (SQL Form) and CREATE PROCEDURE and REPLACE PROCEDURE (External Form).