我的資料表是這樣的,實際上是一個bom結構表
end1id:主件id
end2id:子件id
end2basname:子件名稱
quantity:用量

我現在用start with和connect by可以通過一個主件id查詢到整個結構了
但是其中有一些節點(虛擬件),我想要洗掉(或者隱藏)
該節點有上級節點(主件id),也有下級節點(子件id),如果洗掉掉該虛擬件,那下級節點的主件id就應該改變了,用量也一樣改變
請問應該怎么查詢呢?
uj5u.com熱心網友回復:
沒懂起什么意思。。。uj5u.com熱心網友回復:
就是類似這位在sql server中的問題
uj5u.com熱心網友回復:
https://bbs.csdn.net/topics/390714141uj5u.com熱心網友回復:
with tab1 as (select 1 id, null pid from dual union all
select 2 id, 1 pid from dual union all
select 3 id, 2 pid from dual union all
select 4 id, 2 pid from dual union all
select 5 id, 3 pid from dual union all
select 6 id, 3 pid from dual union all
select 7 id, 3 pid from dual
)
,tab2 as (
select t1.id, t1.pid, sys_connect_by_path(t1.id, '/') c_path from tab1 t1
start with t1.id = 1
connect by prior t1.id = t1.pid
), tab3 as (
select t1.*, regexp_replace(t1.c_path, '\/3') new_path from tab2 t1
)
select t1.*, substr(substr(t1.new_path, 1, instr(t1.new_path, '/' || t1.id) - 1), instr( substr(t1.new_path, 1, instr(t1.new_path, '/' || t1.id) - 1), '/', -1 ) + 1) new_p_id from tab3 t1
where t1.id != 3
;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/65075.html
標籤:基礎和管理
