oracle单维数组、多维数组

着重介绍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常用传参、返参、存储过程、函数使用归纳》


分享到:


相關文章: