Home » SQL & PL/SQL » SQL & PL/SQL » How can I compare a string with 2 digits?
How can I compare a string with 2 digits? [message #37935] Thu, 07 March 2002 09:04 Go to next message
Jess
Messages: 3
Registered: March 2002
Junior Member
Hi,

Can anyone help me to figure out "How can I compare a string with a digits?"

Ex. I have a string = 'Lemieux_12'
I want to make sure that
the 2 last character is a digit.

What I did :

substr('Lemieux_12',9,2) = INTEGER

BUT THE SYSTEM REFUSED MY REQUESTED.
I have really no idea how to make this
comparaison. Can you give me a hand, please?

THANK YOU!

P.S.: May be you find my question is very STUPID,
but I am a beginner at programmation!
I am learning!
Thanks for your understanding.
Re: How can I compare a string with 2 digits? [message #37937 is a reply to message #37935] Thu, 07 March 2002 09:29 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
If in PL/SQL:

if replace(translate(substr(v_value, length(v_value) - 1, 2), '1234567890','0000000000'), '0', '') is null then
  -- the last 2 digits are numeric
else
  -- the last 2 digits are not numeric
end if;


In SQL:

-- show all records where the last 2 digits of column col_name are numeric

select *
  from t
 where replace(translate(substr(col_name, length(col_name) - 1, 2), '1234567890','0000000000'), '0', '') is null
Re: How can I compare a string with 2 digits? [message #37962 is a reply to message #37937] Fri, 08 March 2002 21:28 Go to previous message
malarneasan
Messages: 2
Registered: March 2002
Junior Member
after taking the value using substr
use to_number function and then compare it
Previous Topic: null
Next Topic: Update Statement Error
Goto Forum:
  


Current Time: Wed Apr 24 16:05:27 CDT 2024