|
20-2. |
The snippet calls for you to use the LENGTH function to compute the length of the passed string. The wrinkle, though, is that the LENGTH function returns NULL, not zero, for a NULL string. Hence, you must wrap the call inside the NVL conversion function:
/* Print each character in a string */
CREATE OR REPLACE PROCEDURE nvl_test
(i_val IN VARCHAR2 DEFAULT NULL)
IS
str_len NUMBER := NVL (LENGTH (i_val), 0);
BEGIN
FOR i IN 1 .. str_len
LOOP
DBMS_OUTPUT.put_line (UPPER (SUBSTR (i_val, i, 1)));
END LOOP;
END; |