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

前端 未结 3 900
离开以前
离开以前 2020-12-30 18:49

I tried the following code different ways, like by taking out the while or the if, but when I put both together (if and while), I always get the error at the end...

相关标签:
3条回答
  • 2020-12-30 19:43

    CHAR is a fixed-length data type that uses as much space as possible. So a:= a||'one '; will require more space than is available. Your problem can be reduced to the following example:

    declare
      v_foo char(50);
    begin
      v_foo := 'A';
      dbms_output.put_line('length of v_foo(A) = ' || length(v_foo));
      -- next line will raise:
      -- ORA-06502: PL/SQL: numeric or value error: character string buffer too small
      v_foo := v_foo || 'B';
      dbms_output.put_line('length of v_foo(AB) = ' || length(v_foo));  
    end;
    /
    

    Never use char. For rationale check the following question (read also the links):

    • Oracle datatype: Should I use VARCHAR2 or CHAR
    0 讨论(0)
  • 2020-12-30 19:45

    This may also happen if you have a faulty or accidental equation in your csv file. i.e - One of the cells in your csv file starts with an equals sign (=) (An excel equation) which will, in turn throw an error. If you fix, or remove this equation by getting rid of the equals sign, it should solve the ORA-06502 error.

    0 讨论(0)
  • 2020-12-30 19:52

    PL/SQL: numeric or value error: character string buffer too small

    is due to the fact that you declare a string to be of a fixed length (say 20), and at some point in your code you assign it a value whose length exceeds what you declared.

    for example:

    myString VARCHAR2(20);
    myString :='abcdefghijklmnopqrstuvwxyz'; --length 26
    

    will fire such an error

    0 讨论(0)
提交回复
热议问题