- Related Questions & Answers
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1 in C++
- Compute sum of digits in all numbers from 1 to n
- Print numbers with digits 0 and 1 only such that their sum is N in C Program.
- Print prime numbers from 1 to N in reverse order
- Count pairs of numbers from 1 to N with Product divisible by their Sum in C++
- Print n numbers such that their sum is a perfect square
- Print pyramid of tutorialspoint in PL/SQL
- Difference between SQL and PL/SQL
- Count odd and even digits in a number in PL/SQL
- Program for Fibonacci numbers in PL/SQL
- Squared sum of n odd numbers - JavaScript
- C Program to print numbers from 1 to N without using semicolon
- Program to find all missing numbers from 1 to N in Python
- Sum of square of first n odd numbers
- Convert distance from km to meters and centimeters in PL/SQL

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given a number n and we have to print all odd numbers from 1 to n and also print the sum of numbers from 1 to n in **PL/SQL**.

**PL/SQL** is a procedural language extension to SQL. The code is a sequence of instructions that are ground in a block with all related declarations and instructions.

Let’s see an example of our problem −

Input: 7 Output: odd numbers are: 1, 3, 5, 7 Sum of odd numbers is 16

To solve this problem, we will take a number and initialize it to 1 and a sum variable with initial value 0. And we will increase the number by 2 and add into the sum variable until its value is less than or equal to n.

DECLARE number NUMBER(3) := 1; sumvar NUMBER(4) := 0; BEGIN dbms_output.Put_line('The odd numbers are : '); WHILE num <= 7 LOOP dbms_output.Put_line(number); sumvar := sumvar+num; num := num + 2; END LOOP; dbms_output.Put_line('Sum of odd numbers is '|| sum1); END;

The odd numbers are −

1 3 5 7 Sum of odd numbers is 16

Advertisements