Prerequisite – PL/SQL introduction
In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations.
Given a number N, the task is to display all the odd numbers from 1 to N and their sum.
Input: 3 Output: 1, 3 Input: 5 Output: 1, 3, 5
Approach is to initialize a num with 1 and sum with 0 and keep incrementing num by 2 and sum by num until num <= N.
1 3 5 Sum of all odd numbers is 9
- Comparisons between SQL vs PLSQL
- Print all even numbers from 1 to n in PL/SQL
- Print Patterns in PL/SQL
- Print pyramid of GeeksforGeeks in PL/SQL
- Print different star patterns in SQL
- How to print duplicate rows in a table?
- GCD of two numbers in PL/SQL
- Sum Of Two Numbers in PL/SQL
- Sum and average of three numbers in PL/SQL
- Swap two numbers in PL/SQL
- Finding sum of first n natural numbers in PL/SQL
- Convert the given numbers into words in Pl/SQL
- Greatest number among three given numbers in PL/SQL
- Swap two numbers in PL/SQL without using temp
- Display Sequence of Numbers in SQL Using LEVEL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.