Getting an error: "Keyword ORDER not expected" when creating an AS400 view

Getting an error: "Keyword ORDER not expected" when creating an AS400 view

我正在使用 System i 导航器来创建视图。 我的看法很简单:

   SELECT MOMAST.ORDNO, MOMAST.FITEM
   FROM AMFLIBT.MOMAST AS MOMAST
   WHERE MOMAST.FITEM LIKE 'POS-%'
   GROUP BY  MOMAST.ORDNO,MOMAST.FITEM
   ORDER BY MOMAST.FITEM,MOMAST.ORDNO

单击“确定”按钮创建视图时,出现以下错误:

SQL0199] Keyword ORDER not expected. Valid tokens: . Cause . . . . . : The keyword ORDER was not expected here. A syntax error was detected at keyword ORDER. The partial list of valid tokens is .

当我删除 ORDER BY 语句时,视图创建成功。

我需要使用 ORDER BY 语句创建我的视图,我怎样才能不出错地完成这个任务?

视图是一个关系 table,关系模型将 table 定义为一组行。由于集合未排序 - 根据定义 - 视图中的行也未排序。因此,视图定义中的 ORDER BY 子句是没有意义的。 SQL 标准 (SQL:2003) 不允许在 CREATE VIEW 语句的子选择中使用 ORDER BY 子句,就像在 CREATE TABLE 陈述。

对于您的情况,我建议创建不带 ORDER BY 语句的视图,并在从视图中选择时(而不是在创建视图时)使用此语句。