星空|SQL|元数据|业务对象查询相关SQL原创
9人赞赏了该文章
161次浏览
编辑于2024年05月23日 15:54:14
查询某业务对象的子孙对象
-- 向下递归查询业务对象
WITH CTE_OBJECT_DOWN
AS
(
SELECT 1 AS LEV,OL.FNAME,OE.FSUPPLIERNAME 开发商标识,OE.* FROM T_META_OBJECTTYPE OE
LEFT JOIN T_META_OBJECTTYPE_L OL ON OE.FID = OL.FID AND OL.FLOCALEID = 2052
WHERE OE.FID = 'PUR_MRB'
UNION ALL
SELECT CT.LEV + 1 AS LEV,OL.FNAME,OE.FSUPPLIERNAME 开发商标识,OE.* FROM T_META_OBJECTTYPE OE
JOIN T_META_OBJECTTYPE_L OL ON OE.FID = OL.FID AND OL.FLOCALEID = 2052
JOIN CTE_OBJECT_DOWN CT ON CT.FID = OE.FBASEOBJECTID
)
SELECT * FROM CTE_OBJECT_DOWN
;
应用场景
看到某标准单据下面没扩展,想要增加一个二开扩展,这时需要先用FORMID查一下子孙对象,确认下是不是真的不存在扩展,否则可能会造成同级扩展。
如果SQL查到有扩展,但是协同看不到,需要协同引入一下。
如果SQL查到有扩展,但是协同看不到,需要协同引入一下。
查询某业务对象的父级对象
-- 向上递归查询业务对象
WITH CTE_OBJECT_UP
AS
(
SELECT 0 AS LEV,OL.FNAME,OE.FSUPPLIERNAME 开发商标识,OE.* FROM T_META_OBJECTTYPE OE
LEFT JOIN T_META_OBJECTTYPE_L OL ON OE.FID = OL.FID AND OL.FLOCALEID = 2052
WHERE OE.FID = 'RHTW_PLM_WF_BOMBill'
UNION ALL
SELECT CT.LEV - 1 AS LEV,OL.FNAME,OE.FSUPPLIERNAME 开发商标识,OE.* FROM T_META_OBJECTTYPE OE
JOIN T_META_OBJECTTYPE_L OL ON OE.FID = OL.FID AND OL.FLOCALEID = 2052
JOIN CTE_OBJECT_UP CT ON CT.FBASEOBJECTID = OE.FID
)
SELECT * FROM CTE_OBJECT_UP;
-- 根据名称查询业务对象
SELECT OL.FNAME, OT.*
FROM T_META_OBJECTTYPE OT
LEFT JOIN T_META_OBJECTTYPE_L OL ON OT.FID = OL.FID AND OL.FLOCALEID = 2052
--WHERE OL.FNAME LIKE '%采购订单%'
WHERE OT.FID = 'QDPM_HTXX'
推荐阅读