如何修复此“忽略SQL语句”错误?

时间:2010-06-24 19:20:13

标签: sql oracle plsql ora-04044

我有以下不能编译的小函数:

function f_query_01  Return interval Day to second is 
  start_time timestamp(3);
  end_time timestamp(3);
  time_diff interval Day to second;  
  c_query_number number;

begin

  start_time := systimestamp; 
  select count(*) into c_query_number from wg;  <--This is the line that errors out
  end_time := systimestamp;
  time_diff := start_time - end_time;

  return time_diff;

end f_query_01;

编译器给出了以下错误:

Error(29,3): PL/SQL: SQL Statement ignored
Error(29,44): PL/SQL: ORA-04044: procedure, function, package, or type is not allowed here

导致此错误的原因是什么?如何解决?

2 个答案:

答案 0 :(得分:10)

表格wg似乎不存在。当更新到正确的表名时,编译工作没有错误。来自表的编译器的消息不存在将是最有帮助的。

答案 1 :(得分:1)

CREATE OR REPLACE FUNCTION f_query_01
   RETURN NUMBER
IS
BEGIN
   DECLARE
      c_query_number   NUMBER DEFAULT NULL;
      start_time       DATE DEFAULT NULL;
      end_time         DATE DEFAULT NULL;
      time_diff        NUMBER DEFAULT NULL;
   BEGIN
      SELECT CAST (SYSTIMESTAMP AS DATE) INTO start_time FROM DUAL;

      SELECT COUNT (*) INTO c_query_number FROM ws;

      SELECT CAST (SYSTIMESTAMP AS DATE) INTO end_time FROM DUAL;

      time_diff := start_time - end_time;

      RETURN time_diff;
   END;
END f_query_01;