Example: Creating a Procedure that Consumes a Queue Table - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

The following procedure consumes a shopping cart queue table row that returns the three variables sp_ordernum, sp_product, and sp_quantity:

    CREATE PROCEDURE consumecart(OUT sp_ordernum CHARACTER(15), 
                        OUT sp_product  CHARACTER(30), 
                                 OUT sp_quantity INTEGER) 
    BEGIN 
    SELECT AND CONSUME TOP 1 ordernum, product, quantity INTO 
     :sp_ordernum, :sp_product, :sp_quantity FROM shoppingcart;
    END;

The system retrieves the queue table row at the top of the FIFO queue from a single AMP and deletes the row from the shoppingcart table.

The row was consumed first because its QITS value was the oldest of all rows in the queue. The system builds the response row as specified in the expression list and returns the response row to the requestor in variables.