How to Create or Replace an SQL Stored Procedure | Basic Teradata Query - Creating or Replacing an SQL Stored Procedure - Basic Teradata Query

Basic Teradata® Query Reference - 20.00

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
Lake
VMware
Product
Basic Teradata Query
Release Number
20.00
Published
October 2023
ft:locale
en-US
ft:lastEdition
2025-04-02
dita:mapPath
gxl1691484661681.ditamap
dita:ditavalPath
obe1474387269547.ditaval
dita:id
psp1479308573013
Product Category
Teradata Tools and Utilities

To create an SQL stored procedure, invoke a text editor to create a file named example.spl, and enter the SQL stored procedure source text:

CREATE PROCEDURE samplesp1 ()
BEGIN
   /* SPL Statements*/
DECLARE V1 INTEGER;
SET V1 = 100;
END;

The preceding example creates a procedure without parameters.

To replace this with another SQL stored procedure with parameters, create a file named example1.spl, and enter the SQL stored procedure source text:

REPLACE PROCEDURE samplesp1 (IN pAccountNo INTEGER, OUT pAmount DECIMAL (10,2))
BEGIN
   /* SPL Statements*/
   SELECT : Amount
   INTO : pAmount
   FROM : Account1 WHERE
   aCCTnO = :pAccountNo;
END;

Submit the COMPILE command with this file name.