How to determine if the PL / SQL parameter value was set by default?

Suppose I have a PL / SQL stored procedure as follows:

PROCEDURE do_something(foo VARCHAR2 DEFAULT NULL) IS
BEGIN
    /* Do something */
END;

Now suppose that do_somethingis called in two different ways:

/* Scenario 1: The 'foo' parameter defaults to NULL */
do_something();

/* Scenario 2: The 'foo' parameter is explicitly set to NULL */
do_something(foo => NULL)

How to define a procedure do_somethingto determine which scenario calls it?

Edit: Refining my intentions for this procedure:

FUNCTION find_customer(name VARCHAR2 DEFAULT NULL, number VARCHAR2 DEFAULT NULL) RETURN NUMBER IS
BEGIN
    /* Query the "customer" table using only those parameters provided */
END;

The following are examples of how to use this procedure with the necessary SQL statements:

/* SELECT * FROM customer WHERE customer.name = 'Sam' */
find_customer(name => 'Sam')

/* SELECT * FROM customer WHERE customer.name = 'Sam' AND customer.number = '1588Z' */
find_customer(name => 'Sam', number => '1588Z')

/* SELECT * FROM customer WHERE customer.name = 'Sam' AND customer.number IS NULL */
find_customer(name => 'Sam', number => NULL)

/* SELECT * FROM customer WHERE customer.name IS NULL */
find_customer(name => NULL)

/* SELECT * FROM customer WHERE customer.name IS NULL AND customer.number IS NULL */
find_customer(name => NULL, number => NULL)
+3
source share
2 answers

You can overload this procedure instead of the default value:

PROCEDURE do_something(foo VARCHAR2) IS
BEGIN
    /* Do something */
END;

PROCEDURE do_something IS
BEGIN
    /* here you know: no argument. Then call do_something(null) */
END;
+7
source

null, -, ? , , , .

,

do_something (foo VARCHAR2 DEFAULT '* # @') IS

l_foo  VARCHAR2(32000); -- local copy of foo parm

IF foo = '*#@' THEN

-- I know the parm was omitted

   l_foo := NULL;

ELSE

   l_foo := foo;

END IF;

;

+8

Source: https://habr.com/ru/post/1708647/


All Articles