Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query in Oracle

Status
Not open for further replies.

urge262

MIS
Sep 27, 2004
13
US
Hello,

I am trying to write a query in Oracle.

Here is a sample of the data for the CUST_ID field.
-----CUST_ID---------------------------------
CITFRAVIR01
DHL01
ARINC57
PFIZER11
CARAIRSAN01
---------------------------------------------

I need to write a query that strips off the last 2 digits. So instead of "CARAIRSAN01" I want to return "CARAIRSAN".



The CUST_ID field varies in length and varies in the last 2 digits.

I was trying to play around with the SUBSTR, INSTR, and LENGTH functions together but i couldn't figure it out. So if anyone knows of a different fucntion or a way to use the above functions I would really appreciate it.
 
This doesn't work for you?:

Code:
select substr(Cust_ID, 1, length(Cust_ID) - 2) FROM tblName

Leslie
 
Leslie,

Thank you! I was close! So the "1" means start at the first position right?

Then find the length subtract 2 characters right to left because of the "-" negative 2 and return the string.

thanks again!
 
yes, the 1 means start at the first position and then you end at the length of the string - 2 so you remove the last two characters!!

Glad you got it!

leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top