Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

PL/SQL Fundamentals Exercises: PL/SQL block to create procedure and call it for OR operator

PL/SQL Fundamentals: Exercise-13 with Solution

Write a PL/SQL block to create a procedure using the "IS [NOT] NULL Operator" and show OR operator returns TRUE if either operand is TRUE.

Here is the procedure :

PL/SQL Code:

CREATE OR REPLACE PROCEDURE pri_bool(
  boo_name   VARCHAR2,
  boo_val    BOOLEAN
) IS
BEGIN
  IF boo_val IS NULL THEN
    DBMS_OUTPUT.PUT_LINE( boo_name || ' = NULL');
  ELSIF boo_val = TRUE THEN
    DBMS_OUTPUT.PUT_LINE( boo_name || ' = TRUE');
  ELSE
    DBMS_OUTPUT.PUT_LINE( boo_name || ' = FALSE');
  END IF;
END;
/

Now call the procedure pri_bool:

PL/SQL Code:

DECLARE
  PROCEDURE pri_m_or_n (
    m  BOOLEAN,
    n  BOOLEAN
  ) IS
  BEGIN
   pri_bool ('m', m);
   pri_bool ('n', n);
   pri_bool ('m OR n', m OR n);
 END pri_m_or_n;
BEGIN
DBMS_OUTPUT.PUT_LINE('------------- FOR m OR n both FALSE ---------------------');
 pri_m_or_n (FALSE, FALSE);
DBMS_OUTPUT.PUT_LINE('------------- FOR m TRUE OR n FALSE ---------------------');
 pri_m_or_n (TRUE, FALSE);
DBMS_OUTPUT.PUT_LINE('------------- FOR m FALSE OR n TRUE ---------------------');
 pri_m_or_n (FALSE, TRUE);
DBMS_OUTPUT.PUT_LINE('------------- FOR m TRUE OR n TRUE ---------------------');
 pri_m_or_n (TRUE, TRUE);
DBMS_OUTPUT.PUT_LINE('------------- FOR m TRUE OR n NULL ---------------------');
 pri_m_or_n (TRUE, NULL);
DBMS_OUTPUT.PUT_LINE('------------- FOR m FALSE OR n NULL---------------------');
 pri_m_or_n (FALSE, NULL);
DBMS_OUTPUT.PUT_LINE('------------- FOR m NULL OR n TRUE ---------------------');
 pri_m_or_n (NULL, TRUE);
DBMS_OUTPUT.PUT_LINE('------------- FOR m NULL OR n FALSE ---------------------');
 pri_m_or_n (NULL, FALSE);
END;
/

Sample Output:

------------- FOR m OR n both FALSE ---------------------
m = FALSE
n = FALSE
m OR n = FALSE
------------- FOR m TRUE OR n FALSE ---------------------
m = TRUE
n = FALSE
m OR n = TRUE
------------- FOR m FALSE OR n TRUE ---------------------
m = FALSE
n = TRUE
m OR n = TRUE
------------- FOR m TRUE OR n TRUE ---------------------
m = TRUE
n = TRUE
m OR n = TRUE
------------- FOR m TRUE OR n NULL ---------------------
m = TRUE
n = NULL
m OR n = TRUE
------------- FOR m FALSE OR n NULL---------------------
m = FALSE
n = NULL
m OR n = NULL
------------- FOR m NULL OR n TRUE ---------------------
m = NULL
n = TRUE
m OR n = TRUE
------------- FOR m NULL OR n FALSE ---------------------
m = NULL
n = FALSE
m OR n = NULL

Flowchart:

Procedure

Flowchart: PL/SQL Fundamentals Exercise - PL/SQL block to create procedure and call it for OR operator

Now call the procedure pri_bool:

Flowchart: PL/SQL Fundamentals Exercise - PL/SQL block to create procedure and call it for OR operator

Improve this sample solution and post your code through Disqus

Previous: Write a PL/SQL block to create a procedure using the "IS [NOT] NULL Operator" and show  AND operator  returns TRUE if and only if both operands are TRUE.
Next: Write a PL/SQL block to create a procedure using the "IS [NOT] NULL Operator" and show  NOT operator returns the opposite of its operand, unless the operand is NULL.

What is the difficulty level of this exercise?