Showing posts with label division of two numbers in oracle. Show all posts
Showing posts with label division of two numbers in oracle. Show all posts

Sunday, May 28, 2017

Division of Two Numbers Using Oracle PL/SQL

In this article I would like to share with you a sample program that will ask the user to give two numbers and then it will compute the quotient of the two numbers using Oracle PL/SQL programming  language. I also added a function to check if the given numerator is zero it will display an error message the Divide Over Zero is Not Allowed. The code is very easy to understand and use. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.







Sample Program Output


Error Checking Screen Output



Program Listing
/* Division of Two Numbers With Exception Handling        */
/* Written By Mr. Jake R. Pomperada                       */
/* Language : PL/SQL                                      */
/* Date     : May 28, 2017  Sunday                        */

SET SERVEROUTPUT ON;
DECLARE
        
         solve NUMBER;
         message1 varchar2(50):= 'Division By Zero is not allow.';
         title   varchar2(50) :='Division of Two Numbers Program in PL/SQL';
         author   varchar2(50) :='Written By: Mr. Jake R. Pomperada,MAED-IT';
    
         /* User Input values */
         
         a number:=&a;
         b number:=&b;
         
    BEGIN
          
             solve := (a/b);
             dbms_output.put_line(chr(13)||chr(10) || title);
             dbms_output.put_line(chr(13)||chr(10) || author);
             dbms_output.put_line(chr(13)||chr(10)); 
             dbms_output.put_line('The Value of A is ' || a);
             dbms_output.put_line('The value of B is ' || b);
             dbms_output.put_line(chr(13)||chr(10));
             dbms_output.put_line('The result is ' || solve || '.');
    EXCEPTION
           WHEN ZERO_DIVIDE
   THEN
                 dbms_output.put_line(chr(13)||chr(10) || message1);
                 dbms_output.put_line(chr(13)||chr(10)); 
                 dbms_output.put_line('The Value of A is ' || a);
                 dbms_output.put_line('The value of B is ' || b);
   END;