<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    cuiyi's blog(崔毅 crazycy)

    記錄點(diǎn)滴 鑒往事之得失 以資于發(fā)展
    數(shù)據(jù)加載中……

    非常有意思的sql排錯(cuò)

    1)  你看出區(qū)別在哪里了么? 結(jié)果會(huì)一樣么?
    SELECT
    (select first 
    1 longname from ivctrallocpurch a join jcivloc l  on a.ivlocid=l.ivlocid and a.ctrid=A.ctrid) as mill
    FROM CTR A
    JOIN CTRSMRY CS ON (A.CTRID
    =CS.CTRID)
    WHERE A.CTRID
    =3161

    SELECT
    (select first 
    1 longname from ivctrallocpurch a join jcivloc l  on a.ivlocid=l.ivlocid and a.ctrid=3161) as mill
    FROM CTR A
    JOIN CTRSMRY CS ON (A.CTRID
    =CS.CTRID)
    WHERE A.CTRID
    =3161
    結(jié)果為什么不一樣呢?


    2) Integer overflow. The result of an integer operation caused the most significant bit of the result to carry.
    select sum(rcpt.artothome * rate) as amt
    from cashreceipt rcpt
    join homerate rate on rcpt.currencyid=rate.currencyid
    分析:
    artothome @ arheader  is : numeric(18,4)
    rate @ ..  is : numeric(
    10,10)
    改進(jìn)1 (not work)
    select sum(cast(rcpt.artothome * rate as numeric(18,4))) as amt
    from cashreceipt rcpt
    join homerate rate on rcpt.currencyid
    =rate.currencyid
    改進(jìn)2 (works)
    select sum(cast(cast(rcpt.artothome as numeric(18,4)) * cast(rate as numeric(18,4)) as numeric(18,4))) as amt
    from cashreceipt rcpt
    join homerate rate on rcpt.currencyid
    =rate.currencyid
    reason, forward from http://www.firebirdfaq.org/faq207/
    Integer overflow. The result of an integer operation caused the most significant bit of the result to carry.

    Short explanation:
    If you use fixed precision datatypes (smallint, integer, bigint, decimal and numeric), it is possible that the result of calculation doesn
    't fit the datatype. Try casting the values in complex expressions as double precision and see whether the error goes away. If it works and you don't care about being too precise, you can leave it at that. Otherwise you need to check every operation and calculate the result.

    Details:
    Here
    's an example: if you multiply 9.12 with 8.11 (both numeric(18,2)) you would get 73.9632. If Firebird would store that into numeric(18,2) datatype, we would lose 0.0032. Doesn't look much, but when you have complex calculations, you can easily loose thousands (dollars or euros). Therefore, the result is stored in numeric(18,4).

    Problems are rarely seen with such low precision as 
    2. Let's use some bigger precision. For example, numeric(18,6) times numeric(18,6) yields numeric(18,12) result, meaning that maximal value it can store is 9223372.036854775807. If (for example) you wish to keep only 6 digits of precision, you could use something like:

    cast(value1 as numeric(
    18,3)) * cast(value2 as numeric(18,3))

    which would yield numeric(
    18,6) result, but it is quite possible that you would get more accurate result by casting to double:

    cast(cast(value1 as 
    double precision) * cast(value2 as double precision) as numeric(18,6))

    Also, 
    if you have mixed multiplications and divisions it helps to change the order of operations, so that the overflow doesn't happen.


    String sql = "select mbrid from jcmbr where reference4=?";
    假如沒(méi)有記錄
    DynaBean aBean 
    = CxcDataModule.getInstance().getRow(sql, new Object[]{reference4});
    如果直接用aBean.get("
    reference4") 出錯(cuò);
    錯(cuò)誤的原因是
    aBean  為null

    Object obj 
    = {spring jdbctemplate}.queryForObject(sql, new Object[]{reference4}, Integer.class);
    if (obj instanceof Integer)
             System.out.println(
    "(Integer)obj>>>>>>>>>>" + (Integer)obj);
    else if (obj instanceof Map)
                System.out.println(
    "(Integer)obj>>>>>>>>>>" + ((Map)obj).get("REFERENCE4"));
    真是的流程是 if 分支
    如果有數(shù)據(jù),這是對(duì)的
    如果沒(méi)有數(shù)據(jù),直接出錯(cuò),因?yàn)橛袀€(gè)假定有Integer值存在

    int value = JcDataModuleUtils.getJdbcTemplate().queryForInt(sql, new Object[]{reference4});
    出錯(cuò)原因是假定一定會(huì)有一個(gè)int值返回

    15:09:00,438 ERROR [STDERR] Caused by: org.springframework.dao.IncorrectResultSizeDataAccessException: Incorrect result size:
     expected 1, actual 0
    15:09:00,438 ERROR [STDERR]     at org.springframework.dao.support.DataAccessUtils.requiredUniqueResult(DataAccessUtils.java:
    66)
    15:09:00,469 ERROR [STDERR]     at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:620)
    15:09:00,469 ERROR [STDERR]     at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:629)
    15:09:00,469 ERROR [STDERR]     at org.springframework.jdbc.core.JdbcTemplate.queryForInt(JdbcTemplate.java:656)




    posted on 2008-04-08 18:30 crazycy 閱讀(1688) 評(píng)論(0)  編輯  收藏 所屬分類: DBMS

    主站蜘蛛池模板: 一级成人毛片免费观看| 免费无码又爽又刺激高潮| 美女扒开屁股让男人桶爽免费| 亚洲国产精品一区二区成人片国内| 免费看片A级毛片免费看| 9420免费高清在线视频| 一级做α爱过程免费视频| 亚洲一区二区三区高清在线观看 | 亚洲国产美女精品久久久| 亚洲av永久无码精品秋霞电影影院| 国产伦精品一区二区三区免费下载| 一二三四影视在线看片免费| 日本免费中文字幕| 99麻豆久久久国产精品免费| www亚洲精品久久久乳| 亚洲avav天堂av在线网爱情| 亚洲伊人tv综合网色| 中文字幕精品亚洲无线码二区| 免费一级毛片在级播放| 日韩免费无码一区二区视频| a毛片基地免费全部视频| 99久久精品免费精品国产| 成人黄网站片免费视频| eeuss影院ss奇兵免费com| 特级毛片全部免费播放a一级| 亚洲一线产品二线产品| 亚洲中文字幕无码久久2020 | 久久这里只精品热免费99| 国产免费高清69式视频在线观看| 免费一级毛片在线播放放视频| 亚洲av日韩综合一区久热| 在线观看亚洲AV每日更新无码| 亚洲国产亚洲片在线观看播放| 亚洲成a人片毛片在线| 亚洲美女人黄网成人女| 亚洲天堂一区二区三区四区| 亚洲成人福利在线| 亚洲国产精品专区| 亚洲中文字幕一二三四区苍井空| 亚洲一区无码中文字幕乱码| 亚洲人成小说网站色|