views:

46

answers:

2

I have the following small function that does not compile:

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;

The compiler gives me the following errors:

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

How can I correct this? Thanks!!

+2  A: 

It appears the table wg does not exist. When updated to the correct table name the compile works without errors. A message from the compiler of table does not exist would be most helpful.

twamn
@twamn: Checking google, I have to agree - poor error message.
OMG Ponies
I think the reasoning behind the error message is that if the object is not in the data dictionary, then it must be a locally defined object, hence "procedure, function, package, or type", which are all things that can be defined with a function.
Allan
When I compiled the code, I got a 'table does not exist' error. When I compiled it when I had a function called wg, I got the error described. Maybe there was a public synonym to another 'wg' somewhere.
Gary
A: 
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;
The chicken in the kitchen