2 回答
First off, what you are talking about does not appear to have anything to do with short-circuit evaluation. Short-circuit evaluation would be when code like
IF( quick_condition AND slow_condition )
THEN
<<do something>>
END IF;
evaluates the second slow condition if and only if the initial quick condition evaluates to TRUE.
Second, your assignment of a value to v_ssn_ind
is not syntactically valid.
Third, no, you cannot say
IF <<integer variable>>
THEN
because that would not make sense. What value would evaluate to TRUE and what value would evaluate to FALSE? If 0 is FALSE and 1 is TRUE, for example, what would 17 translate to?
If you are declaring some sort of indicator variable, it would generally make sense to use a BOOLEAN
data type rather than an integer. If you use a boolean, then you can do
IF <<boolean variable>>
THEN
because that eliminates the ambiguity. This won't be any faster than adding the = TRUE
to your IF condition however.
I discourage you from putting any logic into a declaration block, in my opinion it makes code less clear.
Instead IF
you can use CASE
statement.
...
v_ssn_ind INTEGER;
BEGIN
v_ssn_ind := CASE TRIM(p_ssn) IS NULL WHEN TRUE THEN 0 ELSE 1 END;
...
But personally I would chose BOOLEAN
type for v_ssn_ind
...
v_ssn_ind BOOLEAN;
BEGIN
v_ssn_ind := TRIM(p_ssn) IS NOT NULL;
...