首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

oracle里function里創建臨時表錯誤,看看那地方錯啦解决思路

2012-02-10 
oracle里function里創建臨時表錯誤,看看那地方錯啦SQL codecreate or replace function timecoverbegin(ou

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; 这个是查不出任何东西的,即使你的表中有数据。

热点排行