SQL语句改成ORACLE语句
with tbl as
(
select rep_id from dmis_rep_doc where rep_id=@rep_id
union all
select a.rep_id from dmis_rep_doc a,tbl b where a.rep_parent_id=b.rep_id
)
update dmis_rep_doc set rep_state=@rep_state
where rep_id in (select * from tbl)
如何该成ORACLE 语句
[解决办法]
--SQL SERVER 2005的递归写法
WITH tbl AS
( SELECT rep_id FROM dmis_rep_doc WHERE rep_id=@rep_id
UNION ALL
SELECT a.rep_id FROM dmis_rep_doc a,tbl b WHERE a.rep_parent_id=b.rep_id
)
UPDATE dmis_rep_doc
SET rep_state =@rep_state
WHERE rep_id IN
(SELECT * FROM tbl
)
--ORACLE 的递归写法
DECLARE
var_rep_id INT := 10; --具体类型不知道,假定为INT
var_rep_state INT := 1;
BEGIN
UPDATE
(SELECT *
FROM dmis_rep_doc
START WITH rep_id = var_rep_id
CONNECT BY prior rep_parent_id = rep_id
) a
SET a.rep_state = var_rep_state;
END;