2014-09-01 65 views
0

我試圖從select語句更新兩列,但我得到的是說從select語句更新兩列?

ORA-00927: missing equal sign 

請,誰能告訴我,爲什麼錯誤信息?

UPDATE table1 a 
    SET co1 ,co2 = (SELECT COUNT (*), 
          sum(cost)/4 
        FROM table2 b 
        WHERE a.customer_id = b.cust_info_customer_id 
         AND tariff_info = 2); 
+2

'co1'和'co2'需要用括號括起來,像這樣'..設置(COL1,COL2)=(選擇..,.. from ..)'。 – 2014-09-01 08:46:30

+0

@NicholasKrasnov由於他使用的是沒有「GROUP BY」的聚合函數,它保證只返回一行。 – Barmar 2014-09-01 08:47:24

回答

-1

既然你沒有提供任何輸入:

create table table1(
    co1 number, 
    co2 number, 
    customer_id number 
) 
insert into table1 values (1,1, 1) 

select * from table1 

CO1 CO2 CUSTOMER_ID 
------------------- 
    1 1   1 

UPDATE table1 a 
    SET co1 = (
       with table2 as (
       select level cost, 1 cust_info_customer_id from dual connect by rownum < 5 
      ) 
      SELECT COUNT (*) 
       FROM table2 b 
       WHERE a.customer_id = b.cust_info_customer_id 
      ) 
    , co2 = (
       with table2 as (
       select level cost, 1 cust_info_customer_id from dual connect by rownum < 5 
      ) 
      SELECT sum(cost)/4 
       FROM table2 b 
       WHERE a.customer_id = b.cust_info_customer_id 
      ) 
select * from table1 

CO1 CO2 CUSTOMER_ID 
------------------- 
    4 2.5   1 
+0

爲什麼是-1?我看到這個答案沒有問題。 – zaratustra 2014-09-02 12:01:53