1 merge 合并查询
merge into tabl1 a
using (select 1717 product_id, "002" req_no from table2 b
on (a.product_id = b.product_id and a.req_no = b.req_no)
when matched then
update set product_name = "更新", category = "新的"
when not matched then
insert (product_id, req_no) values(1701, "002");
命令解释:
合并查询 表a
关联查询为 b表的product_id字段为1717和req_no字段为"002" 的值
判断条件为 a表的的product_id等于1717和req_no字段为"002"也为002的
当有符合搜索结果的内容时
更新 a表对应的内容的product_name为“更新”,req_no为"002"
当没有符合条件的内容时
执行a表的插入操作
2 start with connect by 递归查询
应用在树形结构中,比如领导和下属的递归关系
start with 从某个节点ID开始 connnect by prior 子节点与父节点的关系
比如:
select * from emp start with empnumber=3306 connect by prior meg=empnumber;
原文:https://www.cnblogs.com/wang-kai-1994/p/10802971.html