郁闷上了、本人第一次使用存储过程:
百度了、也google了、代码是写来了、错误也跟着来了、现在贴出来希望各位给我看看:
--创建存储过程hzwstatusupdate--ecidnumber:为集团编号
create or replace PROCEDURE hzwstatusupdate(ecidnumber in number) is
--创建临时表结构
type v_table_tbmeetroom is table of tbmeetroom%ROWTYPE index by binary_integer;v_tb_mgr v_table_tbmeetroom; --记录临时表别名v_tb_lock v_table_tbmeetroom; --锁定临时表别名v_num number; --编号
meetId number; --会议室编号
begin
for varCode in (select huiyishi from Tbmeetmgr where
to_date(stoptime,'yyyy-MM-dd') = to_date(to_char(sysdate,'yyyy-MM-dd'),'yyyy-MM-dd')
and to_date(to_char(sysdate,'hh24:mi'),'hh24:mi') between to_date(starttime,'hh24:mi')
and to_date(endtime,'hh24:mi') and ecid = ecidnumber)
loop --遍历varCode,封装数据到临时表MyTab中
v_tb_mgr(v_num) := varCode; --v_num相当于游标值,起初为1,第二条记录为2,以此类推
v_num := v_num + 1;
End loop; --判断临时表中是否有数据
if v_tb_mgr.count > 0 then --相当于游标从初始位置起
v_num:=v_tb_mgr.first; --遍历临时表中数据
for varR in v_num..v_tb_mgr.count
loop
meetId:=v_tb_mgr(v_num).id;
dbms_output.put_line(meetId);
--update tbmeetroom set status = 1 where id = meetId ;
End loop;
end if;
for varCode in (select meetroomid from Tbmeetroomlock t where
to_date(to_char(sysdate,'yyyy-MM-dd hh24:mi'),'yyyy-MM-dd hh24:mi')
between to_date(lockstarttime,'yyyy-MM-dd hh24:mi')
and to_date(lockendtime,'yyyy-MM-dd hh24:mi') )
loop --遍历varCode,封装数据到临时表MyTab中
v_tb_lock(v_num) := varCode; --v_num相当于游标值,起初为1,第二条记录为2,以此类推
v_num := v_num + 1;
End loop; --判断临时表中是否有数据
if v_tb_lock.count > 0 then --相当于游标从初始位置起
v_num:=v_tb_lock.first; --遍历临时表中数据
for varR in v_num..v_tb_lock.count
loop
meetId:=v_tb_lock(v_num).huiyishi;
dbms_output.put_line(meetId);
--update tbmeetroom set status = 2 where id = meetId ;
End loop;
end if;
end;--结束我的神仙、执行的时候没有弹出错误提示、只是在Procedures中我存储过程的图标上有一个小红X、他们这样就是错误、
点击Parameters的时候弹出一个错误提示:我存储过程名称 is invalid。
希望给为给看看。
百度了、也google了、代码是写来了、错误也跟着来了、现在贴出来希望各位给我看看:
--创建存储过程hzwstatusupdate--ecidnumber:为集团编号
create or replace PROCEDURE hzwstatusupdate(ecidnumber in number) is
--创建临时表结构
type v_table_tbmeetroom is table of tbmeetroom%ROWTYPE index by binary_integer;v_tb_mgr v_table_tbmeetroom; --记录临时表别名v_tb_lock v_table_tbmeetroom; --锁定临时表别名v_num number; --编号
meetId number; --会议室编号
begin
for varCode in (select huiyishi from Tbmeetmgr where
to_date(stoptime,'yyyy-MM-dd') = to_date(to_char(sysdate,'yyyy-MM-dd'),'yyyy-MM-dd')
and to_date(to_char(sysdate,'hh24:mi'),'hh24:mi') between to_date(starttime,'hh24:mi')
and to_date(endtime,'hh24:mi') and ecid = ecidnumber)
loop --遍历varCode,封装数据到临时表MyTab中
v_tb_mgr(v_num) := varCode; --v_num相当于游标值,起初为1,第二条记录为2,以此类推
v_num := v_num + 1;
End loop; --判断临时表中是否有数据
if v_tb_mgr.count > 0 then --相当于游标从初始位置起
v_num:=v_tb_mgr.first; --遍历临时表中数据
for varR in v_num..v_tb_mgr.count
loop
meetId:=v_tb_mgr(v_num).id;
dbms_output.put_line(meetId);
--update tbmeetroom set status = 1 where id = meetId ;
End loop;
end if;
for varCode in (select meetroomid from Tbmeetroomlock t where
to_date(to_char(sysdate,'yyyy-MM-dd hh24:mi'),'yyyy-MM-dd hh24:mi')
between to_date(lockstarttime,'yyyy-MM-dd hh24:mi')
and to_date(lockendtime,'yyyy-MM-dd hh24:mi') )
loop --遍历varCode,封装数据到临时表MyTab中
v_tb_lock(v_num) := varCode; --v_num相当于游标值,起初为1,第二条记录为2,以此类推
v_num := v_num + 1;
End loop; --判断临时表中是否有数据
if v_tb_lock.count > 0 then --相当于游标从初始位置起
v_num:=v_tb_lock.first; --遍历临时表中数据
for varR in v_num..v_tb_lock.count
loop
meetId:=v_tb_lock(v_num).huiyishi;
dbms_output.put_line(meetId);
--update tbmeetroom set status = 2 where id = meetId ;
End loop;
end if;
end;--结束我的神仙、执行的时候没有弹出错误提示、只是在Procedures中我存储过程的图标上有一个小红X、他们这样就是错误、
点击Parameters的时候弹出一个错误提示:我存储过程名称 is invalid。
希望给为给看看。
PLSQL!!!我不会调试~~~现在正在一条一条的删除、执行、在删除在执行!
第一个:在调取数据到v_tb_mgr(v_num) := varCode; 临时表中时,v_num没有初始化为1
第二个:你查询的数据只有huiyishi这一列(select huiyishi from Tbmeetmgr...),那你后面怎么能取得id列呢(meetId:=v_tb_mgr(v_num).id;)?,应该在查询时,把id列也查询出来才行。
我在--创建临时表结构
type v_table_tbmeetroom is table of tbmeetroom%ROWTYPE index by binary_integer;
的时候用的是tbmeetroom的表结构!这里面的ID(一)跟 tbmeetmgr中的huiyishi(多)有关联!然而查询的时候是查询另一张表tbmeetmgr。 这种情况怎么搞、我没弄过!很急、今天要交差啊、我程序已经实现了的功能、但是老大建议我用Oralce存储过程来实现!
同样,在你第二次获取数据到v_tb_lock临时表中时(select meetroomid from Tbmeetroomlock t...),仔细检查并修改就应该没什么问题。
其中:meetId:=v_tb_lock(v_num).huiyishi;
需要换成meetId:=v_tb_lock(v_num).id;
不知道像我上面那样定义过后、在for循环过后我得到的是我定义的表结构还是得到查询的表的结构!
但是问题和刚刚没什么两样、没有提示错误信息、没有编译错误。
点击Parameters的时候弹出一个错误提示:hzwstatusupdate(我存储过程名称) is invalid。
--创建存储过程hzwstatusupdate--ecidnumber:为集团编号
create PROCEDURE hzwstatusupdate(ecidnumber in number) is
--创建临时表结构
type v_table_tbmeetroom is table of tbmeetroom%ROWTYPE index by binary_integer;v_tb_mgr v_table_tbmeetroom; --记录临时表别名v_tb_lock v_table_tbmeetroom; --锁定临时表别名v_num number; --编号
meetId number; --会议室编号begin ;
v_num = 1 ; --初始化
for varCode in (select id,huiyishi from Tbmeetmgr where
to_date(stoptime,'yyyy-MM-dd') = to_date(to_char(sysdate,'yyyy-MM-dd'),'yyyy-MM-dd')
and to_date(to_char(sysdate,'hh24:mi'),'hh24:mi') between to_date(starttime,'hh24:mi')
and to_date(endtime,'hh24:mi') and ecid = ecidnumber)
loop --遍历varCode,封装数据到临时表MyTab中
v_tb_mgr(v_num) := varCode; --v_num相当于游标值,起初为1,第二条记录为2,以此类推
v_num := v_num + 1;
End loop; --判断临时表中是否有数据
if v_tb_mgr.count > 0 then --相当于游标从初始位置起
v_num:=v_tb_mgr.first; --遍历临时表中数据
for varR in v_num..v_tb_mgr.count -- 其中 .. 是循环的范围从v_num到v_tb_mgr.count
loop
meetId:=v_tb_mgr(v_num).huiyishi;
dbms_output.put_line(meetId);
--update tbmeetroom set status = 1 where id = meetId ;
--commit;
End loop;
end if;
v_num = 1 ; --初始化
for varCode in (select id,meetroomid from Tbmeetroomlock t where
to_date(to_char(sysdate,'yyyy-MM-dd hh24:mi'),'yyyy-MM-dd hh24:mi')
between to_date(lockstarttime,'yyyy-MM-dd hh24:mi')
and to_date(lockendtime,'yyyy-MM-dd hh24:mi') )
loop --遍历varCode,封装数据到临时表MyTab中
v_tb_lock(v_num) := varCode; --v_num相当于游标值,起初为1,第二条记录为2,以此类推
v_num := v_num + 1;
End loop; --判断临时表中是否有数据
if v_tb_lock.count > 0 then --相当于游标从初始位置起
v_num:=v_tb_lock.first; --遍历临时表中数据
for varR in v_num..v_tb_lock.count
loop
meetId:=v_tb_lock(v_num).meetroomid;
dbms_output.put_line(meetId);
--update tbmeetroom set status = 2 where id = meetId ;
--commit;
End loop;
end if;
end;--结束
呵呵世界很庞大、距离很嚣张、passort是我同事、我们既然都不知道、汗死了!!!
问题解决了:create or replace PROCEDURE hzwstatusupdate(ecidnumber in number) is
v_num number; --编号
meetId number; --会议室编号
begin
for varCode in (select huiyishi from Tbmeetmgr where
to_date(stoptime,'yyyy-MM-dd') = to_date(to_char(sysdate,'yyyy-MM-dd'),'yyyy-MM-dd')
and to_date(to_char(sysdate,'hh24:mi'),'hh24:mi') between to_date(starttime,'hh24:mi')
and to_date(endtime,'hh24:mi') and ecid = ecidnumber)
loop
meetId:=varCode.Huiyishi;
update tbmeetroom set status = 1 where id = meetId ;
end loop;
for varCode in (select meetroomid from Tbmeetroomlock t where
to_date(to_char(sysdate,'yyyy-MM-dd hh24:mi'),'yyyy-MM-dd hh24:mi')
between to_date(lockstarttime,'yyyy-MM-dd hh24:mi')
and to_date(lockendtime,'yyyy-MM-dd hh24:mi'))
loop
meetId:=varCode.Meetroomid;
update tbmeetroom set status = 2 where id = meetId;
end loop;
end;