
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Reverse a Number in PL/SQL
PL/SQL is a block-structured language that combines SQL's functionality with procedural commands. In this article, we will discuss a program in PL/SQL to reverse a given number for example −
Input : 98765 Output : 56789 Explanation : reverse number of 98765 is 56789. Input : 56784 Output : 48765 Explanation Reverse number of ‘56784’ is ‘48765’.
Approach to find The Solution
- Take out the last digit from the number by finding the remainder of num/10.
- Now add the last digit to another variable reversed_num.
- Now check if num becomes 0 −
- If YES, then go to STEP1.
- If NO, then go to STEP4.
- Finally, print the reversed_num.
Example
DECLARE num number; reverse_num number:=0; begin num:=98765; while num>0 loop reverse_num:=(reverse_num*10) + mod(num,10); num:=trunc(num/10); end loop; dbms_output.put_line(' Reversed number is : '|| reverse_num);
Output
Reversed number is: 56789
Conclusion
In this article, we discuss the PL/SQL programming language, which is very simple to use; it feels like using ordinary English to command the system. We also discussed a problem of reversing a number in PL/SQL language. We hope you find this article helpful.
- Related Questions & Answers
- How to Reverse a String in PL/SQL using C++
- Difference between SQL and PL/SQL
- What is PL/SQL?
- Count odd and even digits in a number in PL/SQL
- Difference Between T-SQL and PL-SQL
- Find the factorial of a number in pl/sql using C++.
- Sum of the first and last digit of a number in PL/SQL
- Block of PL/SQL in Oracle DBMS
- Print pyramid of tutorialspoint in PL/SQL
- Program for Fibonacci numbers in PL/SQL
- Explain the PL/SQL Engine in DBMS
- Floyd's triangle in PL/SQL
- How to capture Oracle errors in PL/SQL?
- Check if a given year is leap year in PL/SQL
- Count no. of characters and words in a string in PL/SQL
Advertisements