insert - Oracle merge into statement -


trying insert lists python oracle database. want insert 4 pieces of data each list oracle , if 3 of data entries match want update. if don't match want insert.

equip_id parameter_name parameter_value customer 

so 1 entry if equip_id, parameter_name, , customer match entry in db want update parameter value. if don't match want insert of data db. have far doesn't seem working.

merge dbname.tablename    using '26522931','customer','para001','99999'   on (tablename.equipment_node_id = '26522931' , tablename.stream_name = 'customer' , tablename.parameter_name = 'para000') when matched   update set tablename.parameter_value = '99999' when not matched    insert (equipment_node_id,stream_name,parameter_name,parameter_value) values('26522931','customer','para000','99999') 

my guess want this. you'll need select data dual if don't have other table use source.

merge dbname.tablename    using (select '26522931' equipment_node_id,                 'customer' stream_name,                 'para001'  parameter_name,                 '99999'    parameter_value             dual) src   on (tablename.equipment_node_id = src.equipment_node_id     , tablename.stream_name = src.stream_name     , tablename.parameter_name = src.parameter_name ) when matched   update set tablename.parameter_value = src.parameter_value when not matched    insert (equipment_node_id,           stream_name,           parameter_name,           parameter_value)      values(src.equipment_node_id,            src.stream_name,            src.parameter_name,            src.parameter_value)  

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -