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

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

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

    cuiyi's blog(崔毅 crazycy)

    記錄點滴 鑒往事之得失 以資于發展
    數據加載中……

    非常有意思的sql排錯

    1)  你看出區別在哪里了么? 結果會一樣么?
    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
    結果為什么不一樣呢?


    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)
    改進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
    改進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=?";
    假如沒有記錄
    DynaBean aBean 
    = CxcDataModule.getInstance().getRow(sql, new Object[]{reference4});
    如果直接用aBean.get("
    reference4") 出錯;
    錯誤的原因是
    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 分支
    如果有數據,這是對的
    如果沒有數據,直接出錯,因為有個假定有Integer值存在

    int value = JcDataModuleUtils.getJdbcTemplate().queryForInt(sql, new Object[]{reference4});
    出錯原因是假定一定會有一個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 閱讀(1687) 評論(0)  編輯  收藏 所屬分類: DBMS

    主站蜘蛛池模板: 国产免费av一区二区三区| 久久久亚洲AV波多野结衣| 久久久青草青青国产亚洲免观 | 亚洲天堂中文字幕在线| 亚洲AV无码成人专区片在线观看 | 亚洲精品一品区二品区三品区| 黄页免费视频播放在线播放| 免费女人18毛片a级毛片视频| 亚洲AV无码一区二区乱子伦| a级大片免费观看| 亚洲国产精品SSS在线观看AV| 亚洲国产精品精华液| 在线看片无码永久免费aⅴ| 男男gvh肉在线观看免费| 亚洲综合色在线观看亚洲| 东北美女野外bbwbbw免费| 亚洲AV综合色区无码另类小说| 99久久久国产精品免费牛牛四川| 国产小视频免费观看| 亚洲妇女水蜜桃av网网站| eeuss影院免费直达入口| 毛片免费在线观看网站| 亚洲综合久久1区2区3区| 日本阿v免费费视频完整版| 亚洲欧洲日产国产综合网| 一级特级女人18毛片免费视频| 国产亚洲精aa成人网站| 在线看片免费人成视久网| 亚洲AV男人的天堂在线观看| 亚洲狠狠爱综合影院婷婷| 国产亚洲女在线线精品| 亚洲情综合五月天| 久久WWW免费人成—看片| www.亚洲一区| 男男gay做爽爽免费视频| 亚洲午夜国产精品无码老牛影视 | 最近最新高清免费中文字幕| 亚洲日本va一区二区三区| 亚洲人色婷婷成人网站在线观看| 1000部啪啪毛片免费看| 深夜A级毛片视频免费|