1

I am running a simple insert into select and my code is

Insert into TEMP
select a.emp_name,
       Null as address,
       a.emp_id,
       .......
       from Temp1 a,Temp2 b where a.batch_id=b.batch_id

Now the column address is varchar2(30) even though I am inserting NULL . I got an overflow .

SQL Error: ORA-12899: value too large for column "TEMP"."ADDRESS" (actual: 35, maximum: 30)

Really puzzled how this can happen.Can anyone provide any tips? I am using Oracle 11g

2
  • Instead of NULL,can you try to use empty string '' Apr 14, 2015 at 19:47
  • 1
    I imagine you have the values in a different order to the columns in the table. This is one of the reasons you should specify the columns as part of the insert. To verify, can you add the table description to the question?
    – Alex Poole
    Apr 14, 2015 at 19:51

1 Answer 1

2

You are probably just putting the wrong values into the columns, since you haven't specified them in the insert clause. It's better to list the columns explicitly and not rely on the order they appear in the data dictionary:

insert into TEMP (emp_name, address, empi_id, ...)
select a.emp_name,
   null,
   a.emp_id,
   .......
from Temp1 a
join Temp2 b on a.batch_id=b.batch_id

I've also changed to explicit join syntax, though that isn't relevant to the question...

1
  • Thanks Alex, yeah my order got shuffled which result in data mismatch.Thanks for the catch Apr 14, 2015 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.