w3resource

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

PL/SQL Fundamentals: Exercise-14 with Solution

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.

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_not_m (
    m  BOOLEAN
  ) IS
  BEGIN
    pri_bool ('m', m);
    pri_bool ('NOT m', NOT m);
  END pri_not_m;
 
BEGIN
DBMS_OUTPUT.PUT_LINE('------------- FOR m TRUE ---------------------');
  pri_not_m (TRUE);
DBMS_OUTPUT.PUT_LINE('------------- FOR m FALSE ---------------------');
  pri_not_m (FALSE);
DBMS_OUTPUT.PUT_LINE('------------- FOR m NULL ---------------------');
  pri_not_m (NULL);
END;
/

Sample Output:

------------- FOR m TRUE ---------------------
m = TRUE
NOT m = FALSE
------------- FOR m FALSE ---------------------
m = FALSE
NOT m = TRUE
------------- FOR m NULL ---------------------
m = NULL
NOT m = NULL

Flowchart:

Procedure

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

Now call the procedure pri_bool:

Flowchart: PL/SQL Fundamentals Exercise - PL/SQL block to create procedure and call it for NOT 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  OR operator  returns TRUE if either operand is TRUE.
Next: Write a PL/SQL block to describe the usage of NULL values in equal comparison, unequal comparison and NOT  NULL equals NULL comparison.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/plsql-exercises/fundamentals/plsql-fundamentals-exercise-14.php