TL; DR:
How can I declare a user-defined record type so that if I don't populate one of the fields, that field will honor its DEFAULT
?
Details:
In my package spec, I define the following record and table types:
/* set up a custom datatypes that will allow us to pass an array of values into CCD_UI procedures and functions */
TYPE RECORD_OPTION_ATTRIBUTES IS RECORD(
option_name VARCHAR2(200) NOT NULL DEFAULT 'INVALID NAME"', /* default intentionally breaks HTML */
option_value VARCHAR2(200) NOT NULL DEFAULT 'INVALID VALUE"', /* default intentionally breaks HTML */
option_selected_ind NUMBER(1) NOT NULL DEFAULT '0',
option_class VARCHAR2(200) DEFAULT NULL,
option_attributes VARCHAR2(200) DEFAULT NULL
);
TYPE TABLE_OPTION_ATTRIBUTES IS TABLE OF RECORD_OPTION_ATTRIBUTES
INDEX BY BINARY_INTEGER;
In the package body, I have functionality very similar to this:
PROCEDURE populate_user_defined_table()
AS
v_criteria_pairs TABLE_OPTION_ATTRIBUTES;
BEGIN
SELECT some_column1 AS option_name, some_column2 AS option_value, some_column3 AS selected_ind,
some_column4 AS option_class
BULK COLLECT INTO v_criteria_pairs
FROM Some_Table
WHERE some_column='whatever';
END;
The sharp eye will notice that I am not inserting any values into the option_attributes
field; I am populating only 4 of the 5 available fields.
When I attempt to compile this package, I receive the following error from the package body:
PL/SQL: ORA-00913: too many values
If I drop the option_attributes
field from the RECORD_OPTION_ATTRIBUTES
declaration, the package will compile.
How can I declare the record type so that if I don't specify a value for option_attributes
, that field will default to NULL
?