简体   繁体   English

更新Oracle 11g数据库中用户的最新行?

[英]Updating the latest row for a user in an Oracle 11g database?

My code is in this sqlFiddle . 我的代码在此sqlFiddle中

Creating the table 创建表

create table my_table ( pk number, created date, user_name varchar2(200), start_date date);

insert into my_table (pk, created,user_name) values (1, sysdate-1, 'bob');
insert into my_table (pk, created,user_name) values (2, sysdate-2, 'frank');
insert into my_table (pk, created,user_name) values (3, sysdate,'bob');
insert into my_table (pk, created,user_name) values (4, sysdate,'frank');

Updating: 更新中:

update my_table
set start_date = sysdate
  from my_table
 where pk = ( select max(pk) from my_table where user_name = 'bob' );

SQLFiddle gives me this error: SQLFiddle给我这个错误:

ORA-00933: SQL command not properly ended : update my_table set start_date = sysdate from my_table where pk = ( select max(pk) from my_table where user_name = 'bob' )

But I'm sure I have a semicolon in there in the right place. 但我确定我在正确的位置插入了分号。

What gives? 是什么赋予了? I'm quite new to SQL, and thought this would work. 我对SQL还是很陌生,并认为这可以工作。

You don't need the from : 您不需要from

update my_table
    set start_date = sysdate
     where pk = ( select max(pk) from my_table where user_name = 'bob' );

Remove the from clause, you already have it at the top: 删除from子句,您已经在顶部了:

update my_table
set start_date = sysdate
 where pk = ( select max(pk) from my_table where user_name = 'bob' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM