Add a 999 to the front of a integer (sql code)

Hello, What I want to do is add a 999 to the front of a integer value in sql.  Basically, lets say I have a value of 1234.  I want to in sql code add a 999 to it so it would look like 9991234.  Right now my code is literally adding 999 to 1234 giving me a value of 2233 which is not what I am after.  

Any help would be greatly appreciated!
jwebster77Asked:
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.

Daniel WilsonCommented:
You need to convert to a string to do the concatenation, then convert back to an integer.

Looking up CAST or similar ofr Oracle now ...
Daniel WilsonCommented:
http://www.techonthenet.com/oracle/functions/cast.php


Select Cast('999' + Cast(MyIntegerField as varchar2(6)) as integer) as MyFinishedInteger
From MyTable

Open in new window

jwebster77Author Commented:
Here is what I have now but it is still doing it.  THoughts?

UPDATE PO.PO_LINES_ALL SET PO.PO_LINES_ALL.PO_HEADER_ID = Cast('999' + CAST(PO.PO_LINES_ALL.PO_HEADER_ID As char(10)) as integer), PO.PO_LINES_ALL.LINE_NUM = CAST('999' + Cast(PO.PO_LINES_ALL.LINE_NUM As char(10)) as Integer) WHERE PO_HEADER_ID = 34735 AND LINE_NUM = 13  
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Daniel WilsonCommented:
Looks like we're using the wrong operator for concatenation.  Sorry, my experience is in MS SQL Server and MySql.

Please try || instead of +
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/operators003.htm
UPDATE PO.PO_LINES_ALL SET PO.PO_LINES_ALL.PO_HEADER_ID = Cast('999' || CAST(PO.PO_LINES_ALL.PO_HEADER_ID As char(10)) as integer), PO.PO_LINES_ALL.LINE_NUM = CAST('999' || Cast(PO.PO_LINES_ALL.LINE_NUM As char(10)) as Integer) WHERE PO_HEADER_ID = 34735 AND LINE_NUM = 13

Open in new window

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
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Nay, you don't need a cast. Just use the string concatenation operator, which implicitely converts numbers to strings:
   select '999' || IntegerField from  Tbl
awking00Information Technology SpecialistCommented:
Obtaining a numeric value with an explicit conversion would be -
select to_number('999'||to_char(yourintegerfield))
Mark WillsTopic AdvisorCommented:
Might want to keep the trailing part of the number formatted correctly so you dont trip over differing numbers....


e.g. if you number was 1 you may prefer to end up with 99900001 rather than 9991

select '999'||to_char(yourno,'FM00000') from yourtable
Daniel WilsonCommented:
JWebster,

You have solutions from 4 of us now.

Did any of them work for you?
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.