1

这是我到目前为止所拥有的

BEGIN
             UPDATE t1
                set t1.LANGUAGE_ID = (case NETWORK.NID
                        when 11 then 10
                        else 7
                        end)
                FROM PROFILE, NETWORK where
                PROFILE.STATUS in ('A','U','S','H','I')
                AND PROFILE.MID = t1.MID
                AND NETWORK.MID = t1.MID
                AND t1.IS_DELETED = 'N'
END;

得到错误:

"ORA-06550: line 7, column 21:
PL/SQL: ORA-00933: SQL command not properly ended
ORA-06550: line 2, column 18:
PL/SQL: SQL Statement ignored
ORA-06550: line 12, column 4:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

   ( begin case declare end exception exit for goto if loop mod
   null pragma raise return select update while with
   <an identifier> <a double-quoted"

我想在 t1.is_deleted='N' 时更新 t1,并且配置文件中的相同 mid 具有状态 AUSHI。所有表格都有一个中间列。任何想法为什么我会收到此错误?

4

2 回答 2

1

@Justin 提供的解决方案效果很好,但如果您的表很大,请考虑改用 MERGE。使用提供的查询,您将为 table 的每一行运行一次嵌套的 SELECT 查询t1

我发现这个链接非常有用:比较了 8 种批量更新方法

于 2013-08-02T20:29:32.343 回答
1

语句在OracleUPDATE中没有子句。FROM

听起来你想要一个相关的更新

UPDATE t1
   SET t1.language_id = (SELECT (CASE WHEN network.nid = 11 
                                      THEN 10
                                      ELSE 7
                                  END)
                           FROM profile,
                                network
                          WHERE profile.status IN ('A','U','S','H','I')
                            AND profile.mid = t1.mid
                            AND network.mid = t1.mid
                            AND t1.is_deleted = 'N');

如果相关子查询不返回任何行,这将更新每一行t1设置。如果您只想更新子查询返回的匹配行中的行language_idNULLt1

UPDATE t1
   SET t1.language_id = (SELECT (CASE WHEN network.nid = 11 
                                      THEN 10
                                      ELSE 7
                                  END)
                           FROM profile,
                                network
                          WHERE profile.status IN ('A','U','S','H','I')
                            AND profile.mid = t1.mid
                            AND network.mid = t1.mid
                            AND t1.is_deleted = 'N')
  WHERE EXISTS( SELECT 1
                  FROM profile,
                       network
                 WHERE profile.status IN ('A','U','S','H','I')
                   AND profile.mid = t1.mid
                   AND network.mid = t1.mid
                   AND t1.is_deleted = 'N');
于 2013-03-19T15:38:37.427 回答