简体   繁体   中英

default collection type for SQL nested table type

I have an Oracle type that is a table of numbers:

CREATE OR REPLACE TYPE t_number AS TABLE OF number;

Now I want to use that type in an input parameter in a procedure, like so:

CREATE OR REPLACE PROCEDURE proc1 (pt_numbers_in IN t_number)...

How do I set a default value if the parameter is null? With a PL/SQL collection type, I know how to create an empty collection (in, say, a package spec) and use that as the default. Do I have to do the same thing here, or is there a better way to use a default variable of a SQL type? I want to so something like:

CREATE OR REPLACE PROCEDURE proc1 (pt_numbers_in IN t_number DEFAULT NULL)...

I'm running 11.2.0.4.

How do I set a default value if the parameter is null?

You'd have to write some code and check if a collection is the null collection, and if it is, initialize it.

If by "default" value you mean "I want this parameter to be optional", then simply use default clause to initialize a collection like so:

create or replace procedure proc1(
  p_numbers_in in t_number default t_number(1,2,3)
)
as
begin
  -- some useful code 
end;

Something like this from How to Initialize Variables

DECLARE
   t_number_var t_number := t_number(5);  -- initialize
BEGIN
   IF t_number_var(1) IS NULL THEN 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM