I am trying to pull all the odd and even numbers from right to Left.
The Number is 00 1 0072053 60 3716796.
Below is the logic that i am trying to achieve.
1.From the right to left, assign the odd/even position to each digit. Start with odd position.
2.Sum all digits in odd position and multiply the result by 3.
3.Sum all digits in even position.
4.Get the total for the two steps above and divide the result by 10.
5.The check digit is the number which adds the remainder to 10.
can anyone pleasehelp me to achieve this. I need to Deliver this.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
wow... still can't follow but, if the problem involves searching a string and doing math with the pieces you may want to research/use functions below
substr() ... will allow you to pick a piece of the string.
lenght() ... will tell you the total lenght of the string.
to_number() ... will convert a char into a number
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
I'm guessing that this is what you want. Although I got a check sum of 7.
I deserve at least half of the credit for helping you with your homework!
PAVB, I don't think that you are too old. Since I work at a university
I can take classes. So I end up in computer classes with people half
my age. I would say that they are too young.
Code:
SYS@devdb AS SYSDBA> DECLARE
2 v_string VARCHAR2(2000) := REPLACE('001 0072053 60 3716796', ' ', '');
3 i PLS_INTEGER;
4 digitSum PLS_INTEGER := 0;
5 BEGIN
6 i := 1;
7 WHILE i < length(v_string)
8 LOOP
9 digitSum := digitSum + substr(v_string, i, 1);
10 i := i + 2;
11 END LOOP;
12
13 digitSum := digitSum * 3;
14
15 i := 0;
16 WHILE i < length(v_string)
17 LOOP
18 digitSum := digitSum + substr(v_string, i, 1);
19 i := i + 2;
20 END LOOP;
21
22 DBMS_OUTPUT.PUT_LINE('The check digit is: ' || MOD(digitSum, 10));
23 END;
24 /
The check digit is: 7
PL/SQL procedure successfully completed.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
So it was a check-digit calculation! now I can see it LOL
Man, that was one of the best inventions of the 70's, second only to punching an "*" on column 80 -to signal some exception LMAO
For my money adding a divide by zero fault checking would have been the best invention of the 70's. When I was in high school we had a mini computer with teletype terminals. A disgruntled student would occasionally initiate a divide by zero error, in order to crash the computer, then leave. The people who maintained the computer would spend the next hour trying to recover everything. I suppose it was funny the first few times he did it. Fortunately I was doing all my work on the Atari 800 with a basic cartridge and a cassette tape drive. Not that I am old or anything...
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Bookmarks