一个单独可执行的SQL语句没有错误:如下计算月变化率的语句在存储过程中就不能使用,first_value或sum() over(...) 等分析函数,有什么原因,有谁知道?(如果去掉 into l_chg_scale_buffer ,放到sql*plus就可以使用) 
 select f_month,
       (end_value-begin_value)/begin_value as chg_scale
into l_chg_scale_buffer       
from
(
    select distinct
              to_char(fdate,'yyyymm') as f_month,                
              first_value(fclose)      over (partition by to_char(fdate,'yyyymm') order by fdate asc rows between unbounded preceding and unbounded following)  as begin_value,              
              last_value(fclose)       over (partition by to_char(fdate,'yyyymm') order by fdate asc rows between unbounded preceding and unbounded following)  as end_value                 
    from R_ZX_HYZSB 
    where fhydm='998000'
)
where f_month='200405'

解决方案 »

  1.   

    我的oracle不支持分析函数,没有办法测试.帮你顶下
      

  2.   

    应该可以,oracle 9.0.2 的<<PL/SQL USER GUIDE AND REFERENCE>>原话如下:Although the SQL aggregate functions (such as AVG and COUNT) and the SQL
    analytic functions (such as CORR and LAG) are not built into PL/SQL, you can use
    them in SQL statements (but not in procedural statements).
      

  3.   

    but not in procedural statements  就是不能用分析函数了^_^
      

  4.   

    这句话好像应该这么理解,虽然不可以在PL/SQL中直接使用,但是可以在嵌套在PL/SQL中的sql语句使用
      

  5.   

    你好像select了2个字段 确要放到一个变量里面
      

  6.   

    可以使用execute immediate来执行
      

  7.   

    but not in procedural statements
      

  8.   

    你用的oracle什么版本?你试试用execute immediate.动态sql