找的资料都是判断一个表中有没有数据而去插入或更新另外一个表,我想用的是,就是判断本表中有没有某条数据,有就更新,没有就插入,用merge inot 能实现不?下面就是我判断表usermc_cache_t 中存在sid='8000000044' and mcid='000005'的记录没,有就更新,没有就插入,可执行没效果,问题在那?高手给指点下
merge into usermc_cache_t a
using (select * from usermc_cache_t where sid='8000000044' and mcid='000005') b on(a.sid=b.sid and a.mcid=b.mcid)
when MATCHED then update set oprtype='U',oprdate=sysdate
when not matched then insert(a.sid,a.mcid,a.oprtype,a.oprdate) values('8000000044','000005','A',sysdate)
merge into usermc_cache_t a
using (select * from usermc_cache_t where sid='8000000044' and mcid='000005') b on(a.sid=b.sid and a.mcid=b.mcid)
when MATCHED then update set oprtype='U',oprdate=sysdate
when not matched then insert(a.sid,a.mcid,a.oprtype,a.oprdate) values('8000000044','000005','A',sysdate)
解决方案 »
- Oracle各种锁区别
- oracle的单引号 和双引号的问题 疑惑。
- oracle实现类似于Java语言中String的split方法, 达人进!
- 又是一个关于输出格式的问题
- pl/sql中跳过某个循环
- Oracle8.0.5 TNS问题,苦恼中,请帮忙。
- 数据导入问题,出现ORACLE 的 922 错误,请帮忙解答,谢谢大家
- 创建数据库发生从未碰到过的问题,请帮忙看一下
- 如何实现在oracle一个数据库中实时的从另一个数据库的一张表中取得其新增数据,并插入
- 当A表中某一字段更新时,B表内容复制一遍改变某一字段插入B表
- 关于“ORA-00917: 缺少逗号”错误
- 怎么将SQL2008中的函数和存储过程导入到Oracle中
using (select * from usermc_cache_t where sid='8000000044' and mcid='000005') b on(a.sid=b.sid and a.mcid=b.mcid)
when MATCHED then update set oprtype='U',oprdate=sysdate
when not matched then insert(a.sid,a.mcid,a.oprtype,a.oprdate) values('8000000044','000005','A',sysdate)
select * from usermc_cache_t where sid='8000000044' and mcid='000005' 先把这些数据移到另一个临时表中试试看!
替换成(select '8000000044' sid,'000005' mcid from dual)
否则你的b视图可能会为空,when不成立
using usermc_cache_t b on(a.sid=b.sid and a.mcid=b.mcid and b.sid='8000000044' and b.mcid='000005')
when MATCHED then update set oprtype='U',oprdate=sysdate
when not matched then insert(a.sid,a.mcid,a.oprtype,a.oprdate) values('8000000044','000005','A',sysdate)
using (select '8000000044' as sid1, '000005' as mcid1, 'U' as oprtype1, sysdate as oprdate1 from dual) b on(a.sid=b.sid1 and a.mcid=b.mcid1)
when MATCHED then update set oprtype=b.oprtype1,oprdate=b.operdate1
when not matched then insert(a.sid,a.mcid,a.oprtype,a.oprdate) values(b.sid1,b.mcid1,b.oprtype1,b.oprdate1)
when not matched then insert(sid,mcid,oprtype,oprdate) values('8000000044','000005','A',sysdate)