日期:2014-05-16  浏览次数:20842 次

oracle的存储过程中为何无法使用cte
以前在sqlserver 2008中,可以使用CTE进行开发,避免了定义很多临时表,代码结构也比较清晰,现在转到了oracle上面开发,发现CTE只允许在查询中使用,无法在存储过程中使用,这是为何,查了半天这方面的资料,没有一个确切的答案,上来指教大家
Oracle 存储 SQL?Server Structure CTE

------解决方案--------------------
引用:
能否给个测试例子,我已经在存储过程中尝试过了,搞了很久都不行,最后只好使用临时表进行处理
create table t_emp as select * from scott.emp where 1=2;
/
create or replace procedure cte is
begin

  insert into t_emp
    with emp_1 as
     (select * from scott.emp)
    select * from emp_1;

  commit;

end;
/

------解决方案--------------------
scott是oracle的一个sample用户,其中的对象,都是用来测试和学习用的,mssql里,似乎也有sample库的。
我也是只用过insert,delete,update你可以自己测试下,merge语句我试过,似乎不支持的,当时的版本是10g.