【问题标题】:Update in pl/sql procedure在 pl/sql 过程中更新
【发布时间】:2021-03-31 08:18:58
【问题描述】:

我正在 plsql oracle 中编写以下代码,以将卖家和产品的评级更新为 order_products 表中给出的平均评级:

create or replace procedure update_seller_product
as

begin
  update product set rating=
     (select rating from 
        (select p_id,avg(rating) as rating 
           from order_products 
          group by p_id
        ) as t2
      )
    where product.p_id=t2.p_id; 
  commit;
end;
/

但它给出了以下错误:

第 4 行的语句被忽略错误:PL/SQL:ORA-00907:缺少右括号

为什么?请帮忙

【问题讨论】:

  • 这能回答你的问题吗? ORA-00907: missing right parenthesis
  • 是的,错误是一样的,但我编写了非常简单的代码,在 sql 上可以正常工作,但在 oracle pl/sql 中却没有

标签: oracle plsql


【解决方案1】:

删除别名的as

CREATE OR REPLACE PROCEDURE update_seller_product
AS
BEGIN
   UPDATE product
      SET rating =
             (SELECT rating
                FROM (  SELECT p_id, AVG (rating) AS rating
                          FROM order_products
                      GROUP BY p_id) t2)        --> here
    WHERE product.p_id = t2.p_id;

   COMMIT;
END;
/

在 Oracle 中,AS 可用于列(但不是必须):

SQL> select dummy as dm,           --> with AS
  2         dummy    dm2           --> without it
  3  from dual;

D D
- -
X X

对于表格,不能使用:

SQL> select dummy from dual as d;
select dummy from dual as d                     --> with AS
                       *
ERROR at line 1:
ORA-00933: SQL command not properly ended


SQL> select dummy from dual d;                  --> without it

D
-
X

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-15
    • 2013-05-16
    • 2015-10-20
    • 2013-01-26
    • 2012-05-23
    • 1970-01-01
    • 2020-09-14
    • 2012-05-23
    相关资源
    最近更新 更多