sSQL="create global temporary table t_tempAM as 要写成sSQL :='create global temporary table t_tempAM as ...而SQL中的', 要用''来表示.

解决方案 »

  1.   

    你的表名,字段名。定义的时候不要太长。
    单引号 '' ->   ; '''' -> ' ; '''  -> error ;
    双引号 "" ->   ; "'"  -> ' ; "''" -> ''    ; """ -> error
      

  2.   

    1、在oracle语句中,使用单引号标识字符串.
    2、还有一点值得提出,创建临语法不正确。
    3、返回记录集不这样。用动态游标返回吧。declare
    sSQL varchar2(200);
    type t_sor is ref cursor;
    v_sor t_sor;
    beginsSQL='create global temporary table t_tempAM ON COMMIT PRESERVE(DELETE) ROWS as 
    select decode(substr(batchno,1,1),''0'',''2000'',''1'',''2001'',''2'',''2002'',''3'',''2003'',
    ''4'',''2004'',''5'',''2005'',''6'',''1996'',''7'',''1997'',''8'',''1998'',''9'',''1999'') yeildmonth,
    componentsid,to_char(maintaindate,''yyyymm'') maintainmonth from t_components_analysis
     
    where comyielddate is null and maintaindate is not null 
    and substr(batchno,1,1) in (''1'',''2'',''3'',''4'',''5'',''6'',''7'',''8'',''9'',''0'')';execute immediate sSQL;
    open v_sor for select * from t_tempAM where rownum<=200;
    fetch v_sor into 变量1,变量2,变量3;
    loop
    exit when v_sor%notfound;
    dbms_out.put_line(变量1||' '||变量2||' '||变量3);
    fetch v_sor into 变量1,变量2,变量3;
    end loop;
    end;
    /
      

  3.   

    beckhambobo(beckham) 好耐心!佩服!佩服!必有所成!
    谢谢 Lastdrop(空杯) 一直对我的问题很关照。
    谢谢大家了,结贴!
      

  4.   

    还有问题:    open v_sor for select * from t_tempAM where rownum<=200;
    临时表名t_tempAM没声明,不认,该如何解决?SQL plus中具体如下:
    open v_cur for select * from t_tempAM;
                                 *
    ERROR 位于第 18 行:
    ORA-06550: 第 18 行, 第 30 列:
    PLS-00201: 必须说明标识符 'T_TEMPAM'
    ORA-06550: 第 18 行, 第 16 列:
    PL/SQL: SQL Statement ignored