Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In oracle database, how can I specify default value for a parameter that is a user defined type?

    PACKAGE PKG_DEVICE AS 
     TYPE STR_ASSOC_ARR is table of VARCHAR(255) index by BINARY_INTEGER;
     procedure proc_create_device 
(
  in_deviceid in raw  
, in_devicecert in clob  
, in_status in number
, in_caps in STR_ASSOC_ARR
, in_vals in STR_ASSOC_ARR
);

is the stored procedure declaration. I would like to specify a default value for the in_caps and in_vals parameters. Is it possible? I am not able to specify default null as it doesn't work. My goal is to not have to pass these two parameters (or pass null) from C# when they are not available. If there is an odp.net way of accomplishing the same, that would work too.
Using oracle db 11g.

like image 286
Nithin Avatar asked Feb 23 '23 13:02

Nithin


1 Answers

You need to cast NULL as the user defined type. Try this:

    PACKAGE PKG_DEVICE AS 
     TYPE STR_ASSOC_ARR is table of VARCHAR(255) index by BINARY_INTEGER;
     procedure proc_create_device 
(
  in_deviceid in raw  
, in_devicecert in clob  
, in_status in number
, in_caps in STR_ASSOC_ARR DEFAULT CAST(NULL AS STR_ASSOC_ARR)
, in_vals in STR_ASSOC_ARR DEFAULT CAST(NULL AS STR_ASSOC_ARR)
);

Now you should not have to specify values for in_caps or in_vals. If the values are not passed, they default to NULL values of the STR_ASSOC_ARRAY type.

And of course, you'll need to update the procedure declaration in the package body to correspond to these changes.

like image 145
DCookie Avatar answered Feb 26 '23 17:02

DCookie