0

我试图在一个过程中运行这段代码。

DECLARE sharedpool FLOAT;
BEGIN
select bytes/1024/1024 into sharedpool from v$sgastat where pool='shared pool' and name like '%free memory';
insert into tempstats1(stat,cdate) values(sharedpool,sysdate);
commit;
END;

当像这样运行时,它会成功执行并更新表。我想将此块添加到一个过程中并安排一个作业来定期运行它。

CREATE OR REPLACE PROCEDURE temp_insert1 IS
DECLARE sharedpool FLOAT;
BEGIN
select bytes/1024/1024 into sharedpool from v$sgastat where pool='shared pool' and name like '%free memory';
insert into tempstats1(stat,cdate) values(sharedpool,sysdate);
commit;
END;

如果我运行它,它会显示一个警告,该过程是用编译错误创建的。为什么它不能正确编译?有人可以解释我哪里出错了吗?

4

1 回答 1

1

尝试DECLARE从您的存储过程中删除:

CREATE OR REPLACE PROCEDURE temp_insert1
IS
   sharedpool   FLOAT;
BEGIN
   SELECT bytes / 1024 / 1024
     INTO sharedpool
     FROM v$sgastat
    WHERE pool = 'shared pool' AND name LIKE '%free memory';

   INSERT INTO tempstats1 (stat, cdate)
        VALUES (sharedpool, SYSDATE);

   COMMIT;
END;

来自@DavidAldridge 评论:

您可以像这样删除变量声明:

CREATE OR REPLACE PROCEDURE temp_insert1
    IS      
    BEGIN

       INSERT INTO tempstats1 (stat, cdate)
       SELECT bytes / 1024 / 1024, SYSDATE
         FROM v$sgastat
        WHERE pool = 'shared pool' AND name LIKE '%free memory';

       COMMIT;
    END;
于 2013-03-15T12:41:44.520 回答