我的a.sql文件如下:
DECLARE 
V_time VARCHAR2(20);
V_zxid VARCHAR2(200); 
V_rwdbh VARCHAR2(200); 
V_zymc VARCHAR2(200);
V_zgh varchar2(20);
v_wwcrs number(20);
CURSOR c_Tool IS 
Select rwid,zxid,zymc,zgh,rwdbh from B_GR_RWJDB where wcpsrq=V_time or wchqrq= V_time or wcjyrq=V_time or wcjzsrq=V_time or wcsrxdrq=V_time or wcftrq=V_time;
rowCurTool c_Tool%rowtype; 
BEGIN 
V_time := to_char(sysdate,'YYYY.MM.DD'); 
OPEN c_Tool; 
FETCH c_Tool into rowCurTool;  
while c_Tool%found loop 
V_zxid:=rowCurTool.zxid;
V_zymc:=rowCurTool.zymc;
V_rwdbh:=rowCurTool.rwdbh;
select count(*) into v_wwcrs from  B_GR_RWJDB  where WCPSRQ is null and rwdbh=v_rwdbh and zxid=V_zxid and zymc= V_zymc;
if v_wwcrs=0 then
update B_zy_RWJDB set  WCPSRQ = V_time  where rwdbh=v_rwdbh and zxid=V_zxid and zymc= V_zymc;
commit;
FETCH c_Tool into rowCurTool;  
end loop;  
Close c_Tool;
end;
exit;
其中这段语句在plsql 里面测试执行通过了,
我在建立一个批处理文件a.bat,
批处理文件内容如下 sqlplus liumis/liumis@ora92 @a.sql >a.log
结果批处理文件一直在执行,不会停止,看看log 文件如下:
连接到: 
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production 76  就这样一直在这里停顿。
而我接下来将sql文件更改为:update B_zy_RWJDB set  WCPSRQ =tochar(sysdate,'yyyy.mm.dd')where rwdbh=33 and zxid=57 and zymc='xinxi';
commit;
exit;
结果log 文件显示提交了一行,成功;
我就试图将sql文件改成过程,想利用批处理文件来执行这个过程
create procedure oro_a 
As
DECLARE 
V_time VARCHAR2(20);
V_zxid VARCHAR2(200); 
V_rwdbh VARCHAR2(200); 
V_zymc VARCHAR2(200);
V_zgh varchar2(20);
v_wwcrs number(20);
CURSOR c_Tool IS 
Select rwid,zxid,zymc,zgh,rwdbh from B_GR_RWJDB where wcpsrq=V_time or wchqrq= V_time or wcjyrq=V_time or wcjzsrq=V_time or wcsrxdrq=V_time or wcftrq=V_time;
rowCurTool c_Tool%rowtype; 
BEGIN 
V_time := to_char(sysdate,'YYYY.MM.DD'); 
OPEN c_Tool; 
FETCH c_Tool into rowCurTool;  
while c_Tool%found loop 
V_zxid:=rowCurTool.zxid;
V_zymc:=rowCurTool.zymc;
V_rwdbh:=rowCurTool.rwdbh;
select count(*) into v_wwcrs from  B_GR_RWJDB  where WCPSRQ is null and rwdbh=v_rwdbh and zxid=V_zxid and zymc= V_zymc;
if v_wwcrs=0 then
update B_zy_RWJDB set  WCPSRQ = V_time  where rwdbh=v_rwdbh and zxid=V_zxid and zymc= V_zymc;
commit;
FETCH c_Tool into rowCurTool;  
end loop;  
Close c_Tool;
end;
结果说编译错误,明明语句都是编译通过的啊。为什么放在过程里面就错了呢?请高手帮帮忙!

解决方案 »

  1.   

    create or replace procedure oro_a 
    As
    DECLARE  --这个不要
    V_time VARCHAR2(20);
    V_zxid VARCHAR2(200); 
    V_rwdbh VARCHAR2(200); 
    V_zymc VARCHAR2(200);
    V_zgh varchar2(20);
    v_wwcrs number(20);
    CURSOR c_Tool IS 
    Select rwid,zxid,zymc,zgh,rwdbh from B_GR_RWJDB
    where wcpsrq=V_time or wchqrq= V_time
     or wcjyrq=V_time or wcjzsrq=V_time 
     or wcsrxdrq=V_time or wcftrq=V_time;
    rowCurTool c_Tool%rowtype; 
    BEGIN 
    V_time := to_char(sysdate,'YYYY.MM.DD'); 
    OPEN c_Tool; 
    while c_Tool%found loop 
    FETCH c_Tool into rowCurTool; --这个是在循环里
    exit when c_Tool%notfound     -- 要有退出语句
    V_zxid:=rowCurTool.zxid;V_zymc:=rowCurTool.zymc;
    V_rwdbh:=rowCurTool.rwdbh;
    select count(*) into v_wwcrs from B_GR_RWJDB 
    where WCPSRQ is null and rwdbh=v_rwdbh
     and zxid=V_zxid and zymc= V_zymc;
    if v_wwcrs=0 then
    update B_zy_RWJDB set WCPSRQ = V_time where rwdbh=v_rwdbh and zxid=V_zxid and zymc= V_zymc;
    commit;
    FETCH c_Tool into rowCurTool;
    end if; --这里需要if结束符
    end loop; 
    Close c_Tool;
    end;
      

  2.   

    你最好把EXCEPTION 加上 万一有问题 你不加的话 就卡死在那了 
      

  3.   

    感谢Phoenix_99,tangren,oodick的回复,我按照你们的意见将过程进行改,提示编译成功了。
    我建立的过程文件名称为pro_liu
    在sqlplus里面编译成功;提示我过程已经建立;但是我在e:\建立的update.sql;内容如下:
    exec pro_liu;
    exit;同时在e:\建立批处理文件liumis.bat内容如下:
    sqlplus liumis/liumis@ora92 @update.sql >a.log
    建立windows下的任务计划,执行这个批处理文件。结果如下
    连接到: 
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - ProductionBEGIN pro_liu; END;      *
    ERROR 位于第 1 行:
    ORA-06550: 第 1 行, 第 7 列:
    PLS-00201: 必须说明标识符 'PRO_LIU'
    ORA-06550: 第 1 行, 第 7 列:
    PL/SQL: Statement ignored
    从Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - Production中断开
    这次问题出在哪里呢?明明过程已经建立成功了。