newkid大師的精華貼子
測試集合是否為空及為null
2 type customer_type is table of varchar2(30);
3 customer customer_type:=customer_type('customer1','customer2');
5 if customer is empty then
6 dbms_output.put_line('customer是空的empty,empty表明已初始化,但是個空集合,沒有集合元素');
9 if customer is null then
10 dbms_output.put_line('customer是null,null表示未初始化');
14 if customer.count>0 then
15 dbms_output.put_line('customer已初始化且有集合元素');
18 --用delete方法刪除初始化的集合為空再次用is empty判斷
19 if customer is empty then
20 dbms_output.put_line('customer是空的empty,empty表明已初始化,但是個空集合,沒有集合元素');
24 if customer is null then
25 dbms_output.put_line('customer是null,null表示未初始化');
28 if customer.count>0 then
29 dbms_output.put_line('customer已初始化且有集合元素');
31 dbms_output.put_line('customer已初始化但集合元素全被刪除了,目前集合元素是0');
customer是空的empty,empty表明已初始化,但是個空集合,沒有集合元素
customer已初始化但集合元素全被刪除了,目前集合元素是0
PL/SQL procedure successfully completed
小結:
1,null表示集合未初始化,empty已經初始化,只是集合目前沒有元素,
相當於count=0
函式中傳入一個值,向集合尾新增或更新
SQL> create or replace type number_type is table of number;
SQL> create or replace function func_test_number
2 (in_number in number,isreplace in boolean)
5 out_number_type number_type:=number_type(1,2,3);
8 out_number_type(out_number_type.last):=in_number;
10 out_number_type.extend;
11 out_number_type(4):=in_number;
13 return out_number_type;
2 x_number_type number_type;
4 x_number_type:=func_test_number(4,true);
5 for i in x_number_type.first..x_number_type.last loop
6 dbms_output.put_line(x_number_type(i));
PL/SQL procedure successfully completed
PL/SQL procedure successfully completed
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-722236/,如需轉載,請註明出處,否則將追究法律責任。