0

I have this query that I have to convert to Oracle SQL.

UPDATE Active_Exclusions
LEFT JOIN Active_Exclusions_Full ON 

Active_Exclusions.Exclude_Reason = Active_Exclusions_Full.Exclude_Reason AND 
Active_Exclusions.ViantID = Active_Exclusions_Full.ViantID 

SET Active_Exclusions.ViantID = Null, 
Active_Exclusions.Date_Resolved = Date,
Active_Exclusions.Resolution = "Resolved"

WHERE Active_Exclusions.ViantID Is Not Null AND 
Active_Exclusions_Full.ViantID Is Null AND 
Active_Exclusions.Exclude_Reason<>"PCP not in RSA County";

There's an evil join as well as what it sets are static things such as "Null" or "Resolved" and not part of another query.

I've tried various things and can't make this work. Any help?

4

3 回答 3

0

日期将是 date() (即当前日期)当我尝试运行您所拥有的内容时,它说“ViantID”不是有效的标识符。

(SELECT agp_mpi_prov_quality_history.viant_id, AGP_MPI_PROV_QUALITY_HISTORY.RESOLUTION1
FROM AGP.AGP_MPI_PROV_QUALITY_HISTORY AGP_MPI_PROV_QUALITY_HISTORY, 
AGP.AGP_MPI_PROV_QUALITY_CURRENT AGP_MPI_PROV_QUALITY_CURRENT
    WHERE AGP_MPI_PROV_QUALITY_HISTORY.Exclude_Reason = AGP_MPI_PROV_QUALITY_current.Exclude_Reason
    AND AGP_MPI_PROV_QUALITY_HISTORY.Viant_ID = AGP_MPI_PROV_QUALITY_current.Viant_ID
    AND AGP_MPI_PROV_QUALITY_HISTORY.Viant_ID IS NOT NULL
    AND AGP_MPI_PROV_QUALITY_current.Viant_ID IS NULL
    AND AGP_MPI_PROV_QUALITY_HISTORY.Exclude_Reason <> 'PCP not in RSA County')

这有效,但是当我将它包装在

UPDATE( QUERY HERE ) 
Set Viant_id = null  (for ease of use just one)

我收到此错误:QL 错误:ORA-01779:无法修改映射到非键保留表 01779 的列。00000 -“无法修改映射到非键保留表的列” *原因:尝试是用于插入或更新映射到非键保留表的连接视图的列。*行动:直接修改基础基表。

于 2013-10-24T12:38:51.810 回答
0

你能解释一下这次更新的目的是什么吗?你为什么要外连接,然后在左边的表上更新?这几乎没有加入本身的目的,不是吗?

如果您的意图是仅在结果行上进行内部联接和更新,则语法将如下所示:当且仅当两个表之间存在由 FOREIGN KEY 定义的明确关系时,这将为您完成工作,这意味着存在由子表中的键产生的父(正在更新)上的单个记录。

UPDATE (SELECT ae.ViantID, ae.Date_Resolved, ae.Resolution
          FROM Active_Exclusions ae, Active_Exclusions_Full aef
         WHERE ae.Exclude_Reason =
                  aef.Exclude_Reason
               AND ae.ViantID = Active_Exclusions_Full.ViantID
               AND ae.ViantID IS NOT NULL
               AND aef.ViantID IS NULL
               AND ae.Exclude_Reason <>
                      'PCP not in RSA County')
   SET ViantID = NULL, Date_Resolved = Date, Resolution = 'Resolved';

另请注意,您使用由名称“日期”定义的字段将是一个问题。那是一个关键字,如果不可能的话,您最好为该列使用不同的名称,或者至少将其括在双引号“日期”中(也要加上适当的别名)。

于 2013-10-23T18:31:34.433 回答
0

好的!我发现这有效:

update agp_mpi_prov_quality_history
set viant_id = null
where exists
   (SELECT agp_mpi_prov_quality_history.viant_id
   FROM AGP.AGP_MPI_PROV_QUALITY_HISTORY AGP_MPI_PROV_QUALITY_HISTORY, 
   AGP.AGP_MPI_PROV_QUALITY_CURRENT AGP_MPI_PROV_QUALITY_CURRENT
   WHERE AGP_MPI_PROV_QUALITY_HISTORY.Exclude_Reason = AGP_MPI_PROV_QUALITY_current.Exclude_Reason
   AND AGP_MPI_PROV_QUALITY_HISTORY.Viant_ID = AGP_MPI_PROV_QUALITY_current.Viant_ID
   AND AGP_MPI_PROV_QUALITY_HISTORY.Viant_ID IS NOT NULL
   AND AGP_MPI_PROV_QUALITY_current.Viant_ID IS NULL
   AND AGP_MPI_PROV_QUALITY_HISTORY.Exclude_Reason <> 'PCP not in RSA County')
于 2013-10-24T14:07:23.707 回答