当前位置: 首页 > 知识库问答 >
问题:

ORA-06502:PL/SQL:数字或值错误:字符到数字转换错误

钱焕
2023-03-14

有没有办法在mybatis结果映射中指定一个字符串最多应包含20个字符?或者如何设置精度,如数字(4,2)?

例如,我有一个如下所示的结果图:

<resultMap id="IMap" type="com.optsol.beans.Item">

    <result property="item_id" column="ITEM_ID" jdbcType="INTEGER" />
    <result property="item_desc" column="ITEM_DESC" jdbcType="VARCHAR" />
    <result property="min_qty" column="MIN_QTY" jdbcType="INTEGER" />
    <result property="max_qty" column="MAX_QTY" jdbcType="INTEGER" />
    <result property="abc" column="ABC" jdbcType="VARCHAR" />
    <result property="item_weight" column="ITEM_WEIGHT" jdbcType="DOUBLE" />
    <result property="size_cl" column="SIZE_CL" jdbcType="INTEGER" />
    <result property="weight_class" column="WEIGHT_CLASS" jdbcType="INTEGER" />
    <result property="exp_period" column="EXP_PERIOD" jdbcType="DOUBLE" />
    <result property="code" column="CODE" jdbcType="VARCHAR" />
    <result property="um" column="UM" jdbcType="VARCHAR" />
    <result property="img" column="IMG" jdbcType="VARCHAR" />
    <result property="conv_factor" column="CONV_FACTOR" jdbcType="DOUBLE" />
    <result property="vol" column="VOL" jdbcType="INTEGER" />
    <result property="info" column="INFO" jdbcType="VARCHAR" />
    <result property="statist_report" column="STATIST_PERIOD"
        jdbcType="INTEGER" />
    <result property="pack_parent" column="PACK_PARENT" jdbcType="INTEGER" />
    <result property="group_parent" column="GROUP_PARENT" jdbcType="INTEGER" />
    <result property="order_full" column="ORDER_FULL" jdbcType="INTEGER" />
    <result property="insDate" column="INSDATE" />
    <result property="updDate" column="UPDDATE" />
    <result property="insUser" column="INSUSER" jdbcType="VARCHAR" />
    <result property="updUser" column="UPDUSER" jdbcType="VARCHAR" />
</resultMap>

我可以将int的位数限制为只有1,在浮点数上的“.”后面显示N个元素,或者将字符串大小限制为一定的数字吗?

我正在处理的视图具有以下列结构:

('ITEM_ID','NUMBER(10)','No',null,1,null,'NO','NO','NO');
('ITEM_DESC','VARCHAR2(80)','No',null,2,null,'NO','NO','NO');
('MIN_QTY','NUMBER(10)','Yes',null,3,null,'NO','NO','NO');
('MAX_QTY','NUMBER(10)','Yes',null,4,null,'NO','NO','NO');
('ABC','VARCHAR2(1)','No',null,5,null,'NO','NO','NO');
('ITEM_WEIGHT','NUMBER(10,3)','Yes',null,6,null,'NO','NO','NO');
('SIZE_CL','NUMBER(2)','Yes',null,7,null,'NO','NO','NO');
('WEIGHT_CLASS','NUMBER(2)','Yes',null,8,null,'NO','NO','NO');
('EXP_PERIOD','NUMBER(10,3)','Yes',null,9,null,'NO','NO','NO');
('CODE','VARCHAR2(20)','Yes',null,10,null,'NO','NO','NO');
('UM','VARCHAR2(15)','No',null,11,null,'NO','NO','NO');
('IMG','VARCHAR2(100)','Yes',null,12,null,'NO','NO','NO');
('CONV_FACTOR','NUMBER(10,4)','Yes',null,13,null,'NO','NO','NO');
('VOL','NUMBER(10)','Yes',null,14,null,'NO','NO','NO');
('INFO','VARCHAR2(100)','Yes',null,15,null,'NO','NO','NO');
('STATIST_PERIOD','NUMBER(5)','Yes',null,16,null,'NO','NO','NO');
('PACK_PARENT','NUMBER(10)','Yes',null,17,null,'NO','NO','NO');
('GROUP_PARENT','NUMBER(10)','Yes',null,18,null,'NO','NO','NO');
('ORDER_FULL','NUMBER(1)','No',null,19,null,'NO','NO','NO');
('INSDATE','DATE','No',null,20,null,'NO','NO','NO');
('UPDDATE','DATE','No',null,21,null,'NO','NO','NO');
('INSUSER','VARCHAR2(4000)','Yes',null,22,null,'NO','NO','NO');
('UPDUSER','VARCHAR2(4000)','Yes',null,23,null,'NO','NO','NO');

编辑1:每当我试图调用存储过程在此视图中添加新项时...我会得到这个错误:

org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.sql.SQLException: ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at line 2

我创建了一个用于测试的类,该类尝试调用add方法

 private ItemService iService = new ItemService(Item.class);
 @Test
  public void addProcTest() {
    Map<String, Object> paramMap = new HashMap<String, Object>();      
      paramMap.put("p_item_desc", "theo3");
      paramMap.put("p_min_qty", 1);
      paramMap.put("p_max_qty", 2);
      paramMap.put("p_abc", "A");
      paramMap.put("p_item_weight", 2);
      paramMap.put("p_size_cl", 1);
      paramMap.put("p_weight_class", 1);
      paramMap.put("p_exp_period", 2);
      paramMap.put("p_code", "theo");
      paramMap.put("p_um", "MP");
      paramMap.put("p_conv_factor",2.0);
      paramMap.put("p_vol", 2);
      paramMap.put("p_info", "theo2");
      paramMap.put("p_pack_parent", 105249);
      paramMap.put("p_group_parent", 0);
      paramMap.put("p_order_full", 0);
      paramMap.put("p_statist_period", 0);      
      paramMap.put("p_do_it", 1);
      iService.addItem(paramMap);
  }

ItemMapper.xml中存储过程的调用:

<update id="addItem" parameterType="java.util.Map"
    statementType="CALLABLE">

    {call
    SSLS_WMS.PKG_ITEM_ADMIN.PCREATEITEM(
    #{p_item_desc,jdbcType=VARCHAR},
    #{p_min_qty,jdbcType=INTEGER},
    #{p_max_qty,jdbcType=INTEGER},
    #{p_abc,jdbcType=VARCHAR},
    #{p_item_weight,jdbcType=DOUBLE},
    #{p_size_cl,jdbcType=INTEGER},
    #{p_weight_class,jdbcType=INTEGER},
    #{p_exp_period,jdbcType=DOUBLE},
    #{p_code,jdbcType=VARCHAR},
    #{p_um,jdbcType=VARCHAR},
    #{p_conv_factor,jdbcType=DOUBLE},
    #{p_vol,jdbcType=INTEGER},
    #{p_info,jdbcType=VARCHAR},
    #{p_pack_parent,jdbcType=INTEGER},
    #{p_group_parent,jdbcType=INTEGER},
    #{p_order_full,jdbcType=INTEGER},
    #{p_statist_period,jdbcType=INTEGER},
    #{p_do_it, jdbcType=INTEGER}
    )
    }
</update>

最后是存储过程:

PROCEDURE pCreateItem (
                p_ITEM_DESC         item.ITEM_DESC%type,
                p_MIN_QTY           item.MIN_QTY%type,
                p_MAX_QTY           item.MAX_QTY%type,
                p_ABC               item.ABC%type,
                p_ITEM_WEIGHT       item.ITEM_WEIGHT%type,
                p_SIZE_CL           item.SIZE_CL%type,
                p_WEIGHT_CLASS      item.WEIGHT_CLASS%type,
                p_EXP_PERIOD        item.EXP_PERIOD%type,
                p_CODE              item.CODE%type,
                p_UM                item_pack.UM%type,
                p_IMG               item_pack.IMG%type,
                p_CONV_FACTOR       item_pack.CONV_FACTOR%type,
                p_VOL               item_pack.VOL%type,
                p_INFO              item_pack.INFO%type,
                p_PackParent        item_pack.pack_id%type,
                p_GroupParent       item_pack.pack_id%type,
                p_order_full        item.order_full%type default 0,
                p_statist_period    item.STATIST_PERIOD%type default 3,
                p_do_it             PLS_INTEGER DEFAULT 1
);

共有1个答案

凌嘉勋
2023-03-14

您的问题是,您的过程有更多的参数,然后在MyBatis调用时传递给它,因此在缺少参数之后的任何时候,您都应该有ORA-06502:PL/SQL:numeric或value error错误,因为以下参数在传递它的顺序上的类型不同。

您的程序包括:

(...)
p_EXP_PERIOD        item.EXP_PERIOD%type,
p_CODE              item.CODE%type,
p_UM                item_pack.UM%type,
p_IMG               item_pack.IMG%type,
p_CONV_FACTOR       item_pack.CONV_FACTOR%type,
p_VOL               item_pack.VOL%type,
(...)

你在MyBatis的电话,你正在做:

(...)
#{p_exp_period,jdbcType=DOUBLE},
#{p_code,jdbcType=VARCHAR},
#{p_um,jdbcType=VARCHAR},
#{p_conv_factor,jdbcType=DOUBLE},
#{p_vol,jdbcType=INTEGER},
#{p_info,jdbcType=VARCHAR},
(...)

所以在之后p_IMGitem_pack。IMG%type,您没有传递任何未命中类型将导致您的错误。

 类似资料: