Reputation: 47
In my pl sql while loop i try to change the length of a number, which also then changes the length of my value on which my while loop is based the while loop stops working. The code is as follows
CREATE OR REPLACE FUNCTION neemrest(restnumber number)
RETURN NUMBER
AS
partrest NUMBER;
afternumber NUMBER;
BEGIN
WHILE LENGTH(TO_CHAR(restnumber))>9 LOOP
partrest := TO_NUMBER(SUBSTR(restnumber,1,10));
afternumber := TO_NUMBER(SUBSTR(restnumber,11,20));
restnumber := partrest||afternumber;
END LOOP;
RETURN MOD(restnumber,64);
END;
Now by taking each step seperatly i found that the problem liest in the last line of the while loop
restnumber := partrest||afternumber;
Now my question how can i change the lenght of my number whilst not breaking the while loop since this is vital for my function. and the usage of my function
Upvotes: 1
Views: 142
Reputation: 6604
The problem you are running into is that you are trying to assign a value to a readonly parameter.
You should modify your function to be like this:
CREATE OR REPLACE FUNCTION neemrest(restnumber in out number)
RETURN NUMBER
AS
partrest NUMBER;
afternumber NUMBER;
BEGIN
WHILE LENGTH(TO_CHAR(restnumber))>9 LOOP
partrest := TO_NUMBER(SUBSTR(restnumber,1,10));
afternumber := TO_NUMBER(SUBSTR(restnumber,11,20));
restnumber := partrest||afternumber;
END LOOP;
RETURN MOD(restnumber,64);
END;
Upvotes: 1