日期:2014-05-17  浏览次数:20746 次

oracle里function里創建臨時表錯誤,看看那地方錯啦
SQL code


create or replace function timecoverbegin(outbegintime   IN DATE,
                                          outendtime     IN DATE,
                                          inbegintime    IN DATE,
                                          inendtime      IN DATE)
   RETURN date
   as
   tempTbl varchar2(300);
   result date;
   begin
    tempTbl:=' create global temporary table tempTbl         
           (
             tempdate date
           ) on commit  delete  rows ';
   EXECUTE   IMMEDIATE tempTbl;
    insert into tempTbl(tempdate) values(outbegintime);
    insert into tempTbl(tempdate) values(outendtime);
    insert into tempTbl(tempdate) values(inbegintime);
    insert into tempTbl(tempdate) values(inendtime);
    select tempdate into result  from tempTbl order by tempdate;
    return result;
   end timecoverbegin
   ;
/




------解决方案--------------------
说两点: 
1、oracle中的临时表,指数据的临时,并不是表的临时,一次建完了,以后都能用,没必要每次都在函数中建。
你这么写函数,第二次调用肯定会出错,告诉你表已经存在的错误。

2、select * .... where rownum=2; 这个是查不出任何东西的,即使你的表中有数据。