我想使用 SQL UDF 聚合一些行。我想首先选择按其 id 排序的行,然后将它们连接到逗号分隔的列中。我的函数中的 order by 子句有错误,因为它位于 for 循环内。有没有办法在不删除 order by 子句的情况下运行它?我的数据库是 DB2
CREATE FUNCTION mySchema.getDates(recId INTEGER)
RETURNS VARCHAR(1024)
LANGUAGE SQL
BEGIN ATOMIC
DECLARE STR VARCHAR(1024);
SET STR = '' ;
LOOP1 : FOR ROW AS (select replace(char(myDate,EUR),'.','/') as myDate from myTable.BookingDates where recId=recId order by rec_crt-id)
DO
IF ROW.myDate IS NOT NULL THEN
SET STR = STR || CAST ( ROW.myDate AS VARCHAR ( 20 ) ) || ', ' ;
END IF ;
END FOR;
RETURN STR ;
END
SQL State: 42601 Vendor Code: -199 Message: [SQL0199] Keyword ORDER not expected. Valid tokens: ) UNION EXCEPT. Cause . . . . . : The keyword ORDER was not expected here.