简体   繁体   中英

ORA-06502: PL/SQL: numeric or value error: character string buffer too small only three numbers

create or replace FUNCTION "FNC_CALCULATE_MOD11" (P_VALOR IN NUMBER) 
  return number is
      Result number;
begin
DECLARE
  -- LOCAL VARIABLES HERE
    V_PROCESSO VARCHAR2(30);
    V_PESO NUMBER := 2;
    V_SOMA NUMBER := 0;
    V_RESTO NUMBER := 0;
BEGIN

  V_PROCESSO := TO_CHAR(P_VALOR);
  WHILE LENGTH(V_PROCESSO) < 6  --Popular com zeros no inicio até 6
  LOOP
        V_PROCESSO := '0'||V_PROCESSO;
  END LOOP;

--accuses error on this line

FOR I IN REVERSE 1 .. LENGTH(V_PROCESSO)
  LOOP
      V_SOMA := TO_CHAR (V_SOMA) + TO_NUMBER(SUBSTR(V_PROCESSO,i,1))*V_PESO;
      IF V_PESO = 9 THEN  --repetir peso se for necessario
         V_PESO := 2;
      ELSE
         V_PESO := V_PESO + 1;
      END IF;
  END LOOP;

  V_RESTO := MOD(V_SOMA, 11);
  Result := 11 - V_RESTO;

  IF ((Result = 0) OR (Result = 1) OR (Result >= 10)) THEN
     Result := 1;
  END IF;   

END;

  return(Result);
end FNC_CALCULATE_MOD11;

尝试将V_PROCESSO更改为更大的大小,例如V_PROCESSO VARCHAR2(300);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM