嗨,我有一個SQL語句使用connect by prior
。我想通過特定的where
條件獲取路徑。以下SQL工作正常,但我不想只獲得匹配條件的單個行,我還想獲取每個父記錄(垂直向上層次結構)。在Oracle中使用先前的垂直而不是水平的連接獲取路徑層級?
SELECT SUBSTR(SYS_CONNECT_BY_PATH(R.CALCULATION_PLAN_CODE, '.'),4) CODE_PATH,
SUBSTR(SYS_CONNECT_BY_PATH(R.CALCULATION_PLAN_NAME, ' > '),29) NAME_PATH,
R.CALCULATION_PLAN_CODE,
R.CALCULATION_PLAN_NAME
FROM PRM.MOVABLE_CALCULATION_PLAN R
WHERE R.RELATED_YEAR = :relatedYear
AND R.CALCULATION_PLAN_PARENT_OID != 0
AND REGEXP_LIKE (R.CALCULATION_PLAN_NAME,'ROL')
AND CONNECT_BY_ISLEAF = 1
START WITH R.OID =
(SELECT R1.OID
FROM PRM.MOVABLE_CALCULATION_PLAN R1
WHERE (R1.CALCULATION_PLAN_PARENT_OID IS NULL OR R1.CALCULATION_PLAN_PARENT_OID = 0) AND R1.RELATED_YEAR=:relatedYear) CONNECT_BY_PRIOR R.OID = R.CALCULATION_PLAN_PARENT_OID;
我不希望這樣的輸出: 我希望它是這樣的:
150 İLK MADDE VE MALZEMELER
150.1 İLK MADDE VE MALZEMELER > KIRTASİYE MALZEMELERİ GRUBU
150.1.1 İLK MADDE VE MALZEMELER > KIRTASİYE MALZEMELERİ GRUBU > ROL <-----
150 İLK MADDE VE MALZEMELER
150.1 İLK MADDE VE MALZEMELER > KIRTASİYE MALZEMELERİ GRUBU
150.1.1 İLK MADDE VE MALZEMELER > KIRTASİYE MALZEMELERİ GRUBU > YAZI ARAÇLARI
150.1.1.1 İLK MADDE VE MALZEMELER > KIRTASİYE MALZEMELERİ GRUBU > YAZI ARAÇLARI > ROLLER KALEM <-----
如何實現這一目標?
在此先感謝
刪除'AND REGEXP_LIKE(R.CALCULATION_PLAN_NAME,'ROL')'也許? – Timekiller
@Timekiller,如果我刪除它,如何通過名稱進行搜索。我想使用類似運算符按名稱搜索,然後我正在等待看到一個或多個像上面顯示的樹狀樹。 –
有沒有人評論它? –