关于游标使用时的声明变量的问题,请高手赐教!

dos521 2006-12-29 04:48:57
create or replace procedure modi_data
as
o_date date;

declare
l_name varchar2(100);
l_date date;
cursor new_cur is
select t2,t3 from t_testnew;

begin
open new_cur;
fetch new_cur
into l_name,l_date;
while new_cur%found loop
select t_test.t3 into o_date from t_test where t_test.t2 = l_name;
if o_date < l_date then
update t_test set t_test.t3 = o_date where t_test.t2 = l_name;
commit;
end if;
if o_date > l_date then
null;
else
insert into t_test
(select * from t_testnew where t_testnew.t3 = l_name);
commit;
end if;

end loop;
close new_cur;
end;


创建这个存储过程时,系统报
Compilation errors for PROCEDURE USERNAME.MODI_DATA

Error: PLS-00103: 出现符号 "DECLARE"在需要下列之一时:
begin function package
pragma procedure subtype type use <an identifier>
<a double-quoted delimited-identifier> form current cursor
符号 "begin" 被替换为 "DECLARE" 后继续。
Line: 5
Text: declare

Error: PLS-00103: 出现符号 "end-of-file"在需要下列之一时:
begin case declare
end exception exit for goto if loop mod null pragma raise
return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge
<a single-quoted SQL string> pipe
Line: 32

Error: Hint: Variable 'declare' is declared but never used in 'modi_data'
Line: 5
Text: declare


大家帮忙看看哪里错了,我是菜鸟,才学的oracle如有低级错误不要笑话呀,^_^
...全文
176 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tgm78 2006-12-29
  • 打赏
  • 举报
回复
Error: Hint: Variable 'declare' is declared but never used in 'modi_data'
Line: 5
Text: declare

错误信息已经提示的很清楚了。
Eric_1999 2006-12-29
  • 打赏
  • 举报
回复
匿名过程就要。
dos521 2006-12-29
  • 打赏
  • 举报
回复
哈哈,谢谢大家了,那什么时候才需要呀,我看一般都要用呀??
Eric_1999 2006-12-29
  • 打赏
  • 举报
回复
不要declare
Eric_1999 2006-12-29
  • 打赏
  • 举报
回复
create or replace procedure modi_data
as
o_date date;
l_name varchar2(100);
l_date date;
cursor new_cur is
select t2,t3 from t_testnew;

begin
open new_cur;
fetch new_cur
into l_name,l_date;
while new_cur%found loop
select t_test.t3 into o_date from t_test where t_test.t2 = l_name;
if o_date < l_date then
update t_test set t_test.t3 = o_date where t_test.t2 = l_name;
commit;
end if;
if o_date > l_date then
null;
else
insert into t_test
(select * from t_testnew where t_testnew.t3 = l_name);
commit;
end if;

end loop;
close new_cur;
end;

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧