SQL Tutorial

SQL Clauses / Operators

SQL-Injection

SQL Functions

SQL Queries

PL/SQL

MySQL

SQL Server

Misc

Greatest number among three given numbers in PL/SQL

To find the greatest number among three given numbers in PL/SQL, you can use conditional logic (IF-THEN-ELSE) to compare the values. Here's a simple PL/SQL block to determine the greatest number among three given numbers:

DECLARE 
    a NUMBER := 12; -- First number
    b NUMBER := 25; -- Second number
    c NUMBER := 18; -- Third number
    greatest_number NUMBER;
BEGIN 
    IF a > b AND a > c THEN
        greatest_number := a;
    ELSIF b > a AND b > c THEN
        greatest_number := b;
    ELSE
        greatest_number := c;
    END IF;

    DBMS_OUTPUT.PUT_LINE('The greatest number is: ' || greatest_number);
END;
/

Replace the values of a, b, and c with the numbers you wish to compare. After executing the script, the result will display the greatest of the three numbers.

  1. Oracle SQL Function for Determining the Largest Number Among Three:

    CREATE OR REPLACE FUNCTION FindMaxNumber(
        num1 NUMBER,
        num2 NUMBER,
        num3 NUMBER
    ) RETURN NUMBER IS
    BEGIN
        RETURN GREATEST(num1, num2, num3);
    END;
    /
    
  2. Comparing Three Numbers in PL/SQL and Identifying the Greatest:

    DECLARE
        num1 NUMBER := 10;
        num2 NUMBER := 15;
        num3 NUMBER := 8;
        max_num NUMBER;
    BEGIN
        IF num1 > num2 AND num1 > num3 THEN
            max_num := num1;
        ELSIF num2 > num3 THEN
            max_num := num2;
        ELSE
            max_num := num3;
        END IF;
    
        DBMS_OUTPUT.PUT_LINE('The greatest number is: ' || max_num);
    END;
    /
    
  3. PL/SQL Procedure for Finding the Maximum of Three Numbers:

    CREATE OR REPLACE PROCEDURE FindAndPrintMax(
        num1 IN NUMBER,
        num2 IN NUMBER,
        num3 IN NUMBER
    ) IS
        max_num NUMBER;
    BEGIN
        max_num := GREATEST(num1, num2, num3);
        DBMS_OUTPUT.PUT_LINE('The greatest number is: ' || max_num);
    END;
    /