ORACLE和SQL SERVER的SQL语法是不同的,特别是UODATE语句。ORACLE中这么写UPDATE语句是错误的。你可以试试下面的语句: update ht_zygl set rkrq = ( select REPLACE(createdate, '- ', ' ') from sherc_res where a.id=ht_zygl.id ) where exists ( select REPLACE(createdate, '- ', ' ') from sherc_res where a.id=ht_zygl.id )
可不可用这个 MERGE INTO ht_zygl a USING sherc_res b ON (a.id = b.id) WHEN MATCHED THEN UPDATE SET rkrq = REPLACE(b.createdate,'-','') WHEN NOT MATCHED THEN delete where 1=01。其实这里数据不匹配是不操作的 它老是提示缺少关键字 2。 用这个是不是快点我的记录很多的
to:TodayZ 谢谢你的回答。想再请教下。大家帮忙回答下。相信一开始大家都碰到过这个问题
Sorry ,有点失误,忘记去掉"a."了,正确的写法是: update ht_zygl set rkrq = ( select REPLACE(createdate, "- ", " ") from sherc_res where id=ht_zygl.id ) where exists ( select REPLACE(createdate, "- ", " ") from sherc_res where id=ht_zygl.id ) ; 你可以再试试。
几点说明: 1。按照你的最开始的语句,应该是id在sherc_res表中是主键或唯一键。如果在 ht_zygl表中的id在sherc_res表中存在,就用REPLACE(sherc_res.createdate, "- ", " ")的值替换ht_zygl中rkrq的值。从我给你的语句中,set rkrq = ( select REPLACE(createdate, "- ", " ") from sherc_res where id=ht_zygl.id ) 是赋值。exists ( select REPLACE(createdate, "- ", " ") from sherc_res where id=ht_zygl.id ) 是判断 ht_zygl表中的id在sherc_res表中存在。这个和你的需求是一致的2。 2。ORACLE的更新感觉比SQL SERVER慢一些,主要是涉及到回滚段等等的问题,这个有一些办法可以去改进,但都比较复杂。最简单的方法是每次批量处理一部分,比如一次一千条或一万条之类的,具体的方法是在where后面再加写条件,比如: update ht_zygl set rkrq = ( select REPLACE(createdate, '- ',' ') from sherc_res where id=ht_zygl.id ) where exists ( select REPLACE(createdate, '- ',' ') from sherc_res where id=ht_zygl.id ) and id between 1 and 1000 ; 3。用MERGE和你的需求不符。MERGE的用法是存在的就修改,不存在的就新增。 4。 REPLACE(createdate, "- ", " ") 应该是 REPLACE(createdate, '- ',' ') , 不能用双引号要用单引号。
update ht_zygl
set rkrq = ( select REPLACE(createdate, '- ', ' ') from sherc_res where a.id=ht_zygl.id )
where exists ( select REPLACE(createdate, '- ', ' ') from sherc_res where a.id=ht_zygl.id )
MERGE INTO ht_zygl a USING sherc_res b ON (a.id = b.id)
WHEN MATCHED THEN
UPDATE SET rkrq = REPLACE(b.createdate,'-','')
WHEN NOT MATCHED THEN
delete where 1=01。其实这里数据不匹配是不操作的 它老是提示缺少关键字
2。 用这个是不是快点我的记录很多的
update ht_zygl
set rkrq = ( select REPLACE(createdate, "- ", " ") from sherc_res where id=ht_zygl.id )
where exists ( select REPLACE(createdate, "- ", " ") from sherc_res where id=ht_zygl.id ) ;
你可以再试试。
1。按照你的最开始的语句,应该是id在sherc_res表中是主键或唯一键。如果在 ht_zygl表中的id在sherc_res表中存在,就用REPLACE(sherc_res.createdate, "- ", " ")的值替换ht_zygl中rkrq的值。从我给你的语句中,set rkrq = ( select REPLACE(createdate, "- ", " ") from sherc_res where id=ht_zygl.id ) 是赋值。exists ( select REPLACE(createdate, "- ", " ") from sherc_res where id=ht_zygl.id ) 是判断 ht_zygl表中的id在sherc_res表中存在。这个和你的需求是一致的2。
2。ORACLE的更新感觉比SQL SERVER慢一些,主要是涉及到回滚段等等的问题,这个有一些办法可以去改进,但都比较复杂。最简单的方法是每次批量处理一部分,比如一次一千条或一万条之类的,具体的方法是在where后面再加写条件,比如:
update ht_zygl
set rkrq = ( select REPLACE(createdate, '- ',' ') from sherc_res where id=ht_zygl.id )
where exists ( select REPLACE(createdate, '- ',' ') from sherc_res where id=ht_zygl.id )
and id between 1 and 1000 ;
3。用MERGE和你的需求不符。MERGE的用法是存在的就修改,不存在的就新增。
4。 REPLACE(createdate, "- ", " ") 应该是 REPLACE(createdate, '- ',' ') , 不能用双引号要用单引号。