如何限制要使用 oracle 更新的列数?

how to restrict number of columns to be update using oracle?

我正在使用 Oracle 11g。我想限制要更新的列数。我只想更新 300 名学生 Fee_Call_Opt_uid 列。一旦我使用 rownum < 300 它就会抛出错误。

UPDATE student st
   SET st.Fee_Call_Opt_uid =
       (SELECT t.emp_id
          FROM (SELECT DISTINCT eco.emp_id, ct.city_name, con.country_name
                  FROM emp_call_opt eco
                  JOIN territory tr
                    ON tr.territory_id = eco.territory_id
                  JOIN city ct
                    ON ct.territory_id = eco.territory_id
                  JOIN country con
                    ON con.country_id = ct.country_id) t
         WHERE st.city = t.city_name
           AND st.country = t.country_name)
 WHERE st.rownum < 300
   AND st.Fee_Call_Opt_uid IS NULL;

SQL 错误:

ORA-01747: invalid user.table.column, table.column, or column specification 

啊,是的...另一个引发未知错误的查询。

对我来说,它按预期工作。简体:

SQL> update student set fee_call_opt_uid = 'x' where rownum <= 10;

10 rows updated.

SQL>

轮到你了。


又轮到我了:从 rownum 中删除 table 别名,这会导致问题(如 SQL*Plus 用星号很好地指出):

SQL> update student s set s.fee_call_opt_uid = 1 where s.rownum <= 10;
update student s set s.fee_call_opt_uid = 'x' where s.rownum <= 10
                                                    *
ERROR at line 1:
ORA-01747: invalid user.table.column, table.column, or column specification

SQL> update student s set s.fee_call_opt_uid = 'x' where rownum <= 10;

10 rows updated.

SQL>

不要使用 st.rownum。 rownum是一个伪列,不属于任何table.