16.20 - Example: Passing the Value of for a TOP n Operator to an SQL Procedure - Teradata Database - Teradata Vantage NewSQL Engine

Teradata Vantage™ SQL Data Definition Language Syntax and Examples

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-24
dita:mapPath
wkf1512081455740.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.ditaval

The following procedure passes the value for n to the TOP n operator in its SELECT request as the integer parameter a.

     CREATE PROCEDURE fct (IN a INTEGER) 
         BEGIN 
             DECLARE hc1 INTEGER; 
             DECLARE hc2 INTEGER; 
             FOR 
                 RecordPointer AS c_sptable CURSOR FOR 
                 SELECT TOP :a x1 AS c_c1, y1 AS c_c2 
                 FROM t1 
                 DO 
                    SET hc1 = RecordPointer.c_c1; 
                    SET hc2 = RecordPointer.c_c2; 
                    INSERT INTO t2 VALUES (:hc1,:hc2); 
             END FOR ; 
         ROLLBACK; 
         END;