admin管理员组

文章数量:1277373

How to use SEQ in MERGE?

merge into tab_a tgt using 
(Select col1,col2,seq
from tab_a f) src
on 
(joinin condition)
when matched then update 
set 
tgt.seq = src.seq;

It is showing

Sequence number not allowed here

How to achieve this?

How to use SEQ in MERGE?

merge into tab_a tgt using 
(Select col1,col2,seq
from tab_a f) src
on 
(joinin condition)
when matched then update 
set 
tgt.seq = src.seq;

It is showing

Sequence number not allowed here

How to achieve this?

Share Improve this question edited Feb 25 at 9:09 Dale K 27.4k15 gold badges58 silver badges83 bronze badges asked Feb 25 at 6:17 TSBTSB 1058 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

I removed the seq from the source query and added to directly in the update statement, it is working now.

merge into tab_a tgt using 
(Select col1,col2
from tab_a f) src
on 
(joinin condition)
when matched then update 
set 
tgt.seq = seq.nextval;
MERGE INTO employees e
USING (SELECT 101 AS emp_code, 'John Doe' AS emp_name FROM dual) src
ON (e.emp_code = src.emp_code)
WHEN MATCHED THEN
    UPDATE SET e.emp_name = src.emp_name
WHEN NOT MATCHED THEN
    INSERT (emp_id, emp_code, emp_name)
    VALUES (emp_seq.NEXTVAL, src.emp_code, src.emp_name);

本文标签: sqlOracle Sequence in MERGE StatementStack Overflow