---
title: "sql%rowcount 为零？？"
author: "winzenghua"
date: "2009-06-05T10:24:00Z"
tags: []
slug: "sql-rowcount"
draft: false
lastmod: "2009-06-05T10:24:00Z"
id: 987880
url: "https://java4gis.iteye.com/blog/987880"
---

begin  
starttime:=sysdate;  
v\_maxtime := to\_date('9999-12-31 00:00:00','yyyy-mm-dd hh24:mi:ss');  
select max(f\_logintime) into v\_maxtime from t\_gather\_userloginlog;

if v\_maxtime != to\_date('9999-12-31 00:00:00','yyyy-mm-dd hh24:mi:ss') then

insert into t\_gather\_userloginlog (f\_userid,f\_username,f\_logintime,f\_userip,f\_loginflag,f\_logintype) --来源主网登陆的。  
select f\_uid,f\_username,f\_logintime,f\_ip,f\_flag,f\_type from [t\_webloginlog\_bak@link\_stdby](mailto:t_webloginlog_bak@link_stdby) w where w.f\_logintime &gt; v\_maxtime;

insert into t\_gather\_userloginlog (f\_userid,f\_username,f\_logintime,f\_userip) --来源其他地方登陆。  
select ui\_id,ui\_username,ui\_lasttime,ui\_lastip  
from [b\_expuserinfo@link\_stdby](mailto:b_expuserinfo@link_stdby) inner join [t\_webloginlog\_bak@link\_stdby](mailto:t_webloginlog_bak@link_stdby)  
on ui\_username = f\_username and ui\_lastip = f\_ip and f\_logintime=ui\_lasttime and f\_logintime &gt; v\_maxtime  
where f\_username is null and ui\_lasttime &gt; v\_maxtime;

end if;

rownumber := sql%rowcount;  
insert into t\_base\_sp\_runlog values('gather','p\_Gather\_Day\_i\_UserLoginLog02',sysdate,'成功','INSERT', rownumber,round((dbms\_utility.get\_time-l\_start)/100,2),starttime);  
commit;

跑了很多天日志记录该过程影响行数为0! 不可能没有用户登陆啊

经过一番查证后：

insert into t\_gather\_userloginlog (f\_userid,f\_username,f\_logintime,f\_userip,f\_loginflag,f\_logintype) --来源主网登陆的。  
select f\_uid,f\_username,f\_logintime,f\_ip,f\_flag,f\_type from [t\_webloginlog\_bak@link\_stdby](mailto:t_webloginlog_bak@link_stdby) w where w.f\_logintime &gt; v\_maxtime;  
rownumber := sql%rowcount;--这里有数据

insert into t\_gather\_userloginlog (f\_userid,f\_username,f\_logintime,f\_userip) --来源其他地方登陆。  
select ui\_id,ui\_username,ui\_lasttime,ui\_lastip  
from [b\_expuserinfo@link\_stdby](mailto:b_expuserinfo@link_stdby) inner join [t\_webloginlog\_bak@link\_stdby](mailto:t_webloginlog_bak@link_stdby)  
on ui\_username = f\_username and ui\_lastip = f\_ip and f\_logintime=ui\_lasttime and f\_logintime &gt; v\_maxtime  
where f\_username is null and ui\_lasttime &gt; v\_maxtime;  
rownumber := sql%rowcount; --在这里变量被清空了

end if;