In: Computer Science
PL/SQL
Write a PL/SQL block, using a While Loop, to calculate and print the sum of the odd integers from 10 to 120 inclusive. (Hint: 11 + 13 + 15 + . . . + 97 + 99)
Since we have to find the sum of odd integers from 10 to 120, we will take a variable numb and assign it with 11 as 11 is the first odd value after 10 as 10 is not an odd number. We will also take another variable sum to count the sum of the numbers as required. the code is -
DECLARE ## declaring the variales globally
numb NUMBER(2):= 11; ##
Initializing the variable as 11 (base value)
sum NUMBER(6):= 0;
## initialize the variable sum to store the result of
all sums
BEGIN ## Beginning of the code
WHILE numb<= 120
LOOP ## loop to iterate from 10 to 120.
sum:=sum+numb; ## find the
sum of the odd numbers.
numb:=numb+2; ## to go to next odd number
END
LOOP;
dbms_output.Put_line(
'Sum of all odd numbers
in between 10 and 120 is'
|| sum); ## To print the sum
of all the odd numbers
END
;
::PLEASE UPVOTE THE ASNWER::