oracle存储过程经常使用技巧

咱们在进行pl/sql编程时打交道最多的就是存储过程了。存储过程的结构是很是的简单的,咱们在这里除了学习存储过程的基本结构外,还会学习编写存储过程时相关的一些实用的知识。如:游标的处理,异常的处理,集合的选择等等html

1.存储过程结构
1.1 第一个存储过程
create or replace procedure proc1(
p_para1 varchar2,
p_para2 out varchar2,
p_para3 in out varchar2
)as
v_name varchar2(20);
begin
v_name := '张三丰';
p_para3 := v_name;
dbms_output.put_line('p_para3:'||p_para3);
end;java

上面就是一个最简单的存储过程。一个存储过程大致分为这么几个部分:
建立语句:create or replace procedure 存储过程名
若是没有or replace语句,则仅仅是新建一个存储过程。若是系统存在该存储过程,则会报错。Create or replace procedure 若是系统中没有此存储过程就新建一个,若是系统中有此存储过程则把原来删除掉,从新建立一个存储过程。
存储过程名定义:包括存储过程名和参数列表。参数名和参数类型。参数名不能重复, 参数传递方式:IN, OUT, IN OUT
IN 表示输入参数,按值传递方式。
OUT 表示输出参数,能够理解为按引用传递方式。能够做为存储过程的输出结果,供外部调用者使用。
IN OUT 便可做输入参数,也可做输出参数。
参数的数据类型只须要指明类型名便可,不须要指定宽度。
参数的宽度由外部调用者决定。
过程能够有参数,也能够没有参数
变量声明块:紧跟着的as (is )关键字,能够理解为pl/sql的declare关键字,用于声明变量。
变量声明块用于声明该存储过程须要用到的变量,它的做用域为该存储过程。另外这里声明的变量必须指定宽度。遵循PL/SQL的变量声明规范。
过程语句块:从begin 关键字开始为过程的语句块。存储过程的具体逻辑在这里来实现。
异常处理块:关键字为exception ,为处理语句产生的异常。该部分为可选
结束块:由end关键字结果。程序员

1.2 存储过程的参数传递方式
存储过程的参数传递有三种方式:IN,OUT,IN OUT .
IN 按值传递,而且它不容许在存储过程当中被从新赋值。若是存储过程的参数没有指定存参数传递类型,默认为IN
create or replace procedure proc1(
p_para1 varchar2,
p_para2 out varchar2,
p_para3 in out varchar2
)as
v_name varchar2(20);
begin
p_para1 :='aaa';
p_para2 :='bbb';
v_name := '张三丰';
p_para3 := v_name;
dbms_output.put_line('p_para3:'||p_para3);
null;
end;sql

Warning: Procedure created with compilation errors数据库

SQL> show error;
Errors for PROCEDURE LIFEMAN.PROC1:express

LINE/COL ERROR
-------- ----------------------------------------------------------------------
8/3 PLS-00363: expression 'P_PARA1' cannot be used as an assignment target
8/3 PL/SQL: Statement ignored
这一点与其它高级语言都不一样。它至关于java在参数前面加上final关键字。编程

OUT 参数:做为输出参数,须要注意,当一个参数被指定为OUT类型时,就算在调用存储过程以前对该参数进行了赋值,在存储过程当中该参数的值仍然是null.
create or replace procedure proc1(
p_para1 varchar2,
p_para2 out varchar2,
p_para3 in out varchar2
)as
v_name varchar2(20);
begin
v_name := '张三丰';
p_para3 := v_name;
dbms_output.put_line('p_para1:'||p_para1);
dbms_output.put_line('p_para2:'||p_para2);
dbms_output.put_line('p_para3:'||p_para3);
end;数组

SQL> var p1 varchar2(10);
SQL> var p2 varchar2(10);
SQL> var p3 varchar2(10);
SQL> exec :p1 :='aaaa';
SQL> exec :p2 :='bbbb';
SQL> exec :p3 :='cccc';
SQL> exec proc1(:p1,:p2,:p3);
p_para1:aaaa
p_para2:
p_para3:张三丰
SQL> exec dbms_output.put_line(:p2);安全

PL/SQL procedure successfully completed
p2
---------app

INOUT 是真正的按引用传递参数。便可做为传入参数也能够做为传出参数。

1.3 存储过程参数宽度
create or replace procedure proc1(
p_para1 varchar2,
p_para2 out varchar2,
p_para3 in out varchar2
)as
v_name varchar2(2);
begin
v_name := p_para1;
end;

SQL> var p1 varchar2(10);
SQL> var p2 varchar2(20);
SQL> var p3 varchar2(30);
SQL> exec :p1 :='aaaaaa';
SQL> exec proc1(:p1,:p2,:p3);

ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "LIFEMAN.PROC1", line 8
ORA-06512: at line 1

首先,咱们要明白,咱们没法在存储过程的定义中指定存储参数的宽度,也就致使了咱们没法在存储过程当中控制传入变量的宽度。这个宽度是彻底由外部传入时决定的。
咱们再来看看OUT类型的参数的宽度。
create or replace procedure proc1(
p_para1 varchar2,
p_para2 out varchar2,
p_para3 in out varchar2
)as
v_name varchar2(2);
begin
p_para2 :='aaaaaaaaaaaaaaaaaaaa';
end;
SQL> var p1 varchar2(1);
SQL> var p2 varchar2(1);
SQL> var p3 varchar2(1);
SQL> exec :p2 :='a';
SQL> exec proc1(:p1,:p2,:p3);
在该过程当中,p_para2被赋予了20个字符a.
而在外部的调用过程当中,p2这个参数仅仅被定义为varchar2(1).
而把p2做为参数调用这个过程,却并无报错。并且它的真实值就是20个a
SQL> select dump(:p2) from dual;
DUMP(:P2)
---------------------------------------------------------------------------
Typ=1 Len=20: 97,97,97,97,97,97,97,97,97,97,97,97,97,97,97,97,97,97,97,97
p2
---------
aaaaaaaaaaaaaaaaaaaa

再来看看IN OUT参数的宽度

create or replace procedure proc1(
p_para1 varchar2,
p_para2 out varchar2,
p_para3 in out varchar2
)as
v_name varchar2(2);
begin
p_para3 :='aaaaaaaaaaaaaaaaaaaa';
end;

SQL> var p1 varchar2(1);
SQL> var p2 varchar2(1);
SQL> var p3 varchar2(1);
SQL> exec proc1(:p1,:p2,:p3);
执行这个过程,仍然正确执行。

可见,对于IN参数,其宽度是由外部决定。
对于OUT 和IN OUT 参数,其宽度是由存储过程内部决定。
所以,在写存储过程时,对参数的宽度进行说明是很是有必要的,最明智的方法就是参数的数据类型使用%type。这样双方就达成了一致。

1.3 参数的默认值
存储过程的参数能够设置默认值
create or replace procedure procdefault(p1 varchar2,
p2 varchar2 default 'mark')
as
begin
dbms_output.put_line(p2);
end;

SQL> set serveroutput on;
SQL> exec procdefault('a');
mark
能够经过default 关键字为存储过程的参数指定默认值。在对存储过程调用时,就能够省略默认值。
须要注意的是:默认值仅仅支持IN传输类型的参数。OUT 和 IN OUT不能指定默认值

对于有默认值的参数不是排在最后的状况。
create or replace procedure procdefault2(p1 varchar2 default 'remark',
p2 varchar2 )
as
begin
dbms_output.put_line(p1);
end;
第一个参数有默认值,第二个参数没有。若是咱们想使用第一个参数的默认值时
exec procdefault2('aa');
这样是会报错的。
那怎么变呢?能够指定参数的值。
SQL> exec procdefault2(p2 =>'aa');

remark
这样就OK了,指定aa传给参数p2

  1. 存储过程内部块
    2.1 内部块
    咱们知道了存储过程的结构,语句块由begin开始,以end结束。这些块是能够嵌套。在语句块中能够嵌套任何如下的块。
    Declare … begin … exception … end;
    create or replace procedure innerBlock(p1 varchar2)
    as
    o1 varchar2(10) := 'out1';
    begin
    dbms_output.put_line(o1);
    declare
    inner1 varchar2(20);
    begin
    inner1 :='inner1';
    dbms_output.put_line(inner1);

    declare
    inner2 varchar2(20);
    begin
    inner2 := 'inner2';
    dbms_output.put_line(inner2);
    end;
    exception
    when others then
    null;
    end;
    end;
    须要注意变量的做用域。

3.存储过程的经常使用技巧
3.1 哪一种集合?
咱们在使用存储过程的时候常常须要处理记录集,也就是多条数据记录。分为单列多行和多列多行,这些类型均可以称为集合类型。咱们在这里进行比较这些集合类型,以便于在编程时作出正确的选择。
索引表,也称为pl/sql表,不能存储于数据库中,元素的个数没有限制,下标能够为负值。
type t_table is table of varchar2(20) index by binary_integer;
v_student t_table;
varchar2(20)表示存放元素的数据类型,binary_integer表示元素下标的数据类型。
嵌套表,索引表没有 index by子句就是嵌套表,它能够存放于数据中,元素个数无限,下标从1开始,而且须要初始化
type t_nestTable is table of varchar2(20);
v_class t_nestTable ;
仅是这样声明是不能使用的,必须对嵌套表进行初始化,对嵌套表进行初始化可使用它的构造函数
v_class :=t_nestTable('a','b','c');
变长数组,变长数组与高级语言的数组类型很是类似,下标以1开始,元素个数有限。
type t_array is varray (20) of varchar2(20);

varray(20)就定义了变长数组的最大元素个数是20个
变长数组与嵌套表同样,也能够是数据表列的数据类型。
同时,变长数组的使用也须要事先初始化。

类型 可存储于数据库 元素个数 是否需初始化 初始下标值
索引表 否 无限 不需
嵌套表 可 无限 需 1
可变数组 可 有限(自定义) 需 1

因而可知,若是仅仅是在存储过程当中看成集合变量使用,索引表是最好的选择。

3.2 选用何种游标?
显示游标分为:普通游标,参数化游标和游标变量三种。
下面以一个过程来进行说明
create or replace procedure proccursor(p varchar2)
as
v_rownum number(10) := 1;
cursor c_postype is select pos_type from pos_type_tbl where rownum =1;
cursor c_postype1 is select pos_type from pos_type_tbl where rownum = v_rownum;
cursor c_postype2(p_rownum number) is select pos_type from pos_type_tbl where rownum = p_rownum;
type t_postype is ref cursor ;
c_postype3 t_postype;
v_postype varchar2(20);
begin
open c_postype;
fetch c_postype into v_postype;
dbms_output.put_line(v_postype);
close c_postype;
open c_postype1;
fetch c_postype1 into v_postype;
dbms_output.put_line(v_postype);
close c_postype1;
open c_postype2(1);
fetch c_postype2 into v_postype;
dbms_output.put_line(v_postype);
close c_postype2;
open c_postype3 for select pos_type from pos_type_tbl where rownum =1;
fetch c_postype3 into v_postype;
dbms_output.put_line(v_postype);
close c_postype3;
end;

cursor c_postype is select pos_type from pos_type_tbl where rownum =1
这一句是定义了一个最普通的游标,把整个查询已经写死,调用时不能够做任何改变。
cursor c_postype1 is select pos_type from pos_type_tbl where rownum = v_rownum;
这一句并无写死,查询参数由变量v_rownum来决定。须要注意的是v_rownum必须在这个游标定义以前声明。
cursor c_postype2(p_rownum number) is select pos_type from pos_type_tbl where rownum = p_rownum;
这一条语句与第二条做用类似,都是能够为游标实现动态的查询。可是它进一步的缩小了参数的做用域范围。可是可读性下降了很多。
type t_postype is ref cursor ;
c_postype3 t_postype;
先定义了一个引用游标类型,而后再声明了一个游标变量。
open c_postype3 for select pos_type from pos_type_tbl where rownum =1;
而后再用open for 来打开一个查询。须要注意的是它能够屡次使用,用来打开不一样的查询。
从动态性来讲,游标变量是最好用的,可是阅读性也是最差的。
注意,游标的定义只能用使关键字IS,它与AS不通用。

3.3 游标循环最佳策略
咱们在进行PL/SQL编程时,常常须要循环读取结果集的数据。进行逐行处理,这个过程就须要对游标进行循环。对游标进行循环的方法有多种,咱们在此一一分析。
create or replace procedure proccycle(p varchar2)
as
cursor c_postype is select pos_type, description from pos_type_tbl where rownum < 6;
v_postype varchar2(20);
v_description varchar2(50);
begin
open c_postype;
if c_postype%found then
dbms_output.put_line('found true');
elsif c_postype%found = false then
dbms_output.put_line('found false');
else
dbms_output.put_line('found null');
end if;
loop
fetch c_postype into v_postype,v_description ;
exit when c_postype%notfound;
dbms_output.put_line('postype:'||v_postype||',description:'||v_description);
end loop;
close c_postype;
dbms_output.put_line('---loop end---');
open c_postype;
fetch c_postype into v_postype,v_description;
while c_postype%found loop
dbms_output.put_line('postype:'||v_postype||',description:'||v_description);
fetch c_postype into v_postype,v_description ;
end loop;

close c_postype;
dbms_output.put_line('---while end---');
for v_pos in c_postype loop
v_postype := v_pos.pos_type;
v_description := v_pos.description;
dbms_output.put_line('postype:'||v_postype||',description:'||v_description);
end loop;
dbms_output.put_line('---for end---');
end;

使用游标以前须要开打游标,open cursor,循环完后再关闭游标close cursor.
这是使用游标应该慎记于心的法则。
上面的过程演示了游标循环的三种方法。
在讨论循环方法以前,咱们先看看%found和%notfound这些游标的属性。

open c_postype;
if c_postype%found then
dbms_output.put_line('found true');
elsif c_postype%found = false then
dbms_output.put_line('found false');
else
dbms_output.put_line('found null');
end if;
在打开一个游标以后,立刻检查它的%found或%notfound属性,它获得的结果即不是true也不是false.而是null.必须执行一条fetch语句后,这些属性才有值。

第一种使用loop 循环
loop
fetch c_postype into v_postype,v_description ;
exit when c_postype%notfound;
……
end loop
这里须要注意,exit when语句必定要紧跟在fetch以后。必避免多余的数据处理。
处理逻辑须要跟在exit when以后。这一点须要多加当心。
循环结束后要记得关闭游标。

第二种使用while循环。
fetch c_postype into v_postype,v_description;
while c_postype%found loop
……
fetch c_postype into v_postype,v_description ;
end loop;

咱们知道了一个游标打开后,必须执行一次fetch语句,游标的属性才会起做用。因此使用while 循环时,就须要在循环以前进行一次fetch动做。
并且数据处理动做必须放在循环体内的fetch方法以前。循环体内的fetch方法要放在最后。不然就会多处理一次。这一点也要很是的当心。
总之,使用while来循环处理游标是最复杂的方法。

第三种 for循环
for v_pos in c_postype loop
v_postype := v_pos.pos_type;
v_description := v_pos.description;

end loop;
可见for循环是比较简单实用的方法。
首先,它会自动open和close游标。解决了你忘记打开或关闭游标的烦恼。
其它,自动定义了一个记录类型及声明该类型的变量,并自动fetch数据到这个变量中。
咱们须要注意v_pos 这个变量无须要在循环外进行声明,无须要为其指定数据类型。
它应该是一个记录类型,具体的结构是由游标决定的。
这个变量的做用域仅仅是在循环体内。
把v_pos看做一个记录变量就能够了,若是要得到某一个值就像调用记录同样就能够了。
如v_pos.pos_type
因而可知,for循环是用来循环游标的最好方法。高效,简洁,安全。
但遗憾的是,经常见到的倒是第一种方法。因此从今以后得改变这个习惯了。

3.4 select into不可乎视的问题
咱们知道在pl/sql中要想从数据表中向变量赋值,须要使用select into 子句。
可是它会带动来一些问题,若是查询没有记录时,会抛出no_data_found异常。
若是有多条记录时,会抛出too_many_rows异常。
这个是比较糟糕的。一旦抛出了异常,就会让过程当中断。特别是no_data_found这种异常,没有严重到要让程序中断的地步,能够彻底交给由程序进行处理。
create or replace procedure procexception(p varchar2)
as
v_postype varchar2(20);
begin
select pos_type into v_postype from pos_type_tbl where 1=0;
dbms_output.put_line(v_postype);
end;

执行这个过程
SQL> exec procexception('a');
报错
ORA-01403: no data found
ORA-06512: at "LIFEMAN.PROCEXCEPTION", line 6
ORA-06512: at line 1

处理这个有三个办法
1. 直接加上异常处理。
create or replace procedure procexception(p varchar2)
as
v_postype varchar2(20);

begin
select pos_type into v_postype from pos_type_tbl where 1=0;
dbms_output.put_line(v_postype);
exception
when no_data_found then
dbms_output.put_line('没找到数据');
end;
这样作换汤不换药,程序仍然被中断。可能这样不是咱们所想要的。

  1. select into作为一个独立的块,在这个块中进行异常处理
    create or replace procedure procexception(p varchar2)
    as
    v_postype varchar2(20);

begin
begin
select pos_type into v_postype from pos_type_tbl where 1=0;
dbms_output.put_line(v_postype);
exception
when no_data_found then
v_postype := '';
end;
dbms_output.put_line(v_postype);
end;
这是一种比较好的处理方式了。不会由于这个异常而引发程序中断。
3.使用游标
create or replace procedure procexception(p varchar2)
as
v_postype varchar2(20);
cursor c_postype is select pos_type from pos_type_tbl where 1=0;
begin
open c_postype;
fetch c_postype into v_postype;
close c_postype;
dbms_output.put_line(v_postype);
end;
这样就彻底的避免了no_data_found异常。彻底交由程序员来进行控制了。

第二种状况是too_many_rows 异常的问题。
Too_many_rows 这个问题比起no_data_found要复杂一些。
给一个变量赋值时,可是查询结果有多个记录。
处理这种问题也有两种状况:
1. 多条数据是能够接受的,也就是说从结果集中随便取一个值就行。这种状况应该很极端了吧,若是出现这种状况,也说明了程序的严谨性存在问题。
2. 多条数据是不能够被接受的,在这种状况确定是程序的逻辑出了问题,也说是说原来根本就不会想到它会产生多条记录。
对于第一种状况,就必须采用游标来处理,而对于第二种状况就必须使用内部块来处理,从新抛出异常。
多条数据能够接受,随便取一条,这个跟no_data_found的处理方式同样,使用游标。
我这里仅说第二种状况,不可接受多条数据,可是不要忘了处理no_data_found哦。这就不能使用游标了,必须使用内部块。
create or replace procedure procexception2(p varchar2)
as
v_postype varchar2(20);

begin
begin
select pos_type into v_postype from pos_type_tbl where rownum < 5;
exception
when no_data_found then
v_postype :=null;
when too_many_rows then
raise_application_error(-20000,'对v_postype赋值时,找到多条数据');
end;
dbms_output.put_line(v_postype);
end;
须要注意的是必定要加上对no_data_found的处理,对出现多条记录的状况则继续抛出异常,让上一层来处理。
总之对于select into的语句须要注意这两种状况了。须要稳当处理啊。

3.5 在存储过程当中返回结果集
咱们使用存储过程都是返回值都是单一的,有时咱们须要从过程当中返回一个集合。即多条数据。这有几种解决方案。比较简单的作法是写临时表,可是这种作法不灵活。并且维护麻烦。咱们可使用嵌套表来实现.没有一个集合类型可以与java的jdbc类型匹配。这就是对象与关系数据库的阻抗吧。数据库的对象并不可以彻底转换为编程语言的对象,还必须使用关系数据库的处理方式。

create or replace package procpkg is
type refcursor is ref cursor;
procedure procrefcursor(p varchar2, p_ref_postypeList out refcursor);
end procpkg;

create or replace package body procpkg is
procedure procrefcursor(p varchar2, p_ref_postypeList out refcursor)
is
v_posTypeList PosTypeTable;
begin
v_posTypeList :=PosTypeTable();--初始化嵌套表
v_posTypeList.extend;
v_posTypeList(1) := PosType('A001','客户资料变动');
v_posTypeList.extend;
v_posTypeList(2) := PosType('A002','团体资料变动');
v_posTypeList.extend;
v_posTypeList(3) := PosType('A003','受益人变动');
v_posTypeList.extend;
v_posTypeList(4) := PosType('A004','续期交费方式变动');
open p_ref_postypeList for select * from table(cast (v_posTypeList as PosTypeTable));
end;
end procpkg;

在包头中定义了一个游标变量,并把它做为存储过程的参数类型。
在存储过程当中定义了一个嵌套表变量,对数据写进嵌套表中,而后把嵌套表进行类型转换为table,游标变量从这个嵌套表中进行查询。外部程序调用这个游标。
因此这个过程须要定义两个类型。
create or replace type PosType as Object (
posType varchar2(20),
description varchar2(50)
);
create or replace type PosTypeTable is table of PosType;
须要注意,这两个类型不能定义在包头中,必须单独定义,这样java层才能使用。

在外部经过pl/sql来调用这个过程很是简单。
set serveroutput on;
declare
type refcursor is ref cursor;
v_ref_postype refcursor;
v_postype varchar2(20);
v_desc varchar2(50);
begin
procpkg.procrefcursor('a',v_ref_postype);
loop
fetch v_ref_postype into v_postype,v_desc;
exit when v_ref_postype%notfound;
dbms_output.put_line('posType:'|| v_postype || ';description:' || v_desc);
end loop;
end;

注意:对于游标变量,不能使用for循环来处理。由于for循环会隐式的执行open动做。而经过open for来打开的游标%isopen是为true的。也就是默认打开的。Open一个已经open的游标是错误的。因此不能使用for循环来处理游标变量。

咱们主要讨论的是如何经过jdbc调用来处理这个输出参数。
conn = this.getDataSource().getConnection();
CallableStatement call = conn.prepareCall("{call procpkg.procrefcursor(?,?)}");
call.setString(1, null);
call.registerOutParameter(2, OracleTypes.CURSOR);
call.execute();
ResultSet rsResult = (ResultSet) call.getObject(2);
while (rsResult.next()) {
String posType = rsResult.getString("posType");
String description = rsResult.getString("description");
......
}

这就是jdbc的处理方法。

Ibatis处理方法:
1.参数配置



2.调用过程

{call procpkg.procrefcursor(?,?)}

3.定义本身的处理器
public class CursorHandlerCallBack implements TypeHandler{
public Object getResult(CallableStatement cs, int index) throws SQLException {
ResultSet rs = (ResultSet)cs.getObject(index);
List result = new ArrayList();
while(rs.next()) {
String postype =rs.getString(1);
String description = rs.getString(2);
CodeTableItemDTO posTypeItem = new CodeTableItemDTO();
posTypeItem.setCode(postype);
posTypeItem.setDescription(description);
result.add(posTypeItem);
}
return result;
}

  1. dao方法
    public List procPostype() {
    String p = "";
    Map para = new HashMap();
    para.put("p",p);
    para.put("p_ref_postypeList",null);
    this.getSqlMapClientTemplate().queryForList("pos_dayprocset.procrefcursor", para);
    return (List)para.get("p_ref_postypeList");
    }

这个跟jdbc的方式很是的类似.
咱们使用的是ibatis的2.0版本,比较麻烦。
若是是使用2.2以上版本就很是简单的。
由于能够在parameterMap中定义一个resultMap.这样就无须要本身定义处理器了。
能够从分析2.0和2.0的dtd文件知道。

上面的两种方式都是很是的复杂,若是仅仅是须要返回一个结果集,那就彻底可使用函数来实现了。
create or replace package procpkg is
type refcursor is ref cursor;
procedure procrefcursor(p varchar2, p_ref_postypeList out refcursor);
function procpostype(p varchar2) return PosTypeTable;
end procpkg;

create or replace package body procpkg is
procedure procrefcursor(p varchar2, p_ref_postypeList out refcursor)
is
v_posTypeList PosTypeTable;
begin
v_posTypeList :=PosTypeTable();--初始化嵌套表
v_posTypeList.extend;
v_posTypeList(1) := PosType('A001','客户资料变动');
v_posTypeList.extend;
v_posTypeList(2) := PosType('A002','团体资料变动');
v_posTypeList.extend;
v_posTypeList(3) := PosType('A003','受益人变动');
v_posTypeList.extend;
v_posTypeList(4) := PosType('A004','续期交费方式变动');
open p_ref_postypeList for select * from table(cast (v_posTypeList as PosTypeTable));
end;

function procpostype(p varchar2) return PosTypeTable
as
v_posTypeList PosTypeTable;
begin
v_posTypeList :=PosTypeTable();--初始化嵌套表
v_posTypeList.extend;
v_posTypeList(1) := PosType('A001','客户资料变动');
v_posTypeList.extend;
v_posTypeList(2) := PosType('A002','团体资料变动');
v_posTypeList.extend;
v_posTypeList(3) := PosType('A003','受益人变动');
v_posTypeList.extend;
v_posTypeList(4) := PosType('A004','续期交费方式变动');
return v_posTypeList;
end;
end procpkg;

ibatis配置




Dao的写法跟普通查询同样
public List queryPostype() {
return this.getSqlMapClientTemplate().queryForList("pos_dayprocset.procPostype", null);
}

有几点须要注意,这里不能使用索引表,而是嵌套表。
另外就是把嵌套表强制转换为普通表。

http://www.cnblogs.com/chinafine/archive/2010/07/12/1776102.html

相关文章
相关标签/搜索