CTE用起来很方便,但是,发现WITH后必须跟着select,想把WITH的结果应用到存储过程则失败,比如:
正确用法:
with cte as select * from table1 union all select table1.* from table1, cte where table1.parentid=cte.id select * from cte;
换成cursor失败:
with cte as select * from table1 union all select table1.* from table1, cte where table1.parentid=cte.id declare mycursor cursor for select * from cte;
请问有什么办法达成这个目的?
谢谢!
你可以考虑把CTE结果Insert到一个临时表里面啊。
另外,CURSOR是你写错顺序了。