Answer the question
In order to leave comments, you need to log in
How to forbid passing empty arguments to a procedure?
How, when creating a pl / sql procedure, to prohibit passing NULL values to arguments, to make them strictly (for example) VARCHAR2? At the same time, it is desirable to avoid explicit checks in the style of "IF arg IS NULL THEN ...", because many arguments are passed and their separate check clogs the code. Is there something like an argument modifier that says what values can be passed?
For example, this code runs without errors, but I want NULL to be treated as an invalid argument.
DECLARE
PROCEDURE null_args_testing(arg IN VARCHAR2) IS
BEGIN
NULL;
END;
BEGIN
null_args_testing('STRING'); -- При таком вызове процедура должна работать
null_args_testing(NULL); -- при таком вызове должно происходить исключение
END;
Answer the question
In order to leave comments, you need to log in
docs.oracle.com (Parameter Declaration):
You cannot constrain this data type (with NOT NULL, for example).
The first value in raise_application_error- must be in the custom error range:
PROCEDURE null_args_testing(arg IN VARCHAR2) IS
BEGIN
if arg is null then
raise_application_error(-20101, 'Value cannot be NULL');
end if;
NULL;
END;
You can also do this if you need more complex logic:
PROCEDURE null_args_testing(arg IN VARCHAR2) IS
p_is_null exception;
BEGIN
if arg is null then
raise p_is_null;
end if;
exception
when p_is_null then
/*processing logic*/
raise;/*procedure ends*/
END;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question