- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Sum of the first and last digit of a number in PL/SQL
In this problem, we are given a number n. Our task is to create a program to find the sum of the first and last digit of a number in PL/SQL.
First, let’s brush-up about PL/SQL,
PL/SQL is a combination of SQL along with the procedural features of programming languages.
Let’s take an example to understand the problem,
Input − n = 31415
Output − 8
Explanation − first digit = 3 , last digit = 5. Sum = 8
To, solve this problem, we will extract the first and last digit to number n. And the print their sum.
The first and last digits are extracted using the substr() function.
Program to illustrate the working of our solution,
DECLARE n INTEGER := 31415; fistDigit INTEGER := 0; lastDigit INTEGER := 0; s INTEGER; BEGIN IF a > 9 THEN lastDigit:= Substr(n, 1, 1); fistDigit := Substr(n, Length(n), 1); s := fistDigit + lastDigit; ELSE s := n; END IF; dbms_output.Put_line('Sum of the first digit and last digit of the number is ' ||s); END; -- Program End
Sum of the first digit and last digit of the number is 8
- Find the sum of first and last digit for a number using C language
- Finding sum of first n natural numbers in PL/SQL
- Reverse a Number in PL/SQL
- Find the factorial of a number in pl/sql using C++.
- Check if the first and last digit of the smallest number forms a prime in Python
- Finding sum of first and last digit using divide and modulo operator in C language
- Difference between SQL and PL/SQL
- Count of Numbers in Range where first digit is equal to last digit of the number in C++
- Difference Between T-SQL and PL-SQL
- Count odd and even digits in a number in PL/SQL
- Find the area and perimeter of right triangle in PL/SQL
- Block of PL/SQL in Oracle DBMS
- Print pyramid of tutorialspoint in PL/SQL
- First digit in factorial of a number in C++
- Count no. of characters and words in a string in PL/SQL