ora-06502 pl sql numeric or value error character string buffer too small

I am getting above exception while excuting this function. i didn't no what is wrong in it.

CREATE OR REPLACE function MPP.FN_GET_DIVISION_BY_ID(p_division_id number)
 return varchar2
 is
 v_division varchar2(100);
 begin
 select NAME || ' ' || EXTENDED_NAME into v_division  from ORGANIZATIONAL_UNIT where DIVISION_ID = p_division_id;
 return v_division;
 end;
/

My Expected output is "Housing Finance and Operations Administrative Support".
kravindraAsked:
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.

MilleniumaireCommented:
It is likely that NAME||' '||EXTENDED_NAME is greater than 100 characters and therefore cant' be stored in the v_division variable.

Make v_division bigger i.e. varchar2(1000).

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
MilleniumaireCommented:
Just noticed your expected output, which clearly isn't greater than 100 characters.

First, I would confirm that this is your expected output.  If it is, does increasing your v_division to varchar2(200) make the function work, with the same expected output?  If so, then this may be a multi-byte language issue.
awking00Information Technology SpecialistCommented:
What are the datatypes for NAME and EXTENDED_NAME? If they are fixed lengths, you may want to trim them before concatenating and inserting into your variable.
Naveen KumarProduction Manager / Application Support ManagerCommented:
try this : basically it is the same what all above updates are being said.

just taking only 100 chars if the length is more than 100 to avoid the error. Check the string returned and if it is not complete, then increase the variable length or if it has spaces use trim to get rid of them.

CREATE OR REPLACE function MPP.FN_GET_DIVISION_BY_ID(p_division_id number)
 return varchar2
 is
 v_division varchar2(100);
 begin
 select substr(NAME || ' ' || EXTENDED_NAME,1,100) into v_division  from ORGANIZATIONAL_UNIT where DIVISION_ID = p_division_id;
 return v_division;
 end;
/

kravindraAuthor Commented:
help ful
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.