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

When I execute a Oracle procedure I get this ORA-06502 error.
The string size that I am trying to output (on DBMS_OUTPUT.PUTLINE) is less than 2000 character. Is there any way to avoid this error?

I plan to create a script that will create a table with field names that are same as the date value strings of a certain day each week between the dates  "starteDate" and "endDate ".

I get error in the test process... when I run the procedure on SQL prompt:
SQL>  set serveroutput on;
SQL> set serveroutput on buffer 2560000;
SQL>  begin
  2   myProc ;
  3   end;
/

ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 3
CREATE OR REPLACE PROCEDURE myProc IS
  starteDate   Date;
  endDate      Date;
col_string   VARCHAR2(2000);
s_sql_insert VARCHAR2(2000);
BEGIN

-- Get the starteDate and endDate values via sql.
s_sql_insert := 'CREATE TABLE MyTab ( f1 VARCHAR2(256), f2 VARCHAR2(256), ';

  loopDate := starteDate;
  WHILE starteDate <= endDate LOOP
    col_string := col_string || to_char(loopDate) || 'VARCHAR2(256),';
    loopDate := loopDate + 7;
  END LOOP;

  s_sql_insert := s_sql_insert || col_string || ')';

  DBMS_OUTPUT.PUT_LINE('s_sql_insert : ' || s_sql_insert ); -- Getting ERROR


--  EXECUTE IMMEDIATE s_sql_insert;
 

END;

Open in new window

toookiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sdstuberCommented:
your loop never ends

I think you want to check your loopDate, not your StarteDate

loopDate := starteDate;
  WHILE loopDate<= endDate LOOP
    col_string := col_string || to_char(loopDate) || 'VARCHAR2(256),';
    loopDate := loopDate + 7;
  END LOOP;

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
toookiAuthor Commented:
Thanks a lot and that worked. I changed the while statement..
Many thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.