问题描述
我正在使用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;
ORA-01747: invalid user.table.column,table.column,or column specification
解决方法
不要使用st.rownum。 Rownum是伪列,不属于任何表。
,啊,是的……又一个引发未知错误的查询。
对我来说,它按预期工作。简化:
SQL> update student set fee_call_opt_uid = 'x' where rownum <= 10;
10 rows updated.
SQL>
轮到你了。
再次轮到我:从rownum
删除表别名,这会导致问题(因为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>