0

我有以下存储过程

create or replace PROCEDURE WEB_AC
(
  v_iDocid IN NUMBER DEFAULT NULL ,
  v_valor IN VARCHAR2 DEFAULT NULL ,
  v_campo IN VARCHAR2 DEFAULT NULL ,
  v_error  OUT NUMBER
)
AS
v_campoid NUMBER(5,0);
v_tipodato VARCHAR2(50);
v_DOCTYPE NUMBER;
v_tabla VARCHAR2(50);
v_procedure VARCHAR2(70);
BEGIN
  v_error:= 0;
  IF v_valor IS NULL
    OR v_valor IS NULL
    OR LENGTH(TRIM(v_valor)) = 0 THEN
       BEGIN
           v_error:= 3;

       END;
  else   
   Begin
      bEGIN
        SELECT campoid,
            doctype,
          tipodato
        INTO v_campoid,
          v_DOCTYPE,
          v_tipodato
        FROM TiposDocumento t
            , DIGITALIZAMAIN d
            , CatCamposDocumento c
        where
            c.tabla=t.tabla and
         nombre=v_campo and
         doctype = TipoDocumentoID and
         docid = v_iDocid AND 
         Mostrar = 1;
        EXCEPTION
          WHEN OTHERS THEN
            v_campoid := 0;
      END;
    --select @campoid
       IF v_campoid != 0 THEN
         Begin
              EXECUTE IMMEDIATE 'BEGIN ABANCE3.WEB_UPDOC' || TRIM(TO_CHAR(v_DOCTYPE )) || 'C' || TRIM(TO_CHAR(v_campoid)) ||'(' ||
             TO_CHAR (v_iDocid)||' , '||CHR(39)||v_valor||CHR(39)||',:2);END;'  
                USING out v_error;

      END;
    END IF;
    end;
  end if;  
 END;  

 create or replace PROCEDURE WEB_UPDOC1C6(v_idreg NUMBER,v_valor VARCHAR2,v_temp OUT NUMBER) 
 AS
   v_sys_error NUMBER := 0;
    BEGIN
      BEGIN
       SELECT count(*)
         INTO v_sys_error
         FROM DOC1
         where DOCID = v_idreg;
         EXCEPTION WHEN OTHERS THEN v_sys_error:=0;
       END;


       IF v_sys_error > 0 THEN
         BEGIN
           BEGIN
             UPDATE DOC1
               SET DESCRIPCION = v_valor
               WHERE  DOCID = v_idreg;
              EXCEPTION WHEN OTHERS THEN v_sys_error:=0;
          END;
         IF v_sys_error = 0 THEN v_temp:=0 ;
         ELSE v_temp:=1 ;
         END IF;
       END;
     END IF;
   END;

我正在使用以下代码从应用程序中调用它们:

 Friend Function ActualizaCampos(ByVal iDocID As Long, ByVal valor As String, ByVal Campo As String, ByVal ProyectoID As Integer) As String
         Dim mstrCS as String = "Here goes the connection String to my server"
         Dim db As Database
         Dim dbCW As DbCommand
         Dim iValor As String = "0"

    Select Case Me.TipoBD
             Case GlobalDef.eTipoBD.Oracle
                 db = New OracleDatabase(mstrCS)
                 dbCW = db.GetStoredProcCommand(WEB_AC, iDocid, valor, Campo, 0)
                 db.ExecuteNonQuery(dbCW)
             Case GlobalDef.eTipoBD.SQLServer
                 db = New SqlDatabase(mstrCS)
                 dbCW = db.GetStoredProcCommand(WEB_AC, iDocid, valor, Campo)
                 iValor = db.ExecuteScalar(dbCW).ToString()
         End Select

         Return iValor
     End Function

在这个例子中,WEB_AC SP总是执行 spWEB_UPDOC1C6

我有两个问题。

第一个问题:在应用程序的某个时刻,我将valor参数(可视基本函数的)作为带有空格的字符串,类似于"some string with spaces"。发生这种情况时,存储过程不会更新表。如果我直接在数据库中执行 SP(使用 SQL Developer),一切正常。我知道这与缺少一些引号(')的字符串有关,但我还没有让它工作。对此有一些想法?

第二个问题:有时,在调试应用程序时,如果我中断执行,每次尝试再次执行时,我都会在数小时内开始收到ORA-24338 'statement handle not executed' 错误。我相信这与公开交易有关。但老实说,由于我是与 Oracle 合作的新手,我真的不知道问题可能是什么。

你能帮助我吗?

更新:我找到了 ORA-24338 的真正原因。这是另一个导致错误的SP。当我找到其他问题的解决方案时,我会将其全部发布在这里。

4

1 回答 1

2

I'd suggest that you replace your WHEN OTHERS clause with one that specifically names the erros that you are expecting, or you raise the error after handling it anyway. WHEN OTHERS is a bit contraversial as it is notorious for hiding the real problem.

于 2009-12-09T10:34:17.887 回答