--清理失效表单表格脚本
-- SELECT * FROM PORTAL_VI vi WHERE vi.TYPENAME NOT IN (SELECT p.NAME  FROM PLBTMTYPE p) AND vi.TYPENAME NOT IN (SELECT p2.NAME  FROM PLLINKTYPE p2);
DELETE FROM PORTAL_VI vi WHERE vi.TYPENAME NOT IN (SELECT p.NAME  FROM PLBTMTYPE p) AND vi.TYPENAME NOT IN (SELECT p2.NAME  FROM PLLINKTYPE p2);

--清理失效的UI定义的SQL脚本
--SELECT * FROM PLPAGELAYOUTDEFINATION t WHERE t.PLRELATEDTYPE NOT IN (SELECT p.NAME FROM PLBTMTYPE p) ;
DELETE PLPAGELAYOUTDEFINATION t WHERE t.PLRELATEDTYPE NOT IN (SELECT p.NAME FROM PLBTMTYPE p) ;

--SELECT * FROM PLTABPAGE t WHERE t.PLPAGEDEFINATIONOID NOT IN (SELECT p.PLOID FROM PLPAGELAYOUTDEFINATION p);
DELETE PLTABPAGE t WHERE t.PLPAGEDEFINATIONOID NOT IN (SELECT p.PLOID FROM PLPAGELAYOUTDEFINATION p);

--SELECT * FROM PLPAGEDEFINATION t WHERE t.PLPAGECONTEXTOID NOT IN (SELECT p.PLOID FROM PLTABPAGE p );
DELETE PLPAGEDEFINATION t WHERE t.PLPAGECONTEXTOID NOT IN (SELECT p.PLOID FROM PLTABPAGE p );

--SELECT * FROM PLTABBUTTON t WHERE t.PLTABLEOID NOT IN (SELECT p.PLOID FROM PLPAGEDEFINATION p );
DELETE PLTABBUTTON t WHERE t.PLTABLEOID NOT IN (SELECT p.PLOID FROM PLPAGEDEFINATION p );

--SELECT * FROM PLCOMMANDPARAMETER t WHERE t.PLCOMMANDOID NOT IN (SELECT p.PLOID FROM PLTABBUTTON p);
DELETE PLCOMMANDPARAMETER t WHERE t.PLCOMMANDOID NOT IN (SELECT p.PLOID FROM PLTABBUTTON p);

-- 清理无效的查询模板
--SELECT * FROM PLATFORM_QT qt WHERE qt.BTMNAME  NOT IN (SELECT p.NAME  FROM PLBTMTYPE p) AND qt.BTMNAME NOT IN (SELECT p2.NAME  FROM PLLINKTYPE p2)
DELETE FROM PLATFORM_QT qt WHERE qt.BTMNAME  NOT IN (SELECT p.NAME  FROM PLBTMTYPE p) AND qt.BTMNAME NOT IN (SELECT p2.NAME  FROM PLLINKTYPE p2)

-- 清理无效的查询模板定义
--SELECT * FROM PLATFORM_QTD qd WHERE (qd.BTMNAME IS NOT NULL AND qd.BTMNAME  NOT IN (SELECT p.NAME  FROM PLBTMTYPE p)) or (qd.LINKTYPENAME IS NOT NULL AND qd.LINKTYPENAME  NOT IN (SELECT p2.NAME  FROM PLLINKTYPE p2))
DELETE FROM PLATFORM_QTD qd WHERE (qd.BTMNAME IS NOT NULL AND qd.BTMNAME  NOT IN (SELECT p.NAME  FROM PLBTMTYPE p)) or (qd.LINKTYPENAME IS NOT NULL AND qd.LINKTYPENAME  NOT IN (SELECT p2.NAME  FROM PLLINKTYPE p2))

-- 清理失效权限信息
--SELECT * FROM PLROLERIGHT r WHERE r.PLROLEOID NOT IN (SELECT pluid FROM PLROLE) or (r.PLFUNCOID NOT IN (SELECT p.PLOID FROM PLFUNCTION p) AND r.PLFUNCOID NOT IN (SELECT p2.PLOID FROM PLPAGEDEFINATION p2) AND r.PLFUNCOID NOT IN (SELECT NAME FROM PLBTMTYPE))
DELETE PLROLERIGHT r WHERE r.PLROLEOID NOT IN (SELECT pluid FROM PLROLE) or (r.PLFUNCOID NOT IN (SELECT PLOID FROM PLFUNCTION) AND r.PLFUNCOID NOT IN (SELECT PLOID FROM PLPAGEDEFINATION) AND r.PLFUNCOID NOT IN (SELECT NAME FROM PLBTMTYPE))

