Example: Creating an SQL Procedure with a Multiple-Statement Request - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

The following procedure runs the statements in the multiple-statement request in parallel:

    CREATE PROCEDURE salesadjust(IN item    INTEGER, 
                                 IN numsold INTEGER)
      BEGIN
        DECLARE price DECIMAL(8,2);
        SELECT item_price INTO price 
        FROM pricetbl 
        WHERE item = pricetbl.item_no;
        BEGIN REQUEST
          UPDATE sales_summary
          SET total_sales = total_sales + price * numsold
          WHERE item = sales_summary.item_no
          ;UPDATE inventory
          SET item_no = item_no - numsold
          WHERE item = inventory.item_no;
        END REQUEST;
      END;

The stages in the process followed by this procedure are as follows:

  1. The price of an item is retrieved from pricetbl.
  2. The total sales amount is computed by multiplying the total price by the number of items sold.
  3. Two update requests are dispatched to the AMPs in parallel:

    The first updates a total_sales summary table that keeps track of the cash made on all items sold.

    The second adjusts inventory to reflect the remaining quantity stocked for that item.