0% found this document useful (0 votes)
4 views2 pages

SQL Arithmetic and Logical Operations

Uploaded by

l87020758
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

SQL Arithmetic and Logical Operations

Uploaded by

l87020758
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Sql>SET SERVEROUTPUT

DECLARE

-- Variables

A NUMBER := 10;

B NUMBER := 5;

Result NUMBER;

BEGIN

-- Arithmetic operations

Result := A + B; -- Addition

DBMS_OUTPUT.PUT_LINE('A + B = ' || Result);

Result := A - B; -- Subtraction

DBMS_OUTPUT.PUT_LINE('A - B = ' || Result);

Result := A * B; -- Multiplication

DBMS_OUTPUT.PUT_LINE('A * B = ' || Result);

Result := A / B; -- Division

DBMS_OUTPUT.PUT_LINE('A / B = ' || Result);

Result := A ** B; -- Exponentiation

DBMS_OUTPUT.PUT_LINE('A ** B = ' || Result);

-- Relational operations

IF A = B THEN

DBMS_OUTPUT.PUT_LINE('A is equal to B');

ELSE

DBMS_OUTPUT.PUT_LINE('A is not equal to B');

END IF;

IF A < B THEN

DBMS_OUTPUT.PUT_LINE('A is less than B');

ELSE

DBMS_OUTPUT.PUT_LINE('A is not less than B');

END IF;

-- Comparison operations

IF A BETWEEN 5 AND 20 THEN

DBMS_OUTPUT.PUT_LINE('A is between 5 and 20');

ELSE

DBMS_OUTPUT.PUT_LINE('A is not between 5 and 20');


END IF;

IF A IN (5, 10, 15) THEN

DBMS_OUTPUT.PUT_LINE('A is in the set (5, 10, 15)');

ELSE

DBMS_OUTPUT.PUT_LINE('A is not in the set (5, 10, 15)');

END IF;

-- Logical operations

IF (A > B) AND (A < 15) THEN

DBMS_OUTPUT.PUT_LINE('A is greater than B and less than 15');

ELSE

DBMS_OUTPUT.PUT_LINE('A does not satisfy the condition');

END IF;

-- String operations (not covered in this example)

END;

You might also like