更新选择ORA-01732

时间:2017-09-11 10:10:42

标签: oracle select plsql

我上了oracle-server ORA-01732。 这个ORA还有其他任何问题,但它对我的情况没有帮助。

我选择了两个表中的一些数据,并将这些内容分组为:

SELECT  SUM (LG_ALL.HOURS) AS hour_sum,
            TO_CHAR (LG_ALL.WORK_DATE, 'YYYY.MM') AS singel_month,
            LG_ALL.EXPORTED
       FROM USER usr, 
            USER_ALLWC LG_ALL, 
      WHERE usr.user_id = LG_ALL.user_id            
            AND LG_ALL.EXPORTED = 'N'   
     GROUP BY 
            TO_CHAR (LG_ALL.WORK_DATE, 'YYYY.MM'),
            LG_ALL.EXPORTED
   ORDER BY usr.LOGNAME DESC 

下一步,我必须设置表USER_ALLWC

  

LG_ALL.EXPORTED =' Y'

因此,我将它包装成update-statement之类的 updates-based-on-queries => Inline View Method

UPDATE (   SELECT  SUM (LG_ALL.HOURS) AS hour_sum,
                TO_CHAR (LG_ALL.WORK_DATE, 'YYYY.MM') AS singel_month,
                LG_ALL.EXPORTED
           FROM USER usr, 
                USER_ALLWC LG_ALL, 
          WHERE usr.user_id = LG_ALL.user_id            
                AND LG_ALL.EXPORTED = 'N'   
         GROUP BY 
                TO_CHAR (LG_ALL.WORK_DATE, 'YYYY.MM'),
                LG_ALL.EXPORTED
       ORDER BY usr.LOGNAME DESC ) allg
SET allg.EXPORTED = 'Y';

可悲的是,我得到了ORA-01732。 任何人都可以解释,当我可以更新select语句,我该如何解决它?

1 个答案:

答案 0 :(得分:1)

来自Oracle SQL Language Reference

  

视图不得包含以下任何构造:

     
      
  • 集合运算符

  •   
  • DISTINCT运算符

  •   
  • 汇总或分析功能

  •   
     

...

尝试简化它 - sumgroup by等等,无论如何都不添加任何价值:

UPDATE (   SELECT  LG_ALL.EXPORTED
           FROM USER usr, 
                USER_ALLWC LG_ALL, 
          WHERE usr.user_id = LG_ALL.user_id            
                AND LG_ALL.EXPORTED = 'N'   
       ) allg
SET allg.EXPORTED = 'Y';

只要有USER_ALLWCUSER的外键,就可以使用。

事实上,假设 这样的外键,整个陈述相当于:

UPDATE USER_ALLWC
   SET EXPORTED = 'Y'
 WHERE EXPORTED = 'N';