Increment a letter by 1

1,059 views
Skip to first unread message

Anthony Smith

unread,
Jun 27, 2007, 5:01:32 PM6/27/07
to Oracle PL/SQL
Lets say I have some SQL that is pulling this one value
SUBSTR(corp_id_nbr,1,1)

How can I make my sql increment the value by 1 when it is a character?

For example if SUBSTR(corp_id_nbr,1,1) = D, I want to be able to
increment to get the value E.

adamin

unread,
Jun 27, 2007, 5:12:22 PM6/27/07
to Oracle PL/SQL
chr(ascii(SUBSTR(corp_id_nbr,1,1))+1)

Antony Raj

unread,
Jul 5, 2007, 5:11:21 AM7/5/07
to Oracle...@googlegroups.com
Anthony,
Do you want to increment any value in the arguments of SUBSTR() ?? or just increment the output value i,e if D then E

 
--
With Warm Regards
Antony Raj .V

"Knowledge is the only treasure that increases on sharing"

Patricio Rodriguez

unread,
Jul 5, 2007, 10:43:27 AM7/5/07
to Oracle...@googlegroups.com
did you try this way.
char => ascii => increment by 1 => char again.
Example
-------------
SELECT CHR(ASCII(SUBSTR('corporation', 1, 1)) + 1)
  FROM dual


Best wishes.

Rob Wolfe

unread,
Jul 5, 2007, 11:01:54 AM7/5/07
to Oracle PL/SQL

Or, since someone re-opened the thread and I am feeling completely
over the top today .. try this


SELECT TRANSLATE(UPPER(SUBSTR(corp_id_nbr,1,1)),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'BCDEFGHIJKLMNOPQRSTUVWXYZA')
FROM sometable;

IIRC this will even have the extra benefit of ignoring anything that
is not alpha and just plopping out the original value.

Like the rest of the folks here, I am assuming that you are just
trying to transform the output of your query and that you do
understand that there is an "update" statement if you actually want to
make a change to the values in the table.

Patricio Rodriguez

unread,
Jul 5, 2007, 11:42:33 AM7/5/07
to Oracle...@googlegroups.com
MUCH BETTER. THANKS
Reply all
Reply to author
Forward
0 new messages