insert into tree(id,name,pid) select '101','test','10' from dual where not exists(select 1 from tree where id='101');or
insert when (not exists (select 1 from tree where id='101')) then into tree(id,name,pid) select '101','test','10' from dual;
本文介绍了一种使用 SQL 语句向具有树形结构的表中插入记录的方法。通过判断记录是否已存在来决定是否执行插入操作。该方法适用于需要维护树状数据结构的应用场景。
insert into tree(id,name,pid) select '101','test','10' from dual where not exists(select 1 from tree where id='101');insert when (not exists (select 1 from tree where id='101')) then into tree(id,name,pid) select '101','test','10' from dual;
2769

被折叠的 条评论
为什么被折叠?