我正在尝试在一个过程中运行这段代码。
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;
如果我运行它,它会显示一个警告,说明该程序是由编译错误创建的。为什么不能正确编译?有人可以解释我哪里出错吗?
答案 0 :(得分: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;