﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-磨刀不误砍材工-文章分类-数据库</title><link>http://www.blogjava.net/weiwei/category/53459.html</link><description>技术路</description><language>zh-cn</language><lastBuildDate>Sat, 30 Mar 2013 14:55:42 GMT</lastBuildDate><pubDate>Sat, 30 Mar 2013 14:55:42 GMT</pubDate><ttl>60</ttl><item><title>非严谨不可为学</title><link>http://www.blogjava.net/weiwei/articles/327847.html</link><dc:creator>weiwei</dc:creator><author>weiwei</author><pubDate>Tue, 03 Aug 2010 09:32:00 GMT</pubDate><guid>http://www.blogjava.net/weiwei/articles/327847.html</guid><wfw:comment>http://www.blogjava.net/weiwei/comments/327847.html</wfw:comment><comments>http://www.blogjava.net/weiwei/articles/327847.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/weiwei/comments/commentRss/327847.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/weiwei/services/trackbacks/327847.html</trackback:ping><description><![CDATA[领导要我写个脚本，往表中添加一些数据，我想到了在pl/sql实现，但很少写pl/sql，又不熟悉，到网上找了一会，把SQL写成了这样：<br /><br /><div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">create</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">or</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 255);">replace</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">procedure</span><span style="color: rgb(0, 0, 0);"> updateXeDeptAll </span><span style="color: rgb(0, 0, 255);">is</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">cursor</span><span style="color: rgb(0, 0, 0);"> c1 </span><span style="color: rgb(0, 0, 255);">is</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">distinct</span><span style="color: rgb(0, 0, 0);"> d.c_dpt_cde<br />      </span><span style="color: rgb(0, 0, 255);">FROM</span><span style="color: rgb(0, 0, 0);"> T_DEPARTMENT d<br />     </span><span style="color: rgb(0, 0, 255);">WHERE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">NOT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">EXISTS</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);"><br />              </span><span style="color: rgb(0, 0, 255);">FROM</span><span style="color: rgb(0, 0, 0);"> claim_common_parameter c<br />             </span><span style="color: rgb(0, 0, 255);">WHERE</span><span style="color: rgb(0, 0, 0);"> c.value_code </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> d.c_dpt_cde<br />               </span><span style="color: rgb(128, 128, 128);">AND</span><span style="color: rgb(0, 0, 0);"> c.parameter_type </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">DEPTXE</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br />       </span><span style="color: rgb(128, 128, 128);">AND</span><span style="color: rgb(0, 0, 0);"> LENGTH(d.c_dpt_cde) </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">2</span><span style="color: rgb(0, 0, 0);"><br />       </span><span style="color: rgb(128, 128, 128);">AND</span><span style="color: rgb(0, 0, 0);"> d.c_dpt_cde </span><span style="color: rgb(0, 0, 255);">IS</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">NOT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">NULL</span><span style="color: rgb(0, 0, 0);">;<br />  v_dpt_cde T_DEPARTMENT.c_dpt_cde</span><span style="color: rgb(128, 128, 128);">%</span><span style="color: rgb(0, 0, 0);">type;<br />  str_sql   </span><span style="color: rgb(0, 0, 0); font-weight: bold;">varchar2</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(128, 0, 0); font-weight: bold;">500</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 0, 255);">begin</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">open</span><span style="color: rgb(0, 0, 0);"> c1;<br />  loop<br />    </span><span style="color: rgb(0, 0, 255);">EXIT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">WHEN</span><span style="color: rgb(0, 0, 0);"> c1</span><span style="color: rgb(128, 128, 128);">%</span><span style="color: rgb(0, 0, 0);">NOTFOUND;<br />    </span><span style="color: rgb(0, 0, 255);">fetch</span><span style="color: rgb(0, 0, 0);"> c1<br />      </span><span style="color: rgb(0, 0, 255);">into</span><span style="color: rgb(0, 0, 0);"> v_dpt_cde;<br />    str_sql :</span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">insert into claim_common_parameter<br />    (created_by,<br />     created_date,<br />     updated_by,<br />     updated_date,<br />     parameter_type,<br />     parameter_name,<br />     value_code,<br />     value_name,<br />     effective_date)<br />  values<br />    (</span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(255, 0, 0);">claim</span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(255, 0, 0);">,<br />     sysdate,<br />     </span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(255, 0, 0);">claim</span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(255, 0, 0);">,<br />     sysdate,<br />     </span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(255, 0, 0);">DEPTXE</span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(255, 0, 0);">,<br />     </span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(255, 0, 0);">机构小额</span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(255, 0, 0);">,<br />     </span><span style="color: rgb(255, 0, 0);">'''</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">||</span><span style="color: rgb(0, 0, 0);"> v_dpt_cde </span><span style="color: rgb(128, 128, 128);">||</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'''</span><span style="color: rgb(255, 0, 0);">,<br />     </span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(255, 0, 0);">1</span><span style="color: rgb(255, 0, 0);">''</span><span style="color: rgb(255, 0, 0);">,<br />     sysdate)</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">;<br />    dbms_output.put_line(v_dpt_cde);<br />  <br />    </span><span style="color: rgb(0, 0, 255);">execute</span><span style="color: rgb(0, 0, 0);"> immediate str_sql; </span><span style="color: rgb(0, 128, 128);">--</span><span style="color: rgb(0, 128, 128);">动态执行DDL语句</span><span style="color: rgb(0, 128, 128);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">commit</span><span style="color: rgb(0, 0, 0);">;<br />  </span><span style="color: rgb(0, 0, 255);">end</span><span style="color: rgb(0, 0, 0);"> loop;<br />  </span><span style="color: rgb(0, 0, 255);">close</span><span style="color: rgb(0, 0, 0);"> c1;<br /></span><span style="color: rgb(0, 0, 255);">end</span><span style="color: rgb(0, 0, 0);"> updateXeDeptAll;</span></div><br />我这个愚蠢的家伙就直接把它交给了领导。<br />知识少，是多么的可怕!<br /><br />DML在PL/SQL中根本就不需要动态sql来执行。<br /><br />上面的sql是完全可以写成这样的：<br /><div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">create</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">or</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 255);">replace</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">procedure</span><span style="color: rgb(0, 0, 0);"> updateXeDeptAll </span><span style="color: rgb(0, 0, 255);">is</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">cursor</span><span style="color: rgb(0, 0, 0);"> c1 </span><span style="color: rgb(0, 0, 255);">is</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">distinct</span><span style="color: rgb(0, 0, 0);"> d.c_dpt_cde<br />      </span><span style="color: rgb(0, 0, 255);">FROM</span><span style="color: rgb(0, 0, 0);"> T_DEPARTMENT d<br />     </span><span style="color: rgb(0, 0, 255);">WHERE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">NOT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">EXISTS</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);"><br />              </span><span style="color: rgb(0, 0, 255);">FROM</span><span style="color: rgb(0, 0, 0);"> claim_common_parameter c<br />             </span><span style="color: rgb(0, 0, 255);">WHERE</span><span style="color: rgb(0, 0, 0);"> c.value_code </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> d.c_dpt_cde<br />               </span><span style="color: rgb(128, 128, 128);">AND</span><span style="color: rgb(0, 0, 0);"> c.parameter_type </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">DEPTXE</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br />       </span><span style="color: rgb(128, 128, 128);">AND</span><span style="color: rgb(0, 0, 0);"> LENGTH(d.c_dpt_cde) </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">2</span><span style="color: rgb(0, 0, 0);"><br />       </span><span style="color: rgb(128, 128, 128);">AND</span><span style="color: rgb(0, 0, 0);"> d.c_dpt_cde </span><span style="color: rgb(0, 0, 255);">IS</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">NOT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">NULL</span><span style="color: rgb(0, 0, 0);">;<br />  v_dpt_cde T_DEPARTMENT.c_dpt_cde</span><span style="color: rgb(128, 128, 128);">%</span><span style="color: rgb(0, 0, 0);">type;<br />  <br /></span><span style="color: rgb(0, 0, 255);">begin</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 255);">open</span><span style="color: rgb(0, 0, 0);"> c1;<br />  loop<br />    </span><span style="color: rgb(0, 0, 255);">EXIT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">WHEN</span><span style="color: rgb(0, 0, 0);"> c1</span><span style="color: rgb(128, 128, 128);">%</span><span style="color: rgb(0, 0, 0);">NOTFOUND;<br />    </span><span style="color: rgb(0, 0, 255);">fetch</span><span style="color: rgb(0, 0, 0);"> c1<br />      </span><span style="color: rgb(0, 0, 255);">into</span><span style="color: rgb(0, 0, 0);"> v_dpt_cde;<br />   </span><span style="color: rgb(0, 0, 255);">insert</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">into</span><span style="color: rgb(0, 0, 0);"> claim_common_parameter<br />    (created_by,<br />     created_date,<br />     updated_by,<br />     updated_date,<br />     parameter_type,<br />     parameter_name,<br />     value_code,<br />     value_name,<br />     effective_date)<br />  </span><span style="color: rgb(0, 0, 255);">values</span><span style="color: rgb(0, 0, 0);"><br />    (</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">claim</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,<br />     sysdate,<br />     </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">claim</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,<br />     sysdate,<br />     </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">DEPTXE</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,<br />     </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">机构小额</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,<br />     v_dpt_cde,<br />     </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">1</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,<br />     sysdate)</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">;   <br />    commit;<br />  end loop;<br />  close c1;<br />end updateXeDeptAll;</span></div><br /><br />而领导后来给我更正的sql语句更让我惭愧：<br /><div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">INSERT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">INTO</span><span style="color: rgb(0, 0, 0);"> claim_common_parameter<br />            (created_by, created_date, updated_by, updated_date,<br />             parameter_type, parameter_name, value_code, value_name,<br />             effective_date)<br />   </span><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">claim</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, SYSDATE, </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">claim</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, SYSDATE, </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">DEPTXE</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">机构小额</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,<br />          d.c_dpt_cde, </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">1</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">, SYSDATE<br />     </span><span style="color: rgb(0, 0, 255);">FROM</span><span style="color: rgb(0, 0, 0);"> T_DEPARTMENT d<br />    </span><span style="color: rgb(0, 0, 255);">WHERE</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">NOT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 128, 128);">EXISTS</span><span style="color: rgb(0, 0, 0);"> (<br />              </span><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 255);">FROM</span><span style="color: rgb(0, 0, 0);"> claim_common_parameter c<br />               </span><span style="color: rgb(0, 0, 255);">WHERE</span><span style="color: rgb(0, 0, 0);"> c.value_code </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> d.c_dpt_cde<br />                     </span><span style="color: rgb(128, 128, 128);">AND</span><span style="color: rgb(0, 0, 0);"> c.parameter_type </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(255, 0, 0);">DEPTXE</span><span style="color: rgb(255, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">)<br />      </span><span style="color: rgb(128, 128, 128);">AND</span><span style="color: rgb(0, 0, 0);"> LENGTH (d.c_dpt_cde) </span><span style="color: rgb(128, 128, 128);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(128, 0, 0); font-weight: bold;">2</span></div><br />学习，真不是个随便的事情，非严谨不可为学呀!<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><img src ="http://www.blogjava.net/weiwei/aggbug/327847.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/weiwei/" target="_blank">weiwei</a> 2010-08-03 17:32 <a href="http://www.blogjava.net/weiwei/articles/327847.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转-使用iBatis中报 java.sql.SQLException: 无效的列类型异常</title><link>http://www.blogjava.net/weiwei/articles/327214.html</link><dc:creator>weiwei</dc:creator><author>weiwei</author><pubDate>Tue, 27 Jul 2010 06:05:00 GMT</pubDate><guid>http://www.blogjava.net/weiwei/articles/327214.html</guid><wfw:comment>http://www.blogjava.net/weiwei/comments/327214.html</wfw:comment><comments>http://www.blogjava.net/weiwei/articles/327214.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/weiwei/comments/commentRss/327214.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/weiwei/services/trackbacks/327214.html</trackback:ping><description><![CDATA[使用iBatis中报 java.sql.SQLException: 无效的列类型异常<br /><br />原文网址：http://www.fengfly.com/plus/view-168285-1.html<br /><br /><br /><br />1. <!--Content表 插入应的记录到数据库中 --><br />2. &lt; insert id = "insertContent"   parameterClass = "com.unmi.content" &gt; <br />3.      INSERT INTO PERSON(ID,NAME,SERVICEID) VALUES(#id#,#name#,#serviceid#) <br />4. <br />//三个子段允许为空(null）<br />1. SqlMapClient sqlMap = SqlMapConfig.getSqlMapInstance();  // as coded above <br />2. Content content= new Content( 1 ); <br />3. content.setName( "Unmi" ); <br />4. // content.setServiceId("123456"); // 注意该行被注释，serviceid属性为NULL <br />5. sqlMap.insert( "content" , content); <br />部分异常信息：<br />--- The error occurred in com/unmi/content.xml.  <br />--- The error occurred while applying a parameter map.  <br />--- Check the insertPerson-InlineParameterMap.  <br />--- Check the parameter mapping for the 'serviceid' property.  <br />--- Cause: java.sql.SQLException : 无效的列类型 <br />Caused by: java.sql.SQLException : 无效的列类型<br />     at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate( GeneralStatement.java:91 ) <br />     at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert( SqlMapExecutorDelegate.java:442 ) <br />     at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert( SqlMapSessionImpl.java:81 )<br />     at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.insert( SqlMapClientImpl.java:58 )<br />     at com.unmi.Client.main( Client.java:33 )<br />Caused by: java.sql.SQLException : 无效的列类型<br />//解决方案：<br />只要去掉 content.setServiceId("123456"); 前的注释，让content的三个字段都不为NULL，才能成功向数据库中插入记录。其实content表并没有任何约束，却是iBatis在此拦截下来，实是多此一举。那如果我确实让某个字段是NULL值，该怎么做呢？您只要修改一下映射文件中预置的SQL语句就行了，告诉iBatis当该字段出现NULL 值该用什么值来替代，连接Oracle即使是要求某字段传入NULL值时就是插入NULL值也必须要你累述一遍，好讨厌的事情。<br /> <br /> <br /><br />1. <!-- 插入一条Person对应的记录到数据库中 -->   <br />2. &lt; insert id = "content" parameterClass = "com.unmi.content" &gt;  <br />3.     INSERT INTO PERSON(ID,NAME,PASSWD) VALUES(#id#,#name#,#SERVICEID:VARCHAR:NULL#)   <br />4. <br />支持的类型在 java.sql.Types 中列示出来了，我一开始还把上面的 VARCHAR 错写成了 VARCHAR2。再比如果你想传入的 id 为NULL时替换为 0, 你就可以写成 #id:INTEGER:0#。<br /><br />原因是 iBatis 是根据参数的当前值的类型(而不是类属性) 来决定对于这个 PrepairedStatement 设置参数是应该调用哪一个版本的 setXxx() 方法(是 String 就调用，setString() ，是 int 就调用 setInt() 等)。而如果参数值为 null，iBatis 便不知道调用哪个 setXxx() 方法，于是在 Oracle 的驱动下就笼统的调用 setNull() 方法，然而 Oracle 在对字符串类型字段使用 setNull() 却是有问题的。因为在配置中就必须指明当前字段的类型，如 #SERVICEID:VARCHAR:NULL#，当 iBatis 在碰到参数为 null 难以决断时，但见到这里的 VARCHAR 选项，它也知道应该用 setString() 方法来给 PrepairedStatement 赋值。至于其中的 NULL，不过是指定参数为 null 时的默认值，显然，写成 #SERVICEID:VARCHAR# 就行了，后面的 NULL 是多余的。<br />不知你注意到没有，我们上面的insert标记配置了属性是 parameterClass, 那如果配置的是 parameterMap 该如何解决因字段为NULL值的问题呢？这就要求我们在配置 parameterMap标记中可能出现NULL值的参数一定要指定相应的 jdbcType属性就行。只要不指定nullValue属性就表示在该表这段中直接记下NULL值。<br />view source <br /> <br />print ? <br />01. &lt; parameterMap   id = "insert-person-paraMap" class = "com.unmi.content" &gt; <br />02. &lt; parameter property = "id" /&gt; <br />03. &lt; parameter property = "name" /&gt; <br />04. &lt; parameter property = "SERVICEID"   jdbcType = "VARCHAR" /&gt; <br />05. <br />06. <!-- 插入一条Person对应的记录到数据库中 --><br />07. &lt; insert id = "insertPerson"   parameterMap = "insert-person-paraMap" &gt; <br />08.      INSERT INTO CONTENT(ID,NAME,SERVICEID) VALUES(?,?,?) <br />09. <br /><br /><img src ="http://www.blogjava.net/weiwei/aggbug/327214.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/weiwei/" target="_blank">weiwei</a> 2010-07-27 14:05 <a href="http://www.blogjava.net/weiwei/articles/327214.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle组合分区</title><link>http://www.blogjava.net/weiwei/articles/307406.html</link><dc:creator>weiwei</dc:creator><author>weiwei</author><pubDate>Sat, 26 Dec 2009 16:46:00 GMT</pubDate><guid>http://www.blogjava.net/weiwei/articles/307406.html</guid><wfw:comment>http://www.blogjava.net/weiwei/comments/307406.html</wfw:comment><comments>http://www.blogjava.net/weiwei/articles/307406.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/weiwei/comments/commentRss/307406.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/weiwei/services/trackbacks/307406.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1、分区表创建：    对轨迹表T_TRACK进行组合分区，首选按轨迹时间T_TRACK_TM进行区间分区，然后，再根据公司代码C_COMP_CDE进行列表分区。create table T_TRACK  (   N_TRACK_ID           NUMBER(20)                      not null,     C_COMP_CDE           VARCH...&nbsp;&nbsp;<a href='http://www.blogjava.net/weiwei/articles/307406.html'>阅读全文</a><img src ="http://www.blogjava.net/weiwei/aggbug/307406.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/weiwei/" target="_blank">weiwei</a> 2009-12-27 00:46 <a href="http://www.blogjava.net/weiwei/articles/307406.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>