【问题标题】:Update in one single Oracle Query在一个 Oracle 查询中更新
【发布时间】:2018-11-11 02:34:02
【问题描述】:

我尝试在 Oracle 数据库中编写单个代码,但无法将其合并到单个查询中,当我最初运行代码时,我收到“ORA-00933:SQL 命令未正确结束错误。我也尝试使用 FOR LOOP , CASE 语句,但它仍然没有用。你能告诉我如何在一个代码中合并查询吗?

要求 在 DTW 上创建列 CIDO 并将数据从 V 插入 DTW 必须满足以下条件 CIDO = CID 作为连接的一部分,我必须使用左连接到来自 V 的 CID 和来自 Q 的 SID 上的 Q 表 然后需要用 Q 中的 CFCID 更新 DTW 中归档的 CID,其中 CCode from V = MX00

我写了:

Alter table DTW add CIDO  -- added column 


Select  V.CID from  V,Q  where  V.CID=Q.SID 
Insert into DTW (CIDO)
Select V.CID from  V 
Left outer join Q  on V.CID = Q.SID 

Update DTW
Set CIDO = (select V.CID from V, Q
Where V.CID=Q.CFCID)

【问题讨论】:

    标签: oracle11g outer-join insert-update insert-into


    【解决方案1】:

    好吧,你没有说你是如何运行这个的,所以我假设是 sqlplus。那里有 4 个不同的命令。在命令行中,您需要运行每一个并放置一个 ;在每个结尾。

    -- Pretty sure your syntax is wrong here. What's the datatype of CIDO?
    Alter table DTW add CIDO;
    
    -- This will just display a list of CIDs, not sure if that's what you want.
    Select  V.CID from  V,Q  where  V.CID=Q.SID;
    
    -- This will insert one or more rows from V and Q
    Insert into DTW (CIDO)
    Select V.CID from  V 
    Left outer join Q  on V.CID = Q.SID;
    
    -- This will update all the rows in DTW to the same value, which is probably not what
    -- you want. Also, if there's more than one row in this subquery, it will raise an error.
    Update DTW
    Set CIDO = (select V.CID from V, Q
    Where V.CID=Q.CFCID);
    

    【讨论】:

      猜你喜欢
      • 2018-05-29
      • 2015-09-02
      • 2020-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多