w3resource

PL/SQL DataType: Procedure to accepts a BOOLEAN parameter and uses a CASE statement to print Unknown if the value of the parameter is NULL, Yes if it is TRUE, and No if it is FALSE

PL/SQL DataType: Exercise-4 with Solution

Write a PL/SQL procedure to accepts a BOOLEAN parameter and uses a CASE statement to print Unknown if the value of the parameter is NULL, Yes if it is TRUE, and No if it is FALSE.

Sample Solution:

PL/SQL Code:

CREATE PROCEDURE use_of_boolean (bl BOOLEAN) AUTHID DEFINER
AS
BEGIN
  DBMS_OUTPUT.put_line (
    CASE
      WHEN bl IS NULL THEN 'Unknown'
      WHEN bl THEN 'Yes'
      WHEN NOT bl THEN 'No'
    END
  );
END;
/

BEGIN
  use_of_boolean(NULL);
  use_of_boolean(FALSE);
  use_of_boolean(TRUE);
END;
/

Sample Output:

Unknown
No
Yes

PL/SQL procedure successfully completed.

Flowchart:

Flowchart: PL/SQL DataType - Procedure to accepts a BOOLEAN parameter and uses a CASE statement to print Unknown if the value of the parameter is NULL, Yes if it is TRUE, and No if it is FALSE
Flowchart: PL/SQL DataType - Procedure to accepts a BOOLEAN parameter and uses a CASE statement to print Unknown if the value of the parameter is NULL, Yes if it is TRUE, and No if it is FALSE

Go to:


PREV : Write a PL/SQL block to differenciate between CHAR and VARCHAR2 datatype.
NEXT : Write a PL/SQL program to show the upper limit of PLS_INTEGER.

Improve this sample solution and post your code through Disqus

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.