Example: Creating a Procedure that Performs a Consume Mode SELECT - Teradata Vantage - Analytics Database

SQL Data Definition Language Syntax and Examples

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2025-11-22
dita:mapPath
jco1628111346878.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
mdr1472255012272
lifecycle
latest
Product Category
Teradata Vantage™

The following example is similar to “Example: Creating a Procedure with Parameters and Local Variables” except that it performs a consume mode SELECT into a queue table. For information about the SELECT AND CONSUME statement, see Teradata Vantage™ - SQL Data Manipulation Language, B035-1146.

    CREATE PROCEDURE spSampleQ(IN  ip INTEGER, 
                               OUT op INTEGER)
    BEGIN DECLARE qits   TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6),
                  qsn    INTEGER GENERATED ALWAYS AS IDENTITY,
                  qcol_1 INTEGER,
                  qcol_2 INTEGER;
      SELECT AND CONSUME TOP 1 qits, qsn, qcol_1, qcol_2 
       INTO c_qits, c_qsn, c_qcol_1, c_qcol_2
      FROM qtab1e; 
    END;

Note that you must specify an AND CONSUME TOP 1 phrase in your SELECT statement to consume rows from a queue table. The AND CONSUME keywords indicate that the request is a consume mode request, while TOP 1 indicates that the oldest row from the queue table is to be retrieved.