on 01-26-2015 2:36 PM
Dear all,
I am writing an procedure where I need to use the length of an array to do the for loop.
The length() is not right. I google it , there is no answer.
PN2 := ARRAY_AGG(:TAB1.POINT ORDER BY POINT); | |
FOR I in 1..LENGTH(PN2) DO |
Is anyone know the function. Thanks a lot.
Shu
The whole program:
DROP PROCEDURE TRAFFIC.ARRAY_AGG_TEST;
CREATE PROCEDURE ARRAY_AGG_TEST()
LANGUAGE SQLSCRIPT AS
BEGIN
DECLARE PN2 Integer ARRAY;
DECLARE PN1 INTEGER ARRAY;
DECLARE TEMPN INTEGER ARRAY;
DECLARE I INTEGER;
TAB1 = SELECT DISTINCT(POINT_2) AS POINT FROM "TRAFFIC"."PAIRSPD";
PN2 := ARRAY_AGG(:TAB1.POINT ORDER BY POINT);
FOR I in 1..LENGTH(PN2) DO
TAB2 = SELECT POINT_1 AS POINT, COUNT(*) AS NUMM FROM "TRAFFIC"."PAIRSPD" WHERE POINT_2 = :ID[I] GROUP BY POINT_1 ORDER BY NUMM DESC;
TEMPN := ARRAY_AGG(:TAB2.POINT);
PN1[I] := TEMPN[1];
END FOR;
TAB3 = UNNEST(:PN1,:PN2);
SELECT * FROM TAB3;
END;
CALL ARRAY_AGG_TEST();
Instead of googling you might just press F1 in SAP HANA Studio and have a look into the SQLScript documentation.
The function to return the number of elements in an ARRAY is called CARDINALITY.
- Lars
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.