Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> pl/sql VARCHAR2
In the code below I simply want to subtract 101 from aidy to get
'0203'. The present code obviously converts aidy to a number then
subtracts 101 yielding the resulting number 203 however I want the
result to be '0203'. I realize that I simply could convert the
resulting number back to a VARCHAR2 and pad that with a '0' zero
getting '0203'. I would prefer not to have to convert the aidy to a
VARCHAR2 at all and simply subtract '0101' from '0304' and get '0203'
never converting any data types. Is this possible in PL/SQL? Any
suggestions on how to do this?
set serveroutput on;
DECLARE
temp_aidy VARCHAR2(4) :='0';
aidy VARCHAR2(4) := '0304';
i NUMBER := 0;
j NUMBER := 0;
BEGIN
i := to_number(aidy);
IF i >= 304 THEN
temp_aidy := 304-101; DBMS_OUTPUT.PUT_LINE(temp_aidy); END IF;