著重介紹Oracle創建單維、多維數組
1、單維數組
type nameArr is table of 字段類型 index by binary_integer;
變量名 nameArr ;
例:
一、
declare
type emp_ssn_array is table of number index by binary_integer;
best_employees emp_ssn_array;
begin
best_employees(1):= ‘1234’;
for i in 1..best_employees.count loop
dbms_output.putline( 'i=' || i || best best_employees(i));
end loop;
end; // sql 塊
二、
declare
type str_typearr is table of varchar(200) index by binary_integer;
str_typearrs str_typearr ;
begin
select * bulk collect into str_typearrs from table( fn_split( ' 1 , 3 , 55 ' , ',' ) ); //fn_split 分割函數,
//此句是將一串字符串按逗號分割後存入 str_typearrs 數組。
end;
2、多維數組
第一步創建對象;
create or replace type 對象名 as object (
字段名 字段類型, // 類似定義表
);
第二步創建對象集合;
create or replace type 對象集合名 is table of 對象名;
例:
create or replace type notes_eachStageCount as object (
p_type varchar2(10),
p_projectId varchar2(20),
p_count number,
p_overcount number,
p_ishaveplantime varchar2(20),
); // 創建對象
create or replace type eachStageCountArr is table of notes_eachStageCount ; // 創建數組
create or replace package temp_projectStageReport is
function getEachStageCount ( v_projectid in varchar2 ,v_type in varchar2 ) return eachStageCountArr;
end; //申明包體 及 函數
create or replace package body temp_projectStageReport is
function getEachStageCount ( v_projectid in varchar2 ,v_type in varchar2 ) return eachStageCountArr
as
p_carid varchar2(20) := '0' ;
v_stageArr eachStageCountArr := eachStageCountArr() ;
begin
v_stageArr.extend;
v_stageArr(1):= notes_eachStageCount('AP' , '0' , 0 , 0 , ' 2012-10-12');
return v_stageArr;
end getEachStageCount;
end temp_projectStageReport; // 包體
實踐調用:
mybatis xml 中 調用 參照本號文章《Mybatis常用傳參、返參、存儲過程、函數使用歸納》
閱讀更多 碼農筆記Day 的文章