plsql - Oracle - Number to varchar -


I have a table in which the type of column of columns

  to create the table tmp ( / * Other field * / some_field number)  

And in a PL SQL script, I want to convert that area to a varchar. However, I do not know its length, so I get an exception

Exception Message ORA-06502: PL / SQL: Numerical or Value Error: Character string buffer is too small

< / Blockquote>
  v_some_field varchar (21); /*...*/ v_some_field: = TO_CHAR (Some_field, '999999999999999999999');  

How should I declare v_some_field buffer? Establishing it in varchar (32767) seems very cruel, is there any alternative?

You do not have an error because the number is too large, but because of your to_char Results are 22 characters long (21x "9" + one letter for the symbol):

  SQL & gt; DECLARE 2 some_field NUMBER: = 123; 3 v_some_field VARCHAR (21); 4 BEGIN 5 v_some_field: = TO_CHAR (Some_field, '999999999999999999999'); 6 END; 7 / ORA-06502: PL / SQL: Numeric or Value Error: Character string buffer is too small ORA-061212: Line 6 SQL & gt; DECLARE 2 some_field NUMBER: = 123; 3 v_some_field VARCHAR (22); 4 BEGIN 5 v_some_field: = TO_CHAR (Some_field, '999999999999999999999'); 6 END; 7 / PL / SQL process successfully completed  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -