with emps(ID,
name,
parentid,
lvl) as
(select ID, name, parentid, 1 as lvl
from MT_CATEGORY
WHERE id = 350
and isvalid = 1
union all
select emp.ID, emp.name, emp.parentid, root.lvl + 1
from MT_CATEGORY emp, emps root
where emp.parentid = root.ID
and emp.isvalid = 1)
select * from emps