简体   繁体   English

此Oracle查询有什么问题?

[英]What's wrong with this Oracle query?

Below is a query generated by the PetaPoco ORM for .NET. 以下是由PetaPoco ORM for .NET生成的查询。 I don't have an Oracle client right now to debug it and I can't see anything obviously wrong (but I'm a SQL Server guy). 我现在没有Oracle客户端可以对其进行调试,并且看不到任何明显错误的内容(但是我是SQL Server专家)。 Can anyone tell me why it is producing this error: 谁能告诉我为什么会产生此错误:

Oracle.DataAccess.Client.OracleException ORA-00923: FROM keyword not found where expected Oracle.DataAccess.Client.OracleException ORA-00923:在预期位置找不到FROM关键字

SELECT * 
FROM (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) peta_rn, 
"ON_CUST_MAS"."CU_NO", 
"ON_CUST_MAS"."CU_NAME", 
"ON_CUST_MAS"."CU_TYPE", 
"ON_CUST_MAS"."CONTACT", 
"ON_CUST_MAS"."ADD1_SH", 
"ON_CUST_MAS"."ADD2_SH", 
"ON_CUST_MAS"."CITY_SH", 
"ON_CUST_MAS"."POST_CODE", 
"ON_CUST_MAS"."PROV_SH", 
"ON_CUST_MAS"."COUNTRY", 
"ON_CUST_MAS"."PHONE_NU", 
"ON_CUST_MAS"."FAX_NU", 
"ON_CUST_MAS"."EMAIL", 
"ON_CUST_MAS"."PU_ORDER_FL", 
"ON_CUST_MAS"."CREDIT_AMOUNT" 
FROM "ON_CUST_MAS" ) peta_paged 
WHERE peta_rn>0 AND peta_rn<=20

Edit: Just in case it helps, this is a paging query . 编辑:以防万一,这是一个分页查询 Regular queries (select all, select by ID) are working fine. 常规查询(全选,按ID选择)工作正常。

The problem is that the SELECT NULL in the ORDER BY clause of your analytic function is syntactically incorrect. 问题是分析函数的ORDER BY子句中的SELECT NULL在语法上不正确。

over (ORDER BY (SELECT NULL))

could be rewritten 可以改写

(ORDER BY (SELECT NULL from dual))

or more simply 或更简单

(ORDER BY null)

Of course, it doesn't really make sense to get a row_number if you aren't ordering the results by anything. 当然,如果您不按任何顺序对结果进行排序,那么获取row_number并没有任何意义。 There is no reason to expect that the set of rows that are returned would be consistent-- you could get any set of 20 rows arbitrarily. 没有理由期望返回的行的集合是一致的-您可以任意获得20个行的任何集合。 And if you go to the second page of results, there is no reason to expect that the second page of results would be completely different than the first page or that any particular result would appear on any page if you page through the entire result set. 而且,如果您转到结果的第二页,则没有理由期望结果的第二页与第一页完全不同,或者如果您浏览整个结果集,则任何特定的结果都会出现在任何页面上。

There should be and order defined within ORDER BY clause. 在ORDER BY子句中应定义和顺序。 For example, lets say your elements are displayed in order of column "on_cust_mas"."cu_no" , than your query should look like: 例如,假设您的元素按列"on_cust_mas"."cu_no"顺序显示,则查询应如下所示:

SELECT *
FROM   (SELECT Row_number()
                 over (
                   ORDER BY ("on_cust_mas"."cu_no")) peta_rn,
               "on_cust_mas"."cu_no",
               "on_cust_mas"."cu_name",
               "on_cust_mas"."cu_type",
               "on_cust_mas"."contact",
               "on_cust_mas"."add1_sh",
               "on_cust_mas"."add2_sh",
               "on_cust_mas"."city_sh",
               "on_cust_mas"."post_code",
               "on_cust_mas"."prov_sh",
               "on_cust_mas"."country",
               "on_cust_mas"."phone_nu",
               "on_cust_mas"."fax_nu",
               "on_cust_mas"."email",
               "on_cust_mas"."pu_order_fl",
               "on_cust_mas"."credit_amount"
        FROM   "on_cust_mas") peta_paged
WHERE  peta_rn > 0
       AND peta_rn <= 20

If this is a different column that sets the order just switch it within ORDER BY clause. 如果这是设置顺序的其他列,则只需在ORDER BY子句中进行切换即可。 In fact there should be any order defined, otherwise it's not guaranteed that it won't change, and you cant be sure what will be displayed at any page. 实际上,应该定义任何顺序,否则不能保证它不会更改,并且您不能确定将在任何页面上显示什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM