Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 是否从select语句更新两列?_Oracle - Fatal编程技术网

Oracle 是否从select语句更新两列?

Oracle 是否从select语句更新两列?,oracle,Oracle,我试图更新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_i

我试图更新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);

由于您没有提供任何输入:

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

co1和co2需要用括号括起来,如下所示。。设置col1,col2=选择。。from…@NicholasKrasnov因为他使用的是聚合函数,而不使用groupby,所以它保证只返回一行。为什么是-1?我认为这个答案没有问题。