create table monthly_sum (yearmonth char(6) primary key,msum decimal (10,2)); insert into monthly_sum values ('201001',100),('201002',200),('201003',400),('201004',500);
Which is the equivalent to the REPLACE
statement below?
replace into monthly_sum values ('201001',1202.13); a) insert into monthly_sum values ('201001',1202.13) ON DUPLICATE KEY UPDATE msum=1202.13; b) update monthly_sum set msum=1202.13 where yearmonth='201001'; c) insert into monthly_sum select '201001',1202.13 from dual where not exists (select 1 from monthly_sum where yearmonth='201001'); d) delete from monthly_sum where yearmonth='201001'; insert into monthly_sum values ('201001',1202.13);
[ Updating Data (10%) - The REPLACE Statement ]
Answer:
d
A
REPLACE
does aDELETE
and anINSERT
. Answer a does anINSERT
and anUPDATE
.c only inserts, if the row does not exist.