Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Guys I have 1 question i have 1 column where i have numbers like 995551808080
only change is after 95551 and i want to Cut all unececary Numbers from there and i want to be there only 995551 << this number can you help me with some script?
Posted
Updated 17-Aug-15 2:11am
v2
Comments
ZurdoDev 17-Aug-15 8:20am    
Doesn't Oracle have a LEFT() function or something like that?

It's very easy!

SQL
SELECT SUBSTR('995551808080', 1, 6);
        -- returns: '995551'


Documentation: SUBSTR[^]
 
Share this answer
 
v2
Comments
Jörgen Andersson 19-Aug-15 9:47am    
Nope that doesn't work, your link is for MySQL, nowadays owned by Oracle.
For Oracles own implementation you need to use SUBSTR().
Maciej Los 19-Aug-15 15:17pm    
Thank you, Jorgen for your valuable comment. The answer has been updated.
In MSSql

Sol 1: - Select Left ('995551121212',6)
Output :- 995551

Use Substring Fuinction :-

Sol 2 :- Select Substring ('995551121212',1,6)
OutPut :- 995551
 
Share this answer
 
Now i Search and Found substr << function that cut numbers how you want
 
Share this answer
 
Comments
Jörgen Andersson 19-Aug-15 9:48am    
SUBSTR() is correct, I don't see why you got downvoted. Have a compensation.
Maciej Los 19-Aug-15 15:17pm    
Agree!
if your column type is varchar or nvarchar use subtring like
SELECT SUBSTR('995551808080', 1, 6);

if it is BIGINT or INT

firstly cast it to varchar like

SELECT CONVERT(varchar(10), field_name) FROM table_name

and than use SUBSTR
 
Share this answer
 
Comments
Jörgen Andersson 21-Aug-15 2:53am    
Not necessary, conversion is implicit.
Bigint is btw not a datatype in Oracle. You're mixing it up with SQLServer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900