达梦数据库实现一条sql判断数据是否存在,如存在则修改,不存在,则新增

 

# 达梦数据库实现一条sql判断数据是否存在,如存在则修改,不存在,则新增
MERGE
INTO
	X.TABLE1 T1
		USING (
	SELECT
		3 as id, '名字' as COLUMN_1, 0 as COLUMN_2
	FROM
		DUAL ) T2 ON(T1.id = T2.id)
	WHEN MATCHED THEN
UPDATE SET T1.COLUMN_1 = T2.COLUMN_1,T1.COLUMN_2 = T2.COLUMN_2
	WHEN NOT MATCHED THEN
INSERT(id, COLUMN_1, COLUMN_2)VALUES(T2.id, T2.COLUMN_1, T2.COLUMN_2);

  

posted @ 2024-05-11 14:25  东峰叵,com  阅读(603)  评论(0编辑  收藏  举报