<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">博客园_live in 1984</title><subtitle type="text">Freedom is not free</subtitle><id>http://feed.cnblogs.com/blog/u/52316/rss</id><updated>2012-05-21T07:30:56Z</updated><author><name>catch22</name><uri>http://www.cnblogs.com/millen/</uri></author><generator>feed.cnblogs.com</generator><link rel="alternate" type="text/html" href="http://www.cnblogs.com/millen/"/><link rel="self" type="application/atom+xml" href="http://feed.cnblogs.com/blog/u/52316/rss"/><entry><id>http://www.cnblogs.com/millen/archive/2012/01/04/2311786.html</id><title type="text">在 DB2 9.7 for Linux, UNIX, and Windows 上运行 Oracle 应用程序(转)</title><summary type="text">转自:http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/ DB2 9.7 添加了 Oracle 兼容性特性要使为某个 RDBMS 编写的应用程序运行在另一个上并且基本上没有变化，很多部分要依序出现。不同的锁机制、数据类型、SQL、服务器上的过程语言、甚至应用程序自身使用的客户机接口都需要保持一致，不仅在语法上而且在语义上。DB2 中已经采取了所有这些步骤。变化是例外，而不是规则（IBM 可以迅速访问需要的应用程序变更）。表 1 提供了对常用特性的快速概览：表 1. 常用特性</summary><published>2012-01-04T03:27:00Z</published><updated>2012-01-04T03:27:00Z</updated><author><name>catch22</name><uri>http://www.cnblogs.com/millen/</uri></author><link rel="alternate" href="http://www.cnblogs.com/millen/archive/2012/01/04/2311786.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/millen/archive/2012/01/04/2311786.html"/><content type="html">&lt;p&gt;转自:&lt;a href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/"&gt;http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"&gt;&lt;span style="text-align: left" class="Apple-style-span"&gt; &lt;/p&gt;&lt;p&gt;&lt;a name="N1009F"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;DB2 9.7 添加了 Oracle 兼容性特性&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;要使为某个 RDBMS 编写的应用程序运行在另一个上并且基本上没有变化，很多部分要依序出现。不同的锁机制、数据类型、SQL、服务器上的过程语言、甚至应用程序自身使用的客户机接口都需要保持一致，不仅在语法上而且在语义上。&lt;/p&gt;&lt;p&gt;DB2 中已经采取了所有这些步骤。变化是例外，而不是规则（IBM 可以迅速访问需要的应用程序变更）。表 1 提供了对常用特性的快速概览：&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="table1"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;表 1. 常用特性&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;table style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; width: 708px; border-top-width: 0px; font-size: 0.8em; border-right: rgb(204,204,204) 1px solid" class="ibm-data-table" border="0" cellspacing="0" summary="Illustration of Oracle compatibility for DB2" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial"&gt;Oracle&lt;/th&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial"&gt;--&amp;gt;&lt;/th&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial"&gt;DB2&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;并发性控制&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;--&amp;gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;本机支持&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;SQL 专用语言&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;--&amp;gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;本机支持&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;PL/SQL&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;--&amp;gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;本机支持&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;PL/SQL 包&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;--&amp;gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;本机支持&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;内置包&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;--&amp;gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;本机支持&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;带有扩展的 JDBC 客户机&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;--&amp;gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;本机支持&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;SQL*Plus 脚本&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;--&amp;gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;本机支持&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;通过 DB2 9.7，就不再需要为应用程序确定端口了。只要&lt;em&gt;启用&lt;/em&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;应用程序即可。在使用打包应用程序的时候，甚至可能为 DB2 和 Oracle 共享&lt;em&gt;一个源&lt;/em&gt;。&lt;/p&gt;&lt;p&gt;换句话说，在 DB2 中支持 Oracle 应用程序不比使为 HP-UX 编写的 C 程序运行在 AIX 上复杂多少。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="code-hd"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;并发性控制&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;过去，Oracle 与 DB2 之间最突出的不同一直是并发性控制方法不同。比较易记的说法是：&amp;#8220;读取器不会阻止编写器且编写器不会阻止读取器&amp;#8221;。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="table2"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;表 2. Oracle 并发性行为&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;table style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; width: 708px; border-top-width: 0px; font-size: 0.8em; border-right: rgb(204,204,204) 1px solid" class="ibm-data-table" border="0" cellspacing="0" summary="Oracle concurrency behavior" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;挂起事务&lt;/th&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;行为&lt;/th&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;新事务&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;不会阻止&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;不会阻止&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;不会阻止&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;阻止&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;不用深入到隔离级别，现在足以说明使用 Oracle 默认的&lt;em&gt;语句级隔离&lt;/em&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;的绝大多数应用程序在使用 DB2 默认的&lt;em&gt;游标稳定性（Cursor Stability，CS）&lt;/em&gt;时也能很好的工作。&lt;/p&gt;&lt;p&gt;但是，传统上，CS 已经实现了，所以编写器组织读取器并且，在某些情况下，读取器可以组织编写器。原因是传统上，在 CS 隔离级别下的事务将 &amp;#8220;等待挂起的并发事务的变更的结果&amp;#8221;。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="table3"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;表 3. 传统 DB2 的 CS 并发性行为&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;table style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; width: 708px; border-top-width: 0px; font-size: 0.8em; border-right: rgb(204,204,204) 1px solid" class="ibm-data-table" border="0" cellspacing="0" summary="Traditional DB2 concurrency behavior" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;挂起事务&lt;/th&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;行为&lt;/th&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;新事务&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;不会阻止&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;很少阻止&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;阻止&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;阻止&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;最终发现在 CS 隔离下运行的事务在遇到变更的行时&lt;em&gt;等待结果&lt;/em&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;不是出于语义原因。另一个比较满意的行为是读取变更行的&lt;em&gt;当前提交&lt;/em&gt;版本。&lt;/p&gt;&lt;p&gt;此行为已经在 DB2 9.7 中实现。具体方法是 DB2 只需从日志中获取锁定行的当前提交版本。在大部分一般情况下，该行仍位于日志缓冲区，因为尚未提交变更。但是只要该行已经编写出来&lt;em&gt;并且&lt;/em&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;也已经在日志缓冲区中重写，DB2 就能准确知道在哪里找到它，因此单次 IO 就可以将需要的版本带入缓冲区。&lt;/p&gt;&lt;p&gt;假设（请参见图 2），一个用户更新员工表中的名字。在该用户提交变更之前，另一个用户在浏览这个表。过去，第二个用户不得不等待第一个用户提交或回滚。借助于&lt;em&gt;读取当前提交数据&lt;/em&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;特性，第二个用户的浏览操作只需从不包含第一个用户变更的日志缓冲区获取该行的版本即可。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="fig2"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;图 2. 编写器不阻止读取器&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;img style="padding-bottom: 0.7em; border-right-width: 0px; padding-left: 5px; padding-right: 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0.3em" alt="编写器不阻止读取器" src="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/concurrency.gif" width="572" height="233" /&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;注意一下这个行为：&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;没有引入新对象，比如回滚段&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;编写日志之后，编写器就没有性能开销了&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;不会引起任何类似 &amp;#8220;快照过旧&amp;#8221; 的情况，因为几乎不可能出现所需的日志文件已经被归档（而事务仍然打开！）在这种情况下，DB2 将会后退并等待锁消失&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;除了这些变更，其他避免锁定技术也已经被引入 DB2 了，以便清除在 CS 隔离下持有锁读取器。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="table4"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;表 4. 新 DB2 的 CS 并发性行为&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;table style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; width: 708px; border-top-width: 0px; font-size: 0.8em; border-right: rgb(204,204,204) 1px solid" class="ibm-data-table" border="0" cellspacing="0" summary="New DB2 concurrency behavior" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;挂起事务&lt;/th&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;行为&lt;/th&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;新事务&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;不会阻止&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;strong&gt;不会阻止&lt;/strong&gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;strong&gt;不会阻止&lt;/strong&gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;读取器&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;阻止&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;编写器&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;如您所见，DB2 的并发性行为现在与 Oracle 的一样了。事实上，新创建的 DB2 数据库会默认表现出这种行为。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N1025F"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;新数据类型&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;每个数据库的核心都是其数据。错配的类型或这些类型错配的语义可能会严重影响在另一个 RDBMS 中支持一个应用程序的能力。因此，要允许 Oracle 应用程序在 DB2 上运行，很重要的一点是要支持其非标准的基本类型，比如字符串、日期和数字。除了调整这些基本类型之外，Oracle PL/SQL 中常用的其他一些更复杂的类型也已经添加到了 DB2 9.7 中。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="table5"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;表 5. 新 DB2 数据类型&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;table style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; width: 708px; border-top-width: 0px; font-size: 0.8em; border-right: rgb(204,204,204) 1px solid" class="ibm-data-table" border="0" cellspacing="0" summary="New DB2 data types" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;数据类型&lt;/th&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;说明&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;NUMBER&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;在 DECFLOAT（通过 Power6 硬件加速）和 DECIMAL 基础上添加了对 NUMBER 和 NUMBER(p [, s]) 的支持。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;VARCHAR2&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;VARCHAR2-类型的行为包括被解释为 NULL 的空字符串和对结尾空白敏感的纠正。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;Oracle DATE&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;Oracle 中数据库的 DATE 模式除了日历日期还包括 TIME 组件&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;TIMESTAMP(n)&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;秒的小数部分的范围可以在 0（日期 + 时间）到 12（微微妙）之间选择。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;BOOLEAN&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;此类型可以用在过程逻辑、变量和例程的参数中。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;VARRAY&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;过程中的 ARRAY 支持已经扩展到支持 VARRAY 风格的方法和语法。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;INDEX BY&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;除了常规数组，DB2 还支持联合数组。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;ROW TYPE&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;此复合类型可以用在变量和参数中，并且作为元素用在数组和联合数组中。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;Ref Cursor TYPE&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;游标可以指定给变量或者使用参数到处传递。&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N102D2"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;隐式的类型转换和类型解析&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;#8220;如果走路像鸭子，讲话像鸭子，那么它一定是鸭子。&amp;#8221;&lt;/p&gt;&lt;p&gt;这是很多新兴语言，比如 PHP 和 Ruby，的原则。每个字面值都是一个字符串，然后根据上下文用作另一个类型。过去，秉承了 SQL 标准并遵循了类型错配很可能预示着编码错误的原则，DB2 一直遵守着强硬的类型规则，其中字符串和数字不能比较，除非某一个经过显式地类型转换，转换成另一个。&lt;/p&gt;&lt;p&gt;不幸地是，Oracle 应用程序在其 SQL 中使用了较弱的类型规则，过去该应用程序可能不能在 DB2 上编译。在 DB2 9.7 中，添加了隐式的类型转换（较弱的类型规则）。也就是，可以以非常灵活的方式比较、赋值和操作字符串和数字。&lt;/p&gt;&lt;p&gt;此外，可以在很多地方使用无类型的 NULL，而且几乎可以在任何地方使用无类型的参数标记，这要多亏了&lt;em&gt;递延准备&lt;/em&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;功能。也就是说，在发现其第一个实际值之前，DB2 不用再解析参数标记类型。&lt;/p&gt;&lt;p&gt;为了完成隐式类型转换，DB2 还支持默认的过程参数以及通过名称关联 argument 和 parameter。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N102EA"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;DB2 中扩展的内置函数库&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;所有 RDBMs 都提供了函数库来操作数据。问题时没有哪两个数据库对这些函数使用同样的名称，尽管最终其功能都非常类似。&lt;/p&gt;&lt;p&gt;除了其自己传统的函数集，DB2 现在支持与 Oracle 兼容的库。以下列表提供了快速概览，当然不可能是全部的：&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;strong&gt;转换和类型转换函数&lt;/strong&gt; &lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 1em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;TO_DATE&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;TO_CHAR&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;TO_CLOB&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;TO_NUMBER&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;TO_TIMESTAMP&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;这些函数中的每一个都支持丰富的兼容格式字符串集。&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;strong&gt;日期算法&lt;/strong&gt; &lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 1em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;EXTRACT&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;ADD_MONTHS&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;MONTHS_BETWEEN&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;NEXT_DAY&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;加号 (+) 添加天的分数&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;strong&gt;字符串操作&lt;/strong&gt; &lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 1em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;LPAD&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;RPAD&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;INSTR&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;INITCAP&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;扩展到&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;SUBSTR&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;strong&gt;其他&lt;/strong&gt; &lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 1em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;NVL&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;DECODE&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;LEAST&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;GREATEST&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;BITAND&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;两种产品间支持函数的重合部分不断增加表明在 DB2 上对 Oracle 应用程序开箱即用的支持得到了极大改进。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N103A6"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;Oracle SQL 专用语言支持&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;到目前为止，本文介绍了并发性、数据类型、类型规则和函数。但是 Oracle 和 DB2 之间的不同不止于此。SQL 专用语言的框架、其关键字和语义在某些方面是不同的。而且每个产品都会有一些特性是另一个不支持的。在这些特性流行时，它们限制了为两种产品提供通用 SQL 的能力。在大大小小的语言不同中，表 6 列举了一些重点：&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="table6"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;表 6. 新的 SQL 支持&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;table style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; width: 708px; border-top-width: 0px; font-size: 0.8em; border-right: rgb(204,204,204) 1px solid" class="ibm-data-table" border="0" cellspacing="0" summary="New SQL support" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;特性&lt;/th&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;说明&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;CONNECT BY&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;递归&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;到目前为止，DB2 已经支持 ANSI SQL 递归了。现在，已经可以添加 Oracle-样式的&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;CONNECT BY&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;了，包括各种函数和伪列，比如&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;LEVEL&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;和&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;CONNECT_BY_PATH&lt;/code&gt;。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;(+) 连接语法&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;这种语法实际上甚至连 Oracle 都不提倡了，但是有很多应用程序和开发人员仍在使用这种形式的&lt;code style="font-family: monospace; font-size: small !important"&gt;OUTER JOIN&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;语法。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;DUAL&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;表&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;单行、单列表在 Oracle 应用程序中被广泛地用作哑表。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;ROWNUM&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;伪列&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;该伪列通常用于限制返回的行数并在结果集中枚举行。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;ROWID&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;伪列&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;Rowid 用于快速获取之前根据其物理地址获取的行。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;MINUS&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;SQL 操作符&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;在 Oracle 中，用&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;MINUS&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;而不是&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;EXCEPT&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;从另一个结果集中减去一个结果集。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;SELECT INTO FOR UPDATE&lt;/code&gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;FOR UPDATE&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;构建在&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;SELECT INTO&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;之上，允许从 DB2 中抽取一行，以便稍后在不使用游标的情况下修改它。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;PUBLIC SYNONYM&lt;/code&gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;公共同义字是一个没有模式名的别名。DB2 支持表对象、序列和 PL/SQL 包的公共同义字。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;CREATE TEMPORARY TABLE&lt;/code&gt;&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;除了声明全局临时表之外，DB2 还支持创建全局临时表。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;TRUNCATE&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;表语句&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;此语句无需激活触发器即可快速删除整个表的内容。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;不严格的名称解析&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;DB2 9.7 不再需要命名&lt;em&gt;内联视图&lt;/em&gt;。另外，可以更轻松地从集合操作符（比如 UNION）继承列名称。&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;p&gt;到这里，对 DB2 变化的概述就结束了，这是因为有了这些变化，向 DB2 数据库提交 SQL 的 Oracle 应用程序才能保持几乎不变的运行。但是，有很多应用程序的主要部分在服务器自身上执行。Oracle 应用程序服务器端的语言选择是 PL/SQL。没有对 PL/SQL 的支持，就不要声称可以提供兼容性。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N1046E"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;DB2 对 PL/SQL 的支持&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;通常，应用程序从一个产品定位到另一个产品时，SQL 和过程语言也从一种 SQL 专用语言转换成另一种。这会造成几个问题：&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;由于源和目标语言之间自动的不顺畅的错配导致得到的转换后代码让人费解。&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;应用程序开发人员不熟悉目标 SQL 专用语言。这使得调试转换后的代码很困难。由于缺乏技能，后续维护会成为一个难题。&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;在处理打包应用程序时，需要为该应用程序的每个新版本重复转换。&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;最后，结果只是类似，从理论上说，它要比原始程序运行得慢一些。&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;为了避免这些问题，DB2 9.7 包含了&lt;strong&gt;本机 PL/SQL&lt;/strong&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;支持。这意味着什么呢？&lt;/p&gt;&lt;p&gt;如您在图 3 中看到的，DB2 引擎现在包括一个 PL/SQL 编译器以及一个 SQL PL 编译器。这两个编译器为 DB2 的 SQL Unified Runtime Engined 生成虚拟机代码。很重要的一点是要注意到监控和开发工具，比如 Optim Development Studio，是在运行时引擎级别被挂靠到 DB2 的。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="N10491"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;图 3. PL/SQL 编译器支持&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;img style="padding-bottom: 0.7em; border-right-width: 0px; padding-left: 5px; padding-right: 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0.3em" alt="Optim Development Studio 中的 PL/SQL 编译器支持" src="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/plsqlcompiler.gif" width="450" height="314" /&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;将 PL/SQL 作为一类过程语言集成到 DB2 中有以下几个影响：&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;没有转换。源码在模式目录中保持原样。&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;开发人员可以继续使用熟悉的语言工作。无需将逻辑移动到 DB2 的专用语言，即使新逻辑是用 SQL PL 编写的。使用不同语言的例程可以彼此调用。&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;打包应用程序厂商可以针对 Oracle 和 DB2 使用一个源代码。&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;PL/SQL 和 SQL PL 都为 DB2 的 SQL Unified Runtime Engine 生成同样的虚拟机代码。因此，在设计上，PL/SQL 和 SQL PL 执行的速度一样。&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;因为调试器基础设施直接挂钩在 SQL Unified Runtime Engine 中，所以 PL/SQL 很自然地得到 Optim Development Studio 的支持。&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a style="color: rgb(76,110,148)" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#fig4"&gt;图 4&lt;/a&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;说明了 PL/SQL 调试会话。该调试器支持标准特性，比如跳入、跳过和断点。此外，它允许用户在程序运行时，改变局部 PL/SQL 变量。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="fig4"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;图 4. DB2 中支持的 PL/SQL 调试器&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;img style="padding-bottom: 0.7em; border-right-width: 0px; padding-left: 5px; padding-right: 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0.3em" alt="DB2 中支持的 PL/SQL 调试器" src="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/plsqldebugger.gif" width="529" height="605" /&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N104C8"&gt;&lt;span style="font-size: 1.2em; font-weight: bold" class="smalltitle"&gt;PL/SQL 语法细则&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;那么，PL/SQL 支持究竟意味着什么呢？首先，有一个核心语法支持。DB2 支持所有 PL/SQL 的通用构造，比如：&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;if then else&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;while 循环&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;:= 赋值&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;局部变量和常量&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;#PRAGMA EXCEPTION 和异常处理&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;各种形式的 for 循环（范围、游标和查询）&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;%TYPE 和 %ROWTYPE 将变量和参数锚定到其他对象&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;#PRAGMA AUTONOMOUS 事务，允许在私有事务中执行过程&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a name="N104EC"&gt;&lt;span style="font-size: 1.2em; font-weight: bold" class="smalltitle"&gt;PL/SQL 对象支持&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;PL/SQL 可以用在各种不同的支持过程逻辑的对象中：&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;标量函数&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;在每行触发器之前&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;在每行触发器之后&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;过程&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;匿名块&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;PL/SQL 包&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a name="N1050A"&gt;&lt;span style="font-size: 1.2em; font-weight: bold" class="smalltitle"&gt;PL/SQL 包支持&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Oracle 应用程序中的大部分 PL/SQL 都包含在所谓的&lt;em&gt;包&lt;/em&gt;中。PL/SQL 包 &amp;#8212; 不要与 DB2 包弄混 &amp;#8212; 是单个对象的集合，能够区分那些外部可访问的对象和哪些仅用于包内部的帮助函数。包的 ANSI SQL 等价物是&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;em&gt;模块&lt;/em&gt;。DB2 现在支持 ANSI SQL 模块以及 PL/SQL 包。特别是，提供了以下功能：&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;CREATE [OR REPLACE] PACKAGE，定义外部访问例程的原型。它还定义了所有外部可访问的、非过程对象，比如变量和类型。&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;CREATE [OR REPLACE] PACKAGE BODY，它实现了所有私有和公共例程以及所有其他私有对象。&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;在包或包体内部，可以定义以下对象： &lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 1em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;变量和常量&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;数据类型&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;异常&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;标量函数&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;过程&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;游标&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;包初始化&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;包的公共同义字&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N10543"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;DB2 提供了通用内置包&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;某些 Oracle 应用程序利用 RDBMS 提供的包。特别是，提供报告、电子邮件或交叉连接通信的库非常流行。为了便于 DB2 支持这些应用程序，DB2 提供了表 7 中列出的包：&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="table7"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;表 7. DB2 提供的内置包&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;table style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; width: 708px; border-top-width: 0px; font-size: 0.8em; border-right: rgb(204,204,204) 1px solid" class="ibm-data-table" border="0" cellspacing="0" summary="Built-in packages supported by DB2" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;包&lt;/th&gt;&lt;th style="background-image: url(http://1.www.s81c.com/i/v16/t/text-tabs-bg.gif); text-align: left; padding-bottom: 8px; background-color: rgb(247,248,252); padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px; background-origin: initial; background-clip: initial" scope="col"&gt;说明&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;DBMS_OUTPUT&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;提供基本报告功能，可以通过命令行开关。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;UTL_FILE&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;允许处理 DB2 服务器上的文件的模块。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;DBMS_SQL&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;除了现有&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;EXECUTE&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;和&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;EXECUTE IMMEDIATE&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;语句，该包提供了用于执行动态 SQL 的 SQL API。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;UTL_MAIL&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;该模块允许从 SQL 发送电子邮件通知。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;UTL_SMTP&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;低级别的 API，类似于提供 SMTP 集成的 UTL_MAIL。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;DBMS_ALERT&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;该包使用时允许不同的会话之间彼此发信号。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;DBMS_PIPE&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;该模块允许会话彼此发送数据。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;DBMS_JOB&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;提供与 DB2 的任务调度器集成的可兼容 API。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;DBMS_LOB&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;Oracle API，用于 LOB 处理，回应 DB2 的内置 LOB 函数。&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;DBMS_UTILITY&lt;/td&gt;&lt;td style="padding-bottom: 8px; padding-left: 5px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; vertical-align: top; border-top: rgb(204,204,204) 1px solid; padding-top: 8px"&gt;应用程序中使用的各种过程的集合。&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N105C7"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;特定于 Oracle 的 JDBC 扩展&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;JDBC 是标准 Java 客户机接口。但是为了支持特定的非标准数据类型，已经向 Oracle 的 JDBC 驱动程序中添加了扩展。&lt;/p&gt;&lt;p&gt;要将基于 Java 技术的应用程序的兼容性提到最高，DB2 9.7 JDBC 驱动程序提供了对通过引用游标和 VARRAY 参数调用过程的支持（当然还提供了其他一些特性）。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N105D3"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;使用 CLPPlus 的 SQL*Plus 脚本支持&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;很多时候，DDL 脚本甚至报告都是使用 SQL*Plus 命令行处理器编写的。要使迁移这些脚本以及编写它们的开发人员的技能更加容易，DB2 提供了兼容 SQL*Plus 的命令行处理器，叫做 CLPPlus。该工具提供了以下功能：&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;兼容 SQL*Plus 的命令选项&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;变量替换&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;列格式化&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;报告功能&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;控制变量&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="N105F0"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;图 5. 兼容 SQL*Plus 的 CLPLus 工具&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;img style="padding-bottom: 0.7em; border-right-width: 0px; padding-left: 5px; padding-right: 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0.3em" alt="兼容 SQL*Plus 的 CLPLus 工具" src="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/clpplus.jpg" width="572" height="263" /&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N105FD"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;在 DB2 中使用就像拖放操作那么简单&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;既然 DB2 已经对 PL/SQL 进行了调整，使其尽可能保持与 Oracle SQL 一致，现在就无需使用复杂的迁移工具箱了。只要使用 IBM Data Movement Tool 就可以轻松地将表、包或整个模式从 Oracle 中拖放到 DB2 中。只有在发生异常的时候需要做很少的修改即可将应用程序移动到 DB2 或者修改应用程序，这样可以在 DB2 和 Oracle 上操作同样的数据源。&lt;/p&gt;&lt;p&gt;步骤可简单到只需：&lt;/p&gt;&lt;ol style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 5px"&gt;设置必要的注册表变量： &lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 1em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 5px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;db2set DB2_COMPATIBILITY_VECTOR=ORA&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 5px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;db2set DB2_DEFERRED_PREPARE_SEMANTICS=YES&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 5px"&gt;重启数据库管理器： &lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 1em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 5px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;db2stop&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 5px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;db2start&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 5px"&gt;创建兼容 Oracle 的数据库： &lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 1em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 5px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;db2 create database mydb pagesize 32 K&lt;/code&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 5px"&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;db2 update db cfg for mydb using auto_reval deferred_force&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 5px"&gt;启动 IBM Data Movement Tool，并连接到 Oracle 和 DB2 数据库（见&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;a style="color: rgb(76,110,148)" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#fig6"&gt;图 6&lt;/a&gt;）。连接后，可以选择仅提取 DDL 或者提取 DDL 和数据。最后，有两个选择：通过执行生成的脚本直接部署，或者继续使用&lt;em&gt;交互部署&lt;/em&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;面板。（对于大部分重要应用程序建议使用后者）。&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="fig6"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 1em; font-weight: bold; padding-top: 0.3em"&gt;图 6. 使用 IBM Data Movement Tool 拖放 Oracle 模式到 DB2&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;img style="padding-bottom: 0.7em; border-right-width: 0px; padding-left: 5px; padding-right: 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0.3em" alt="使用 IBM Data Movement Tool 拖放 Oracle 模式到 DB2" src="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/ExtractTool1.jpg" width="572" height="418" /&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 5px"&gt;使用&lt;em&gt;交互部署&lt;/em&gt;（见&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;a style="color: rgb(76,110,148)" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#fig7"&gt;图 7&lt;/a&gt;）将需要的模式从 Oracle 移动到 DB2。在&lt;em&gt;交互部署&lt;/em&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;模式中，您会看到一个导航树，它显示了所有从 Oracle 数据库中提取的对象。选择所有对象并执行部署菜单选项。该工具将复制这些对象到 DB2 并记录其进度。某些对象可能不能成功部署，该工具会为您提供选项来处理这些对象。选择对象时，您会看到 DDL 以及 DB2 遇到的错误。现在可以按需修复定义并使用内置编辑器重新部署。目标是在发生异常的时候交互式地将所有对象移动到 DB2。&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a name="fig7"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 1em; font-weight: bold; padding-top: 0.3em"&gt;图 7. 使用 IBM Data Movement Tool 将 Oracle 模式拖放到 DB2&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;img style="padding-bottom: 0.7em; border-right-width: 0px; padding-left: 5px; padding-right: 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0.3em" alt="使用 IBM Data Movement Tool 将 Oracle 模式拖放到 DB2" src="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/ExtractTool2.jpg" width="572" height="422" /&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N1066F"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;Oracle 数据库与 DB2 兼容性评估&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;那么使 DB2 9.7 支持 Oracle 应用程序究竟有多容易呢？答案是要视情况而定。IBM 有一个内部工具，叫做 MEET DB2，可以分析 Oracle 数据库中的所有对象并进行评分。它会生成一个报告，其中列出哪些地方可以开箱即用，哪些地方需要进行调整。您的客户代表或销售联系人可以运行此工具快速对您当前的 Oracle 数据库与 DB2 的兼容性进行评估。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="N1067A"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;图 8. MEET DB2 评估报告工具&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;img style="padding-bottom: 0.7em; border-right-width: 0px; padding-left: 5px; padding-right: 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0.3em" alt="MEET DB2 评估报告工具" src="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/MEET-DB2.jpg" width="572" height="355" /&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;在 DB2 9.7 一年的 beta 版测试期间，对很多应用程序（共有 750.000 行 PL/SQL 代码）进行了详细分析，平均开箱即用迁移率为 90%-99%。&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;a name="N1068C"&gt;&lt;strong style="padding-bottom: 0.7em; padding-left: 5px; padding-right: 5px; font-family: arial, sans-serif; font-size: 0.76em; font-weight: bold; padding-top: 0.3em"&gt;图 9. 支持语句的平均迁移率 98%&lt;/strong&gt;&lt;/a&gt;&lt;br /&gt;&lt;img style="padding-bottom: 0.7em; border-right-width: 0px; padding-left: 5px; padding-right: 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0.3em" alt="支持语句的平均迁移率 98%" src="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/supportedrate.jpg" width="572" height="345" /&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N10699"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;局限性&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;DB2 Express、DB2 Express-C 和 DB2 Personal 版目前尚未提供 PL/SQL、内置包库和 CLPPlus。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N106A1"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;结束语&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;凭借其本机多专用语言 SQL 支持，DB2 9.7 支持在 DB2 上轻松地使用 Oracle 应用程序。打包应用程序厂商可以以最少的成本提供既可用于 Oracle 又可用于 DB2 的应用程序。客户可以自由选择提供其所需技术的厂商，无需收到以前的限制。&lt;/p&gt;&lt;p&gt;要测试这些特性，可以下载 DB2 9.7 的试用版（见&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;a style="color: rgb(76,110,148)" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#resources"&gt;参考资料&lt;/a&gt;）。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0907oracleappsondb2/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="N106B2"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;常见问题解答&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;DB2 9.7 支持哪个版本的 Oracle？&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;为 SQL 和 PL/SQL 专用语言提供的范围严格基于应用程序正在使用的版本。支持最新的 Oracle 11g 中引入的某些特性。但是不支持 Oracle 8i 中使用的某些构造。在一个涉及 18 个应用程序总共 750,000 行代码的研究中，90%-99% 的代码被原封不动的移动到了 DB2。其他代码的调整可以自动进行或者是重复的。&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Oracle 应用程序在 DB2 上的运行速度如何？&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;这个问题很难回答！很遗憾，Oracle 许可条款中禁止任何人未经预先书面同意公布基准测试结果。不用说，我们不会自讨没趣的去询问其是否同意。但是，凭借其特别设计，又经过质量保证基准测试的确认，在 DB2 上用 PL/SQL 编写的应用程序与在 DB2 上用 SQL PL 编写的应用程序运行得一样快。使用过这种支持过程的厂商基本上都感到惊喜。&lt;/p&gt;&lt;p&gt;&lt;strong&gt;提供这些特性需要进行多少工作？&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;不像大家想象的那么多。已经以战略方式为 DB2 9.5 完成了一些初始工作，比如&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;CONNECT BY&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;和&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;NUMBER&lt;/code&gt;。坦率地讲，这些工作会在 18 个月之内完成。&lt;/p&gt;&lt;p&gt;&lt;strong&gt;支持从 Oracle 到 DB2 有哪些常见难题？&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;DB2 的兼容性显然不是 100%。所以在您第一次在 DB2 上使用 Oracle 应用程序时可能有些小问题。但是，这些问题很多都是无足轻重的而且容易修复。例如，DB2 支持 PL/SQL 触发器，但不允许组合触发器操作。就是说，要为&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;UPDATE&lt;/code&gt;、&lt;code style="font-family: monospace; font-size: small !important"&gt;DELETE&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;和&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;INSERT&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;操作共享一个触发器。现在，假设有一个 PL/SQL 多操作触发器，使用&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;INSERTED&lt;/code&gt;、&lt;code style="font-family: monospace; font-size: small !important"&gt;UPDATED&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;和&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;DELETED&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;谓词的 boolean 变量很容易将它复制到三个 DB2 PL/SQL 触发器中。&lt;/p&gt;&lt;p&gt;&lt;/span&gt;&lt;/span&gt;&lt;br class="Apple-interchange-newline" /&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/millen/aggbug/2311786.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/millen/archive/2012/01/04/2311786.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/millen/archive/2011/12/30/2307432.html</id><title type="text">db2权限控制(转)</title><summary type="text">转自：http://gocom.primeton.com/blog16274_23254.htmdb2权限控制 1. DB2 权限控制数据库安全性计划的以下几方面：授予用户的权限级别允许用户运行的命令允许用户读和／或修改的数据允许用户创建、修改和／或删除的数据库对象 在 DB2 所提供的五种权限中，SYSADM、SYSCTRL 和 SYSMAINT 是实例级权限。 这意味着权限（作用的）范围包括实例级命令和对实例内的所有数据库所执行的命令。这些权限只能指派给某个组；可以通过 DBM CFG 文件来进行指派。DBADM 和 LOAD 权限是为了某个特定的数据库而指定给某个用户或组的。可以用 GR</summary><published>2011-12-30T06:12:00Z</published><updated>2011-12-30T06:12:00Z</updated><author><name>catch22</name><uri>http://www.cnblogs.com/millen/</uri></author><link rel="alternate" href="http://www.cnblogs.com/millen/archive/2011/12/30/2307432.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/millen/archive/2011/12/30/2307432.html"/><content type="html">&lt;p&gt;转自：&lt;a href="http://gocom.primeton.com/blog16274_23254.htm"&gt;http://gocom.primeton.com/blog16274_23254.htm&lt;/a&gt;&lt;/p&gt;&lt;p&gt;db2权限控制 &lt;meta name="ProgId" content="Word.Document" /&gt;&lt;meta name="Generator" content="Microsoft Word 11" /&gt;&lt;meta name="Originator" content="Microsoft Word 11" /&gt;&lt;style type="text/css"&gt;&lt;!-- /* Font Definitions */ @font-face{font-family:Courier;panose-1:2 7 4 9 2 2 5 2 4 4;mso-font-charset:0;mso-generic-font-family:modern;mso-font-format:other;mso-font-pitch:fixed;mso-font-signature:3 0 0 0 1 0;}@font-face{font-family:Wingdings;panose-1:5 0 0 0 0 0 0 0 0 0;mso-font-charset:2;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:0 268435456 0 0 -2147483648 0;}@font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:Verdana;panose-1:2 11 6 4 3 5 4 4 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:536871559 0 0 0 415 0;}@font-face{font-family:"\@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}p{mso-margin-top-alt:auto;margin-right:0cm;mso-margin-bottom-alt:auto;margin-left:0cm;mso-pagination:widow-orphan;font-size:12.0pt;font-family:宋体;mso-bidi-font-family:"Times New Roman";}code{mso-ansi-font-size:1.5pt;mso-bidi-font-size:1.5pt;font-family:Courier;mso-ascii-font-family:Courier;mso-fareast-font-family:宋体;mso-hansi-font-family:Courier;mso-bidi-font-family:宋体;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;} /* List Definitions */ @list l0{mso-list-id:34283392;mso-list-template-ids:1378517574;}@list l0:level1{mso-level-number-format:bullet;mso-level-text:&amp;#61623;;mso-level-tab-stop:36.0pt;mso-level-number-position:left;text-indent:-18.0pt;mso-ansi-font-size:10.0pt;font-family:Symbol;}@list l1{mso-list-id:996305643;mso-list-template-ids:646488456;}@list l1:level1{mso-level-number-format:bullet;mso-level-text:&amp;#61623;;mso-level-tab-stop:36.0pt;mso-level-number-position:left;text-indent:-18.0pt;mso-ansi-font-size:10.0pt;font-family:Symbol;}@list l2{mso-list-id:1176383444;mso-list-template-ids:-1481896242;}@list l2:level1{mso-level-number-format:bullet;mso-level-text:&amp;#61623;;mso-level-tab-stop:36.0pt;mso-level-number-position:left;text-indent:-18.0pt;mso-ansi-font-size:10.0pt;font-family:Symbol;}@list l3{mso-list-id:1655455230;mso-list-template-ids:-292814426;}@list l3:level1{mso-level-number-format:bullet;mso-level-text:&amp;#61623;;mso-level-tab-stop:36.0pt;mso-level-number-position:left;text-indent:-18.0pt;mso-ansi-font-size:10.0pt;font-family:Symbol;}@list l4{mso-list-id:1813790948;mso-list-template-ids:1175765358;}@list l4:level1{mso-level-number-format:bullet;mso-level-text:&amp;#61623;;mso-level-tab-stop:36.0pt;mso-level-number-position:left;text-indent:-18.0pt;mso-ansi-font-size:10.0pt;font-family:Symbol;}ol{margin-bottom:0cm;}ul{margin-bottom:0cm;}--&gt;&lt;/style&gt;&lt;/p&gt;&lt;p&gt;1. &lt;span style="font-family: Verdana; color: red; font-size: 10pt"&gt;DB2 &lt;/span&gt;&lt;span style="color: red; font-size: 10pt"&gt;权限控制数据库安全性计划的以下几方面：&lt;/span&gt;&lt;span style="font-family: Verdana; color: red; font-size: 10pt"&gt;&lt;/span&gt;&lt;/p&gt;&lt;ul type="disc"&gt;&lt;li style="text-align: left; color: red"&gt;&lt;span style="font-family: 宋体; font-size: 10pt"&gt;授予用户的权限级别&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: red"&gt;&lt;span style="font-family: 宋体; font-size: 10pt"&gt;允许用户运行的命令&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: red"&gt;&lt;span style="font-family: 宋体; font-size: 10pt"&gt;允许用户读和／或修改的数据&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: red"&gt;&lt;span style="font-family: 宋体; font-size: 10pt"&gt;允许用户创建、修改和／或删除的数据库对象&lt;/span&gt; &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;在&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; DB2 &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;所提供的五种权限中，&lt;/span&gt;&lt;span style="font-family: Verdana; color: red; font-size: 10pt"&gt;SYSADM&lt;/span&gt;&lt;span style="font-family: 宋体; color: red; font-size: 10pt"&gt;、&lt;/span&gt;&lt;span style="font-family: Verdana; color: red; font-size: 10pt"&gt;SYSCTRL &lt;/span&gt;&lt;span style="font-family: 宋体; color: red; font-size: 10pt"&gt;和&lt;/span&gt;&lt;span style="font-family: Verdana; color: red; font-size: 10pt"&gt; SYSMAINT &lt;/span&gt;&lt;span style="font-family: 宋体; color: red; font-size: 10pt"&gt;是&lt;em&gt;实例级权限。&lt;/em&gt;&lt;/span&gt; &lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;这意味着权限（作用的）范围包括实例级命令和对实例内的所有数据库所执行的命令。&lt;/span&gt;&lt;span style="font-family: 宋体; color: red; font-size: 10pt"&gt;这些权限只能指派给某个组；可以通过&lt;/span&gt;&lt;span style="font-family: Verdana; color: red; font-size: 10pt"&gt; DBM CFG &lt;/span&gt;&lt;span style="font-family: 宋体; color: red; font-size: 10pt"&gt;文件来进行指派。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt;DBADM &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;和&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; LOAD &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;权限是为了某个特定的数据库而指定给某个用户或组的。可以用&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; GRANT &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;命令来显式地完成这一工作。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size: 10.5pt"&gt;通过发出以下命令，用户可以确定他们具有哪些权限及数据库级别的特权：&lt;/span&gt;&lt;/p&gt;&lt;p align="left"&gt;db2 get authorizations&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: 宋体; color: black"&gt;注：对组成员资格的任何引用都意味着已经在操作系统级别定义了用户和组名称。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10.5pt"&gt;2. DB2 &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;中的&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; SYSADM &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;权限类似于&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; UNIX &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;上的&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; root &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;权限或&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; Windows &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;上的&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; Administrator &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;权限。对某个&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; DB2 &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;实例具备&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; SYSADM &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;权限的用户能够对该实例、该实例内的任何数据库以及这些数据库内的任何对象发出任何&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; DB2 &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;命令。他们还能够访问数据库内的数据，并能够授予或取消特权和权限。&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt;SYSADM &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;用户是唯一允许更新&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; DBM CFG &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;文件的用户。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt;SYSADM &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;权限是通过&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; DBM CFG &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;文件中的&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; SYSADM_GROUP &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;参数来控制的。在创建实例时，在&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; Windows &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;上，该参数被设置成&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; Administrator&lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;（虽然在您&lt;/span&gt;&lt;span style="color: black; font-size: 10.5pt"&gt;发出命令&lt;/span&gt; &lt;code&gt;&lt;span style="color: black; font-size: 10.5pt"&gt;db2 get dbm cfg&lt;/span&gt;&lt;/code&gt; &lt;span style="color: black; font-size: 10.5pt"&gt;时该参数好&lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;象为空）。在&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; UNIX &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;上，该参数被设置成创建实例的主用户组。&lt;/span&gt;&lt;span style="color: red; font-size: 10pt"&gt;由于&lt;/span&gt;&lt;span style="font-family: Verdana; color: red; font-size: 10pt"&gt; SYSADM &lt;/span&gt;&lt;span style="color: red; font-size: 10pt"&gt;用户是唯一允许更新&lt;/span&gt;&lt;span style="font-family: Verdana; color: red; font-size: 10pt"&gt; DBM CFG &lt;/span&gt;&lt;span style="color: red; font-size: 10pt"&gt;的用户，因此他们也是唯一允许向其它组授予任何&lt;/span&gt;&lt;span style="font-family: Verdana; color: red; font-size: 10pt"&gt; SYS* &lt;/span&gt;&lt;span style="color: red; font-size: 10pt"&gt;权限的用户。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: 宋体"&gt;记住，只有将实例停止然后重新启动，上面的更改才会生效。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;3&lt;span style="font-family: 宋体"&gt;．&lt;/span&gt;&amp;nbsp;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;具有&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; SYSCTRL &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;权限的用户可以在实例内执行所有管理和维护命令。然而，与&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; SYSADM &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;用户不同的是，除非向他们授予了访问数据库内任何数据所需的特权，否则他们就不能访问这些数据。&lt;/span&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;span style="font-family: Verdana; color: black"&gt;SYSCTRL &lt;/span&gt;&lt;span style="font-family: 宋体; color: black"&gt;用户可以对实例内的任何数据库执行的命令示例有：&lt;/span&gt;&lt;/p&gt;&lt;ul type="disc"&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2start/db2stop&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 create/drop database&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 create/drop tablespace&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 backup/restore/rollforward database&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 runstats&lt;/span&gt; &lt;span style="font-family: 宋体"&gt;（可以对任何表执行该命令）&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 update db cfg for database &lt;em&gt;dbname&lt;/em&gt; &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt;4. &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;具有&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; SYSMAINT &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;权限的用户可以发出的命令是具有&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; SYSCTRL &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;权限的用户所允许发出的命令的子集。&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt;SYSCTRL &lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;用户只能执行与维护有关的任务。&lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;如：&lt;/span&gt;&lt;/p&gt;&lt;ul type="disc"&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2start/db2stop&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 backup/restore/rollforward database&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 runstats&lt;/span&gt; &lt;span style="font-family: 宋体"&gt;（可以对任何表执行该命令）&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 update db cfg for database &lt;em&gt;dbname&lt;/em&gt; &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;注意：具有&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; SYSMAINT &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;权限的用户不能够创建或删除数据库或表空间。除非向他们授予了访问数据库内任何数据所需的特权，否则他们也不能访问这些数据。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt;5&lt;/span&gt;&lt;span style="color: black; font-size: 10pt"&gt;．&lt;/span&gt;&lt;span style="color: black; font-size: 10.5pt"&gt;总的来说，&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10.5pt"&gt;DBADM &lt;/span&gt;&lt;span style="color: black; font-size: 10.5pt"&gt;用户几乎能够完全控制数据库。但&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10.5pt"&gt; DBADM &lt;/span&gt;&lt;span style="color: black; font-size: 10.5pt"&gt;用户不能执行类似下面的维护或管理任务：&lt;/span&gt;&lt;/p&gt;&lt;ul type="disc"&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;drop database&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;drop/create tablespace&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;backup/restore database&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;update db cfg for database &lt;em&gt;db name&lt;/em&gt; &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p align="left"&gt;&lt;span style="font-family: 宋体; color: black"&gt;然而，他们却可以执行下列任务：&lt;/span&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;span style="font-family: Courier; color: black"&gt;db2 create/drop table&lt;/span&gt; &lt;/p&gt;&lt;p align="left"&gt;&lt;span style="font-family: Courier; color: black"&gt;db2 grant/revoke&lt;/span&gt; &lt;span style="font-family: 宋体; color: black"&gt;（任何特权）&lt;/span&gt; &lt;/p&gt;&lt;p align="left"&gt;&lt;span style="font-family: Courier; color: black"&gt;db2 runstats&lt;/span&gt; &lt;span style="font-family: 宋体; color: black"&gt;（任何表）&lt;/span&gt; &lt;/p&gt;&lt;p align="left"&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt;DBADM &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;用户还被自动授予数据库对象及其内容的全部特权。由于&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; DBADM &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;权限是一种数据库级权限，因此&lt;/span&gt;&lt;span style="font-family: 宋体; color: red; font-size: 10pt"&gt;可以将它指派给用户和组。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt;6. LOAD &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;权限允许用户对表发出&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; LOAD &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;命令。在填充具有大量数据的表时，通常使用&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; LOAD &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;这种执行更快的命令来替代插入或导入命令。根据您希望执行的&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; LOAD &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;类型的不同，仅仅具有&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; LOAD &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;权限可能还是不够的。还可能需要对该表具有特定特权。&lt;/span&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;具有&lt;/span&gt;&lt;span style="font-family: Verdana; color: black; font-size: 10pt"&gt; LOAD &lt;/span&gt;&lt;span style="font-family: 宋体; color: black; font-size: 10pt"&gt;权限的用户可以运行下列命令：&lt;/span&gt;&lt;/p&gt;&lt;ul type="disc"&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 quiesce tablespaces for table&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 list tablespaces&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 runstats&lt;/span&gt; &lt;span style="font-family: 宋体"&gt;（任何表）&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 load insert&lt;/span&gt; &lt;span style="font-family: 宋体"&gt;（必须对表具有插入特权）&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 load restart/terminate after load insert&lt;/span&gt; &lt;span style="font-family: 宋体"&gt;（必须对表具有插入特权）&lt;/span&gt;&lt;/li&gt;&lt;li style="text-align: left; color: black"&gt;&lt;span style="font-family: Courier"&gt;db2 load replace&lt;/span&gt; &lt;span style="font-family: 宋体"&gt;（必须对表具有插入和删除特权）&lt;/span&gt; &lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family: Courier; color: black; font-size: 10.5pt"&gt;db2 load restart/terminate after load replace&lt;/span&gt; &lt;span style="font-family: 宋体; color: black; font-size: 10.5pt"&gt;（必须对表具有插入和删除特权）&lt;/span&gt;&lt;img src="http://www.cnblogs.com/millen/aggbug/2307432.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/millen/archive/2011/12/30/2307432.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/millen/archive/2011/12/28/2304410.html</id><title type="text">Oracle中对XMLType的简单操作（extract、extractvalue）(转)</title><summary type="text">转自：http://hi.baidu.com/wuxg/blog/item/d9c8e750426bc7491038c2c2.htmlOracle中对XMLType的简单操作（extract、extractvalue）2011-03-15 16:53前几天一直在做Oracle对XMLType字段的操作，我还不是Oracle大拿，到网上找了很多资料，但是很多就是单一功能的介绍，不能很好的解决问题，现在在这里总结下。1、下面先创建一个名未test.xml的配置文件。&lt;?xml version="1.0" encoding="UTF-8" ?&gt;&amp;l</summary><published>2011-12-28T02:46:00Z</published><updated>2011-12-28T02:46:00Z</updated><author><name>catch22</name><uri>http://www.cnblogs.com/millen/</uri></author><link rel="alternate" href="http://www.cnblogs.com/millen/archive/2011/12/28/2304410.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/millen/archive/2011/12/28/2304410.html"/><content type="html">&lt;p&gt;转自：&lt;a href="http://hi.baidu.com/wuxg/blog/item/d9c8e750426bc7491038c2c2.html"&gt;http://hi.baidu.com/wuxg/blog/item/d9c8e750426bc7491038c2c2.html&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div class="tit"&gt;Oracle中对XMLType的简单操作（extract、extractvalue）&lt;/div&gt;&lt;div class="date"&gt;2011-03-15 16:53&lt;/div&gt;&lt;p&gt;&lt;table style="width: 100%; table-layout: fixed"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;div id="blog_text" class="cnt"&gt;&lt;span style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; color: rgb(66,66,66); font-size: 16px" class="Apple-style-span"&gt;&lt;p&gt;前几天一直在做Oracle对XMLType字段的操作，我还不是Oracle大拿，到网上找了很多资料，但是很多就是单一功能的介绍，不能很好的解决问题，现在在这里总结下。&lt;/p&gt;&lt;p&gt;1、下面先创建一个名未test.xml的配置文件。&lt;/p&gt;&lt;p&gt;&amp;lt;?xml version="1.0" encoding="UTF-8" ?&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;lt;collection xmlns=""&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp; &amp;lt;record&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;leader&amp;gt;-----nam0-22-----^^^450-&amp;lt;/leader&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;datafield tag="200" ind1="1" ind2=" "&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;subfield code="a"&amp;gt;抗震救灾&amp;lt;/subfield&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;subfield code="f"&amp;gt;奥运会&amp;lt;/subfield&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/datafield&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;datafield tag="209" ind1=" " ind2=" "&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;subfield code="a"&amp;gt;经济学&amp;lt;/subfield&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;subfield code="b"&amp;gt;计算机&amp;lt;/subfield&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;subfield code="c"&amp;gt;10001&amp;lt;/subfield&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;subfield code="d"&amp;gt;2005-07-09&amp;lt;/subfield&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/datafield&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;datafield tag="610" ind1="0" ind2=" "&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;subfield code="a"&amp;gt;计算机&amp;lt;/subfield&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;subfield code="a"&amp;gt;笔记本&amp;lt;/subfield&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/datafield&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp; &amp;lt;/record&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;lt;/collection&amp;gt;&lt;/p&gt;&lt;p&gt;2、在Oracle中创建一个存放该XML文件的表：&lt;/p&gt;&lt;p&gt;create or replace table xmlexample(&lt;br style="line-height: 25px" /&gt;ID varchar2(10),&lt;br style="line-height: 25px" /&gt;name varchar2(20),&lt;br style="line-height: 25px" /&gt;data xmltype&lt;br style="line-height: 25px" /&gt;)&lt;br style="line-height: 25px" /&gt;insert into xmlexample(id,name,data)&lt;br style="line-height: 25px" /&gt;values(sys_guid(),'my document',&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmltype&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bfilename(filepath,filename),&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nls_charset_id('AL32UTF8')&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br style="line-height: 25px" /&gt;)&lt;/p&gt;&lt;p&gt;其中filepath为文件路径，filename为文件名。&lt;/p&gt;&lt;p&gt;3、extractvalue()函数的使用&lt;br style="line-height: 25px" /&gt;&amp;nbsp; Oracle提供对XML文件的检索功能（extractvalue），extractvalue只能返回一个节点的一个值，具体操作方法如下：&lt;/p&gt;&lt;p&gt;SQL&amp;gt; select id,name,&lt;br style="line-height: 25px" /&gt;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extractvalue(x.data,'/collection/record/leader') as A&lt;br style="line-height: 25px" /&gt;&amp;nbsp; 3&amp;nbsp; from xmlexample x;&lt;/p&gt;&lt;p&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&lt;br style="line-height: 25px" /&gt;---------- -------------------- ----------------------------------&lt;br style="line-height: 25px" /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; my document&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -----nam0-22-----^^^450-&lt;/p&gt;&lt;p&gt;如果该节点有两个值，则系统提示错误。&lt;/p&gt;&lt;p&gt;4、extract()函数的使用&lt;br style="line-height: 25px" /&gt;如果想查询所有subfield的值就要用到extract()，它可以返回一个节点下的所有值。操作如下&lt;/p&gt;&lt;p&gt;SQL&amp;gt; select id,name,&lt;br style="line-height: 25px" /&gt;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extract(x.data,'/collection/record/datafield/subfield') as A&lt;br style="line-height: 25px" /&gt;&amp;nbsp; 3&amp;nbsp; from xmlexample x;&lt;/p&gt;&lt;p&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&lt;br style="line-height: 25px" /&gt;---------- -------------------- ---------------------------------------------------------&lt;br style="line-height: 25px" /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; my document&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;subfield xmlns="" code="a"&amp;gt;抗震救灾&amp;lt;/subfield&amp;gt;&amp;lt;subfield xmlns="" code="f"&amp;gt;何观.....&lt;/p&gt;&lt;p&gt;可以看到它返回的是XML格式的。如果我们想只返回它值就要是用两个函数了。&lt;/p&gt;&lt;p&gt;5、table和XMLSequence&lt;br style="line-height: 25px" /&gt;操作如下：&lt;/p&gt;&lt;p&gt;SQL&amp;gt; select extractValue(value(i),'/subfield') xx&lt;br style="line-height: 25px" /&gt;&amp;nbsp; 2&amp;nbsp; from xmlexample x,&lt;br style="line-height: 25px" /&gt;&amp;nbsp; 3&amp;nbsp; table(XMLSequence(extract(x.data,'/collection/record/datafield/subfield'))) i;&lt;/p&gt;&lt;p&gt;XX&lt;br style="line-height: 25px" /&gt;--------------------------------------------------------------------------------&lt;br style="line-height: 25px" /&gt;抗震救灾&lt;br style="line-height: 25px" /&gt;何观华&lt;br style="line-height: 25px" /&gt;经济学&lt;br style="line-height: 25px" /&gt;计算机&lt;br style="line-height: 25px" /&gt;10001&lt;br style="line-height: 25px" /&gt;2005-07-09&lt;br style="line-height: 25px" /&gt;计算几&amp;nbsp; 哈哈&lt;/p&gt;&lt;p&gt;7 rows selected。&lt;/p&gt;&lt;p&gt;6、检索出特定的节点的特定值&lt;br style="line-height: 25px" /&gt;有时候我们在实际操作的时候并不是检索出所有值，而是根据条件查询出我们所需要的信息。如果我们想检索出&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;datafield tag="209" ind1=" " ind2=" "&amp;gt;&lt;br style="line-height: 25px" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;subfield code="a"&amp;gt;经济学&amp;lt;/subfield&amp;gt;&lt;br style="line-height: 25px" /&gt;中的值-经济学&lt;/p&gt;&lt;p&gt;操作如下：&lt;/p&gt;&lt;p&gt;SQL&amp;gt; select id,name,&lt;br style="line-height: 25px" /&gt;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extractvalue(x.data,'/collection/record/datafield[@tag="209"]/subfield[@code="a"]') as A&lt;br style="line-height: 25px" /&gt;&amp;nbsp; 3&amp;nbsp; from xmlexample x;&lt;/p&gt;&lt;p&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A&lt;br style="line-height: 25px" /&gt;---------- -------------------- ---------------------------&lt;br style="line-height: 25px" /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; my document&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 经济学&lt;/p&gt;&lt;p&gt;7、总结&lt;/p&gt;&lt;p&gt;Oracle对与XMLType的操作有很多种，还要靠大家自己去发现。数据库对XML的检索就是吧XML的节点当作一个列来检索，而不同的是表里装的是二维的数据，而XML中可以装N维。还有就是，表中列不存在就会提示无效标识符，如果节点不存在，则检索出NULL，不会报错。所以，对与XML文件的操作通常是通过试图来完成。&lt;/p&gt;&lt;/span&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/millen/aggbug/2304410.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/millen/archive/2011/12/28/2304410.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/millen/archive/2011/12/27/2302993.html</id><title type="text">联邦数据库的一个例子(转)</title><summary type="text">转自：http://bbs.51cto.com/archiver/tid-496967.html联邦数据库的一个例子！联邦数据库的理解就不说了哈！下边就一个例子来配置：在3.40上创建基于4.5的联邦数据库的过程：1.设置联邦数据库开关db2 update dbm cfg using federated yesdb2stopdb2startdb22.为远程数据库创建“包装器”:create wrapper drda--drda为名称3.定义联邦服务器create server tstsvrtype DB2/AIX --数据库类型version 8.1--版本wrapper drda autho</summary><published>2011-12-27T01:16:00Z</published><updated>2011-12-27T01:16:00Z</updated><author><name>catch22</name><uri>http://www.cnblogs.com/millen/</uri></author><link rel="alternate" href="http://www.cnblogs.com/millen/archive/2011/12/27/2302993.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/millen/archive/2011/12/27/2302993.html"/><content type="html">&lt;p&gt;转自：&lt;a href="http://bbs.51cto.com/archiver/tid-496967.html"&gt;http://bbs.51cto.com/archiver/tid-496967.html&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;联邦数据库的一个例子！&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;联邦数据库的理解就不说了哈！&lt;br /&gt;下边就一个例子来配置：&lt;br /&gt;在3.40上创建基于4.5的联邦数据库的过程：&lt;br /&gt;&lt;br /&gt;1.设置联邦数据库开关&lt;br /&gt;db2 update dbm cfg using federated yes&lt;br /&gt;db2stop&lt;br /&gt;db2start&lt;br /&gt;db2&lt;br /&gt;2.为远程数据库创建&amp;#8220;包装器&amp;#8221;:&lt;br /&gt;create wrapper drda&lt;br /&gt;&amp;nbsp;&amp;nbsp;--drda为名称&lt;br /&gt;3.&lt;br /&gt;定义联邦服务器&lt;br /&gt;create server tstsvr&lt;br /&gt;type DB2/AIX --数据库类型&lt;br /&gt;version 8.1&amp;nbsp;&amp;nbsp;--版本&lt;br /&gt;wrapper drda authorization "db2admin" password "...." options(NODE 'SERVER',dbname 'DW');&lt;br /&gt;--&lt;br /&gt;authorization 为远程数据库用户&lt;br /&gt;-- password 为密码&lt;br /&gt;--NODE 为远程实例映射到本地的node&lt;br /&gt;--dbname为远程实例下的数据库名&lt;br /&gt;commit;&lt;br /&gt;4.为联邦者认证创建用户映射&lt;br /&gt;-- create user mapping for "DB2ADMIN" server tstsvr options(remote_authid 'DB2ADMIN',remote_password '....');&lt;br /&gt;-- commit;&lt;br /&gt;CREATE USER MAPPING FOR "DB2ADMIN" --db2admin为本地用户&lt;br /&gt;SERVER TSTSVR&lt;br /&gt;&amp;nbsp;&amp;nbsp;OPTIONS&lt;br /&gt;&amp;nbsp; &amp;nbsp;(REMOTE_AUTHID 'db2admin',--远程用户名和3一致&lt;br /&gt;&amp;nbsp; &amp;nbsp; REMOTE_PASSWORD 777400419419456990610222 --远程秘密和3一致,不过这边有一个加密的过程&lt;br /&gt;&amp;nbsp; &amp;nbsp;);&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;5. 表别名 － 访问远程表的&amp;#8220;门票&amp;#8221;&lt;br /&gt;create nickname CUST_TYPE_C1_Z for tstsvr.db2admin.CUST_GROUP_C1_Z;&lt;br /&gt;commit;&lt;br /&gt;6.测试如下:&lt;br /&gt;select * from CUST_TYPE_C1_Z;&lt;br /&gt;--auther：z.x.t&lt;br /&gt;--前提：用quest center在3.40上配置了关于4.5的catalog，如果没有quest center也可以用以下命令来配置&lt;br /&gt;--如下：&lt;br /&gt;1。创建节点实例&lt;br /&gt;CATALOG TCPIP NODE server&lt;br /&gt;&amp;nbsp; &amp;nbsp; REMOTE 192.168.4.5&lt;br /&gt;&amp;nbsp; &amp;nbsp; SERVER 50000&lt;br /&gt;&amp;nbsp; &amp;nbsp; REMOTE_INSTANCE db2&lt;br /&gt;&amp;nbsp; &amp;nbsp; OSTYPE NT;&lt;br /&gt;2。创建实例下的数据库&lt;br /&gt;CATALOG DATABASE dw&lt;br /&gt;&amp;nbsp; &amp;nbsp; AS dw&lt;br /&gt;&amp;nbsp; &amp;nbsp; AT NODE SERVER&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;AUTHENTICATION SERVER;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;另一篇：&lt;/p&gt;&lt;p&gt;&lt;span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"&gt; &lt;/p&gt;&lt;p&gt;联邦数据库访问远程DB2&lt;br /&gt;假定两个环境host1和host2&lt;/p&gt;&lt;p&gt;host1，本机&lt;br /&gt;IP: 192.168.1.192&lt;br /&gt;DB2 instance: db2inst1&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;DB2 db: local_db&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;host2，远程被访问机器&lt;br /&gt;IP: 192.168.1.195&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;DB2 instance: db2inst1(port=50000,pwd=db2inst1)&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;DB2 db: remote_db&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;table: t_usertable&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;现在需要在host1的local_db数据库中访问远程host2上的表t_usertable&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;首先需要在host1上把host2节点和remote_db库编目进来&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;db2 catalog tcpip node node_195 remote 192.168.1.195 server 50000&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;db2 catalog db remote_db as remote_db_195 at node node_195&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;db2 TERMINATE (必须使用该命令否则可能导致catalog更新不能生效)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;然后在host1上测试到host2的连通性&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;db2 connect to remote_db_195 user db2inst1 using db2inst1&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;db2 connect reset&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;修改host1和host2的实例配置参数，需要重起实例&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;db2 update dbm cfg using FED_NOAUTH yes&lt;br /&gt;db2stop&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;db2start&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;然后连接到host1机器上的local_db数据库中&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;db2 connect to local_db&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;(本地为unix环境)create wrapper DRDA;&lt;br /&gt;(本地为windows环境) create wrapper "DRDA" LIBRARY 'db2drda.dll' OPTIONS( ADD DB2_FENCED 'N');&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;create server remoteserver_195 TYPE DB2/UDB VERSION '8.2' WRAPPER DRDA AUTHORIZATION "db2inst1" PASSWORD "db2inst1" OPTIONS( DBNAME 'remote_db_195', PASSWORD 'Y');&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;CREATE USER MAPPING FOR "db2inst1" SERVER remoteserver_195 OPTIONS ( ADD REMOTE_AUTHID 'db2inst1', ADD REMOTE_PASSWORD 'db2inst1');&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;CREATE NICKNAME remote_t_usertable FOR remoteserver_195.db2inst1.t_usertable;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;(其中，wrapper使用DB2数据源的缺省名称DRDA server名称是remoteserver_195,t_usertable表在local_db数据库中的nickname是remote_t_usertable)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;在缺省的db2inst1模式下 然后可以在host1机器上，登陆进local_db，对remote_t_usertable表进行查询等操作了&lt;br /&gt;db2 'select * from db2inst1.remote_t_usertable'&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;db2 connect reset&lt;/p&gt;&lt;p&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/millen/aggbug/2302993.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/millen/archive/2011/12/27/2302993.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/millen/archive/2011/12/26/2302370.html</id><title type="text">DB2 SQL脚本批量执行(转)</title><summary type="text">转自：http://lavasoft.blog.51cto.com/62575/40316DB2 SQL脚本批量执行环境：Windows系统DB2客户端或者服务端一、准备工作运行db2cmd或者db2cw打开DB2命令行处理器进入SQL脚本存放目录用db2 connect to &lt;dbname&gt; user &lt;username&gt; using &lt;password&gt; 命令连接数据库用db2 set current schema &lt;schema_name&gt; 设置当前的SCHEMA，这个SCHEMA可以是未创建的，DB2会自动创建。二、执行不同类型的SQL</summary><published>2011-12-26T09:44:00Z</published><updated>2011-12-26T09:44:00Z</updated><author><name>catch22</name><uri>http://www.cnblogs.com/millen/</uri></author><link rel="alternate" href="http://www.cnblogs.com/millen/archive/2011/12/26/2302370.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/millen/archive/2011/12/26/2302370.html"/><content type="html">&lt;p&gt;转自：&lt;a href="http://lavasoft.blog.51cto.com/62575/40316"&gt;http://lavasoft.blog.51cto.com/62575/40316&lt;/a&gt;&lt;/p&gt;&lt;div&gt;&lt;strong&gt;&lt;font color="#ff0000" size="4"&gt;DB2 SQL脚本批量执行&lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;环境：&lt;/div&gt;&lt;div&gt;Windows系统&lt;/div&gt;&lt;div&gt;DB2客户端或者服务端&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;strong&gt;&lt;font color="#ff0000"&gt;一、准备工作&lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;运行db2cmd或者db2cw打开DB2命令行处理器&lt;/div&gt;&lt;div&gt;进入SQL脚本存放目录&lt;/div&gt;&lt;div&gt;用db2 connect to &amp;lt;dbname&amp;gt; user &amp;lt;username&amp;gt; using &amp;lt;password&amp;gt; 命令连接数据库&lt;/div&gt;&lt;div&gt;用db2 set current schema &amp;lt;schema_name&amp;gt; 设置当前的SCHEMA，这个SCHEMA可以是未创建的，DB2会自动创建。&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;strong&gt;&lt;font color="#ff0000"&gt;二、执行不同类型的SQL&lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;1、在命令行执行简单SQL命令&lt;/div&gt;&lt;div&gt;db2 &amp;lt;SQL语句内容&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;2、在命令行执行SQL脚本文件&lt;/div&gt;&lt;div&gt;db2 -td; -cf &amp;lt;SQL脚本文件路径&amp;gt; -l &amp;lt;输出日志文件路径&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;说明：-td; 指定语句结束标志。因为一般SQL都是以分号结尾，所以就写成&amp;#8220;-td;&amp;#8221;。&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -l &amp;lt;输出日志文件路径&amp;gt;&amp;nbsp; 是可选的。&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;3、在命令行执行DB2 存储过程文件&lt;/div&gt;&lt;div&gt;db2 -td@ -f &amp;lt;SQL过程文件路径&amp;gt; -l &amp;lt;输出日志文件路径&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;说明：-td; 指定语句结束标志。因为一般SQL过程都是以@结尾，所以就写成&amp;#8220;-td@&amp;#8221;。&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -l &amp;lt;输出日志文件路径&amp;gt;&amp;nbsp; 是可选的。&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;strong&gt;&lt;font color="#ff0000"&gt;三、写批处理脚本&lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;批处理脚本无非就是把命令写在一起，保存为bat文件，执行即可。&lt;/div&gt;&lt;div&gt;在写批处理之前，先回顾一下DB2命令选项：&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;C:\IBM\SQLLIB\BIN&amp;gt;db2 ? options&lt;/div&gt;&lt;div&gt;db2 [option ...] [db2-command | sql-statement |&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [? [phrase | message | sqlstate | class-code]]]&lt;/div&gt;&lt;div&gt;option：-a、-c、-d、-e{c|s}、-finfile、-i、-lhistfile、-m、-n、-o、&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -p、-q、-rreport、-s、-t、-td;、-v、-w、-x 和 -zoutputfile。&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;选项&amp;nbsp;&amp;nbsp;&amp;nbsp; 描述&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 缺省设置&lt;/div&gt;&lt;div&gt;&amp;nbsp;------&amp;nbsp; ----------------------------------------&amp;nbsp; ---------------&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -a&amp;nbsp;&amp;nbsp;&amp;nbsp; 显示 SQLCA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -c&amp;nbsp;&amp;nbsp;&amp;nbsp; 自动落实&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -d&amp;nbsp;&amp;nbsp;&amp;nbsp; 检索并显示 XML 声明&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -e&amp;nbsp;&amp;nbsp;&amp;nbsp; 显示 SQLCODE/SQLSTATE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -f&amp;nbsp;&amp;nbsp;&amp;nbsp; 读取输入文件&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -i&amp;nbsp;&amp;nbsp;&amp;nbsp; 显示 XML 数据并带有缩进&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -l&amp;nbsp;&amp;nbsp;&amp;nbsp; 将命令记录到历史记录文件中&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -m&amp;nbsp;&amp;nbsp;&amp;nbsp; 显示受影响的行数&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -n&amp;nbsp;&amp;nbsp;&amp;nbsp; 除去换行字符&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -o&amp;nbsp;&amp;nbsp;&amp;nbsp; 显示输出&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -p&amp;nbsp;&amp;nbsp;&amp;nbsp; 显示 db2 交互式提示符&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -q&amp;nbsp;&amp;nbsp;&amp;nbsp; 保留空格和换行符&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -r&amp;nbsp;&amp;nbsp;&amp;nbsp; 将输出报告保存到文件&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -s&amp;nbsp;&amp;nbsp;&amp;nbsp; 在命令出错时停止执行&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -t&amp;nbsp;&amp;nbsp;&amp;nbsp; 设置语句终止字符&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -v&amp;nbsp;&amp;nbsp;&amp;nbsp; 回传当前命令&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -w&amp;nbsp;&amp;nbsp;&amp;nbsp; 显示 FETCH/SELECT 警告消息&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ON&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -x&amp;nbsp;&amp;nbsp;&amp;nbsp; 不打印列标题&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; -z&amp;nbsp;&amp;nbsp;&amp;nbsp; 将所有输出保存到输出文件&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OFF&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;注意：&lt;/div&gt;&lt;div&gt;&amp;nbsp;使用 DB2OPTIONS 环境变量定制选项缺省值。&lt;/div&gt;&lt;div&gt;&amp;nbsp;紧跟选项字母后的减号（-）使该选项关闭。&lt;/div&gt;&lt;div&gt;&amp;nbsp;使用 UPDATE COMMAND OPTIONS 更改选项设置（以交互式或&lt;/div&gt;&lt;div&gt;&amp;nbsp;文件输入方式）。&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;根据命令参数创建批处理文件xxx.bat：&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;rem&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -- 连接数据库&lt;/div&gt;&lt;div&gt;db2 connect to &amp;lt;dbname&amp;gt; user &amp;lt;username&amp;gt; using &amp;lt;password&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;rem&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -- 设置SCHEMA&lt;/div&gt;&lt;div&gt;db2 set current schema &amp;lt;schema_name&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;rem&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -- 执行SQL脚本列表&lt;/div&gt;&lt;div&gt;db2 -td; -cf &amp;lt;SQL脚本文件路径&amp;gt; -l &amp;lt;输出日志文件路径&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;rem&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -- 执行SQL过程列表&lt;/div&gt;&lt;div&gt;db2 -td@ -f &amp;lt;SQL过程文件路径&amp;gt; -l &amp;lt;输出日志文件路径&amp;gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;注意：&amp;lt;SQL过程文件路径&amp;gt;可以是绝对路径也可以是相对路径。&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;strong&gt;&lt;font color="#ff0000"&gt;四、执行批处理&lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;运行db2cmd或者db2cw打开DB2命令行处理器。&lt;/div&gt;&lt;div&gt;如果&amp;lt;SQL过程文件路径&amp;gt;和&amp;lt;SQL脚本文件路径&amp;gt;为绝对路径，则可以直接命令行执行 xxx&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;如果&amp;lt;SQL过程文件路径&amp;gt;和&amp;lt;SQL脚本文件路径&amp;gt;为相对路径，则需要进入适当的目录，一边能在此目录下找到批处理，然后执行 xxx&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;p&gt;本文出自 &amp;#8220;&lt;a href="http://lavasoft.blog.51cto.com/"&gt;熔 岩&lt;/a&gt;&amp;#8221; 博客，请务必保留此出处&lt;a href="http://lavasoft.blog.51cto.com/62575/40316"&gt;http://lavasoft.blog.51cto.com/62575/40316&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/millen/aggbug/2302370.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/millen/archive/2011/12/26/2302370.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/millen/archive/2011/12/23/2299419.html</id><title type="text">Oracle Package中的包变量的使用(转)</title><summary type="text">转自：http://hi.baidu.com/andyloolu/blog/item/a64f0ed12cc10738960a165a.html在Oracle中，可以定义包变量。 关于包变量的使用，不少的人不是很清楚。首先我们看如下的例子： CREATE OR REPLACE PACKAGE ds_test AS procedure proc1; END ds_test; / CREATE OR REPLACE PACKAGE BODY ds_test AS n number:=0; procedure proc1 is begin n:=n+1; dbms_output.put_line(.</summary><published>2011-12-23T06:42:00Z</published><updated>2011-12-23T06:42:00Z</updated><author><name>catch22</name><uri>http://www.cnblogs.com/millen/</uri></author><link rel="alternate" href="http://www.cnblogs.com/millen/archive/2011/12/23/2299419.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/millen/archive/2011/12/23/2299419.html"/><content type="html">&lt;p&gt;转自：&lt;a href="http://hi.baidu.com/andyloolu/blog/item/a64f0ed12cc10738960a165a.html"&gt;http://hi.baidu.com/andyloolu/blog/item/a64f0ed12cc10738960a165a.html&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;在Oracle中，可以定义包变量。 &lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 关于包变量的使用，不少的人不是很清楚。首先我们看如下的例子：&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CREATE OR REPLACE PACKAGE ds_test AS&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; procedure proc1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END ds_test;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CREATE OR REPLACE PACKAGE BODY ds_test AS&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n number:=0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; procedure proc1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; is&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n:=n+1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dbms_output.put_line('n='||n);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end proc1;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END ds_test;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 执行如下的脚本，其输出的结果是什么呢？&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DS_TEST.PROC1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DS_TEST.PROC1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DS_TEST.PROC1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DS_TEST.PROC1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 呵呵执行结果是：&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n=1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n=2&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n=3&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n=4&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 这说明什么问题呢，这也就是说ORACLE中的Package酒相当于我们java中的一个class，在运行的时候被实例化，因此其中包变量就像是该实例中的实例变量一样。在Oracle中对包一个会话调用中，包变量是该会话中的&amp;#8220;全局&amp;#8221;变量。&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 当然，在Oracle Package中，也可以定义包过程，其中很简单。比如将入行的包体修改一下：&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CREATE OR REPLACE PACKAGE BODY ds_test AS&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n number:=0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; procedure proc1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; is&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n:=n+1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dbms_output.put_line('n='||n);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end proc1;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#ff0000"&gt;&lt;strong&gt;begin&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n:=n+100;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END ds_test;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 那么执行上述脚本后的结果是什么？&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 执行后的结果是：&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n=101&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n=102&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n=103&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n=104&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 由此可见，包过程是在一个会话中第一次调用时被执行，而在该会话中其他以后的调用中则不再被调用！&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;br /&gt;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/millen/aggbug/2299419.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/millen/archive/2011/12/23/2299419.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/millen/archive/2011/12/22/2297229.html</id><title type="text">SQL1159  Initialization error with DB2 .NET Data Provider, reason code 2；reason code 10</title><summary type="text">昨天遇到reason code 2这个错误，找了很久，网上说权限问题，按照处理办法解决后仍然不行，后来发现除了IBM.Data.DB2.dll，还需要拷贝db2app.dll这个文件到bin目录，如果安装了DB2 Data Provide for .NET,这两个dll应该都放到全局程序集中，但是奇怪的是db2app.dll这个dll没有进去，导致找不到这个dll。开发环境：visual studio 2010 数据库： IBM db2 9.7 for windows操作系统：windows xp sp3reason code 2错误提示：SQL1159 Initialization erro</summary><published>2011-12-22T01:38:00Z</published><updated>2011-12-22T01:38:00Z</updated><author><name>catch22</name><uri>http://www.cnblogs.com/millen/</uri></author><link rel="alternate" href="http://www.cnblogs.com/millen/archive/2011/12/22/2297229.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/millen/archive/2011/12/22/2297229.html"/><content type="html">&lt;p&gt;昨天遇到&amp;nbsp;reason code 2这个错误，找了很久，网上说权限问题，按照处理办法解决后仍然不行，后来发现除了IBM.Data.DB2.dll，还需要拷贝db2app.dll这个文件到bin目录，如果安装了DB2 Data Provide for .NET,这两个dll应该都放到全局程序集中，但是奇怪的是db2app.dll这个dll没有进去，导致找不到这个dll。&lt;/p&gt;&lt;p&gt;开发环境：visual studio 2010 &lt;/p&gt;&lt;p&gt;数据库： IBM db2 9.7&amp;nbsp; for windows&lt;/p&gt;&lt;p&gt;操作系统：windows xp sp3&lt;/p&gt;&lt;p&gt;&amp;nbsp;reason code 2错误提示：&lt;/p&gt;&lt;p&gt;SQL1159&amp;nbsp; Initialization error with DB2 .NET Data Provider, reason code 2, tokens E:\SourceCode\DB2Test\DB2Test\bin\db2app.dll, , Process Owner: XQUANT-BFAA77C8\Administrator&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;reason code 10错误提示：&lt;/p&gt;&lt;p&gt;SQL1159&amp;nbsp; Initialization error with DB2 .NET Data Provider, reason code 2, tokens 0.0.0 E:\SourceCode\DB2Test\DB2Test\bin\db2app.dll&lt;/p&gt;&lt;p&gt;&amp;nbsp;reason code 10的错误，根据tokens返回值提示是由于权限问题，将ASP.NET用户加入到DB2ADMINS用户组，重启IIS解决。参考IBM的官网：&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;h1 style="padding-bottom: 0px"&gt;SQL1159 rc=10 when running a DB2 .NET application&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="position: relative; padding-bottom: 15px; margin-top: 0px; width: 150px; left: 590px; findfakeobj: 1" id="ibm-social-tools" jquery16108760130875784093="29"&gt;&lt;ul&gt;&lt;li&gt;&lt;a class="ibm-share-print" title="打印本页面" href="https://www-304.ibm.com/support/docview.wss?uid=swg21413731#" rel="print" jquery16108760130875784093="30"&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="ibm-share-email" title="用电子邮件发送本页面" href="https://www-304.ibm.com/support/docview.wss?uid=swg21413731#" rel="email" jquery16108760130875784093="31"&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div id="ibm-content-body"&gt;&lt;div id="ibm-content-main"&gt;&lt;!-- TwoX body.doc --&gt;&lt;div class="ibm-container ibm-alternate"&gt;&lt;!--BEGIN MAIN BODY CONTENT--&gt;&lt;!--BEGIN CONTENT--&gt;&lt;p&gt;&lt;strong&gt;Technote (troubleshooting)&lt;/strong&gt;&lt;/p&gt;&lt;div class="ibm-container-body"&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Problem(Abstract)&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;A DB2 .NET application may receive an exception as follows: &lt;br /&gt;SQL1159 Initialization error with DB2 .NET Data Provider, reason code 10, tokens 0.0.0, 9.5.3&lt;br /&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&lt;strong&gt;Cause&lt;/strong&gt;&lt;/p&gt;&lt;div class="ibm-domino-rtf"&gt;&lt;p&gt;An SQL1159 error may be returned if the DB2 .NET data provider had a problem during initialization. &lt;br /&gt;&lt;br /&gt;When the DB2 .NET data provider is initialized it will perform some checks to ensure that the DB2 .NET data provider can be used properly. One of those checks is to see if it can execute a function from within the DB2 native client library called db2app.dll, and before that can be done it tries to load the db2app.dll library in memory.&lt;br /&gt;&lt;br /&gt;Several different reason codes can be returned with the SQL1159 exception, but reason code 10 occurs when there is a mismatch between the DB2 native client library (db2app.dll) and the DB2 .NET data provider library (IBM.Data.DB2.dll). &lt;/p&gt;&lt;p&gt;SQL1159 reason code 10 will return two tokens. The first token is the version of the DB2 client library, and the second token is the version of the DB2 .NET data provider. &lt;/p&gt;&lt;p&gt;If the version of the DB2 client library is returned as 0.0.0, then that means that there was a problem during the initialization of the db2app.dll library. &lt;/p&gt;&lt;p&gt;There are potentially two reasons why a token of 0.0.0 is returned for the native DB2 client library. &lt;/p&gt;&lt;p&gt;The first is that the db2app.dll is not compatible with the version of the DB2 client that is installed. The second is that there was a permission problem when trying to use the db2app.dll library with the application process.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Resolving the problem&lt;/strong&gt;&lt;/p&gt;&lt;div class="ibm-domino-rtf"&gt;&lt;p&gt;&lt;u&gt;Incompatible db2app.dll version&lt;br /&gt;&lt;/u&gt;Every DB2 fixpak and release has its own version of the db2app.dll library. The file size and signature will be different for each fixpak and release. It is very important that when DB2 is installed that the db2app.dll library is the one that came from that level of DB2 that is being installed.&lt;br /&gt;&lt;br /&gt;DB2 will update the db2app.dll library during the install of a fixpak or during the migration from one release to another. If there was a problem updating the db2app.dll, DB2 will document that in its installation log file. &lt;br /&gt;&lt;br /&gt;Here is an example of a typical error in the DB2 install log when the db2app.dll could not be updated: &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;InstallFiles: File: db2app.dll, Directory: C:\Program Files\IBM\SQLLIB\BIN\, Size: 9680160&lt;br /&gt;Info 1603.The file C:\Program Files\IBM\SQLLIB\BIN\db2app.dll is being held in use. Close that application and retry.&lt;br /&gt;MSI (s) (CC:B0) [11:18:48:389]: Product: DB2 Connect Server - DB2COPY1. The file C:\Program Files\IBM\SQLLIB\BIN\db2app.dll is being held in use by the following process Name: msiexec , Id 5392.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If this was the case, then it is important that all applications were shut down before upgrading DB2. This includes any applications that run as Windows services, such as an application server that might be making DB2 connections. The above error is a result of an application holding a lock on the db2app.dll file, thus disallowing DB2 from updating the file. &lt;/p&gt;&lt;p&gt;To verify that the db2app.dll library is in fact compatible with the DB2 level, issue the &lt;strong&gt;&lt;em&gt;db2level&lt;/em&gt;&lt;/strong&gt; command, and then compare the level with the file version of the db2app.dll. To retrieve the file version, find the db2app.dll using Windows Explorer and right-click on it and go to Properties-&amp;gt;Version. &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;u&gt;Invalid priviliges&lt;br /&gt;&lt;/u&gt;When the db2app.dll library is initialized by the DB2 .NET data provider, it initializes an application environment. This process will ensure that the db2app.dll library can be used. Some of the things it does is it checks to see what DB2 environment variables are set, and it checks things like the client-side database manager configuration file. If the DB2 .NET data provider could not initialize the application environment properly then DB2 .NET will return 0.0.0 for the native DB2 client library version. &lt;/p&gt;&lt;p&gt;The most common reason why the initialization of the application environment fails is because of invalid privileges. And the most common reason why there are invalid privileges is if DB2 Extended Security is enabled, and the userid that the application process runs under is not a member of either the DB2ADMNS or the DB2USERS groups. &lt;/p&gt;&lt;p&gt;&lt;br /&gt;If DB2 Extended Security is enabled (this is the default behavior for DB2 installations), then it is mandatory that any DB2 'user' belongs to either the DB2ADMNS or the DB2USERS group. This is not just the userid that is used during authentication with DB2, but it also includes the owner of the application process. &lt;/p&gt;&lt;p&gt;&lt;br /&gt;Some application processes like the w3wp.exe process (which is a process used by Microsoft Information Integrator (IIS)) can run under a different userid than the one that connects to DB2. It is important that this user belongs to the proper DB2 Extended Security group, if DB2 Extended Security is enabled. &lt;/p&gt;&lt;p&gt;If running IIS 7, the default account used for anonymous access is called "IUSR". This user can be added to the extended security group to resolve this error. &lt;/p&gt;&lt;p&gt;To determine what userid is actually trying to use the .NET application then you can use a utility called the Microsoft&amp;#174; Process Monitor located &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx"&gt;here&lt;/a&gt;: &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;That utility will track all file and registry operations issued by any Windows process. If that process failed to read a file, then it will record an ACCESS DENIED error. Microsoft&amp;#174; Process Monitor can show who the userid was that tried to access the file when it failed. Adding that userid to the proper DB2 Extended Security group should then resolve that problem. The userid that is used by the application can be impersonated by another userid. Microsoft&amp;#174; Process Monitor will show who the Impersonating userid is, and that is the userid that needs to be added to the proper DB2 Extended Security group. &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;If DB2 Extended Security is enabled, and the preference is to not use DB2 Extended Security, then the ideal thing to do would be to uninstall DB2 and reinstall it without the DB2 Extended Security option. &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;If Microsoft Windows&amp;#174; 7 or Microsoft Windows Vista&amp;#174; are being used, and DB2 Extended Security is disabled, the problem may still occur due to invalid privileges, specifically if the userid that installed DB2 was not given elevated administrator rights. Typically when User Account Control (UAC) is enabled, users with administrator rights run with least user privileges. These rights can be elevated to perform administrative tasks. If a non-elevated administrator installed DB2 then certain Windows registry settings used by DB2 may not be set properly, preventing the DB2 .NET data provider from working properly. It is important to ensure that a userid with elevated administrator privileges has installed DB2 to resolve this problem. &lt;br /&gt;&amp;nbsp; &lt;/p&gt;&lt;p&gt;If using the IBM Data Server Driver Package, then you could also get this error if you were hitting APAR &lt;a href="https://www-304.ibm.com/support/docview.wss?uid=swg1JR30952"&gt;JR30952&lt;/a&gt; (that is fixed in DB2 v9.5 FP5) or APAR &lt;a href="https://www-304.ibm.com/support/docview.wss?uid=swg1IC63971"&gt;IC63971&lt;/a&gt; (that is fixed in DB2 v9.7 FP1). DB2 Extended Security was being enabled implicitly for the IBM Data Server Driver when it should not have been, and that would result in this error since DB2 would think that the userid running the application would not be a member in the proper DB2 Extended Security group.&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://www.cnblogs.com/millen/aggbug/2297229.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/millen/archive/2011/12/22/2297229.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/millen/archive/2011/12/14/2287700.html</id><title type="text">DB2中的VARCHAR_FORMAT函数</title><summary type="text">VARCHAR_FORMAT scalar functionCharacter to varchar&gt;&gt;-VARCHAR_FORMAT--(--character-expression--)------------------&gt;&lt;Timestamp to varchar:&gt;&gt;-VARCHAR_FORMAT--(--timestamp-expression--+--------------------------------------+--)-&gt;&lt; '-,--format-string--+------------...</summary><published>2011-12-14T07:59:00Z</published><updated>2011-12-14T07:59:00Z</updated><author><name>catch22</name><uri>http://www.cnblogs.com/millen/</uri></author><link rel="alternate" href="http://www.cnblogs.com/millen/archive/2011/12/14/2287700.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/millen/archive/2011/12/14/2287700.html"/><content type="html">&lt;h1 class="title topictitle1"&gt;&lt;span style="font-size: 12pt"&gt;VARCHAR_FORMAT &lt;/span&gt;&lt;span style="font-size: 12pt" class="ph"&gt;scalar function&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div class="body refbody"&gt;&lt;div class="section"&gt;&lt;p class="p"&gt;&lt;strong class="ph b"&gt;Character to varchar&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;&lt;div class="section refsyn"&gt;&lt;span&gt;&lt;img border="0" alt="Read syntax diagram" src="http://www.cnblogs.com/millen/c.gif" longdesc="r0007110syn1.html" /&gt;&lt;/span&gt;&lt;a href="#d1929425e61"&gt;&lt;img border="0" alt="Skip visual syntax diagram" src="http://www.cnblogs.com/millen/c.gif" /&gt;&lt;/a&gt;&lt;br/&gt;&amp;gt;&amp;gt;-VARCHAR_FORMAT--(--&lt;em&gt;character-expression&lt;/em&gt;--)------------------&amp;gt;&amp;lt;&lt;br/&gt;&lt;br/&gt;&lt;a name="d1929425e61"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="section"&gt;&lt;p class="p"&gt;&lt;strong class="ph b"&gt;Timestamp to varchar:&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;&lt;div class="section refsyn"&gt;&lt;span&gt;&lt;img border="0" alt="Read syntax diagram" src="http://www.cnblogs.com/millen/c.gif" longdesc="r0007110syn2.html" /&gt;&lt;/span&gt;&lt;a href="#d1929425e77"&gt;&lt;img border="0" alt="Skip visual syntax diagram" src="http://www.cnblogs.com/millen/c.gif" /&gt;&lt;/a&gt;&lt;br/&gt;&amp;gt;&amp;gt;-VARCHAR_FORMAT--(--&lt;em&gt;timestamp-expression&lt;/em&gt;--+--------------------------------------+--)-&amp;gt;&amp;lt;&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;                                         '-,--&lt;em&gt;format-string&lt;/em&gt;--+----------------+-'   &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;                                                             '-,--&lt;em&gt;locale-name&lt;/em&gt;-'     &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br/&gt;&lt;br/&gt;&lt;a name="d1929425e77"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="section"&gt;&lt;p class="p"&gt;&lt;strong class="ph b"&gt;Decimal floating-point to varchar:&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;&lt;div class="section refsyn"&gt;&lt;span&gt;&lt;img border="0" alt="Read syntax diagram" src="http://www.cnblogs.com/millen/c.gif" longdesc="r0007110syn3.html" /&gt;&lt;/span&gt;&lt;a href="#d1929425e105"&gt;&lt;img border="0" alt="Skip visual syntax diagram" src="http://www.cnblogs.com/millen/c.gif" /&gt;&lt;/a&gt;&lt;br/&gt;&amp;gt;&amp;gt;-VARCHAR_FORMAT--(--&lt;em&gt;decimal-floating-point-expression&lt;/em&gt;--+------------------+--)-&amp;gt;&amp;lt;&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;                                                      '-,--&lt;em&gt;format-string&lt;/em&gt;-'   &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br/&gt;&lt;br/&gt;&lt;a name="d1929425e105"&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="section"&gt;&lt;p class="p"&gt;The schema is SYSIBM.&lt;/p&gt;&lt;p class="p"&gt;The VARCHAR_FORMAT function returns a character string based on applying the specified format string argument, if provided, to the value of the first argument. If any argument of the VARCHAR_FORMAT function can be null, the result can be null; if any argument is null, the result is the null value. &lt;/p&gt;&lt;p class="p"&gt;The expression must be formatted according to a specified character template.&lt;/p&gt;&lt;dl class="dl"&gt;&lt;dt class="dt dlterm"&gt;&lt;span class="ph"&gt;Character to varchar&lt;/span&gt;&lt;/dt&gt;&lt;dd class="dd"&gt;&lt;dl class="dl parml"&gt;&lt;dt class="dt pt dlterm"&gt;&lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;character-expression&lt;/span&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd class="dd pd"&gt;An expression that returns a value that must be a built-in CHAR or VARCHAR data type. In a Unicode database, if a supplied argument is a GRAPHIC or VARGRAPHIC data type, it is first converted to VARCHAR before evaluating the function. &lt;/dd&gt;&lt;/dl&gt;&lt;p class="p"&gt;The result is a VARCHAR with a length attribute that matches the length attribute of the argument. The value of the result is the same as the value of &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;character-expression&lt;/span&gt;&lt;/span&gt;. &lt;/p&gt;&lt;/dd&gt;&lt;dt class="dt dlterm"&gt;&lt;span class="ph"&gt;Timestamp to varchar&lt;/span&gt;&lt;/dt&gt;&lt;dd class="dd"&gt;&lt;dl class="dl parml"&gt;&lt;dt class="dt pt dlterm"&gt;&lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;timestamp-expression&lt;/span&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd class="dd pd"&gt;An expression that returns a value that must be a DATE or TIMESTAMP, or a valid string representation of a date or timestamp that is not a CLOB or DBCLOB. If the argument is a string, the &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;format-string&lt;/span&gt;&lt;/span&gt; argument must also be specified. In a Unicode database, if a supplied argument is a graphic string representation of a data, time, or timestamp, it is first converted to a character string before evaluating the function. &lt;p class="p"&gt;If &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;timestamp-expression&lt;/span&gt;&lt;/span&gt; is a DATE or a valid string representation of a date, it is first converted to a TIMESTAMP(0) value, assuming a time of exactly midnight (00.00.00).&lt;/p&gt;&lt;p class="p"&gt;For the valid formats of string representations of datetime values, see &lt;span class="q"&gt;"String representations of datetime values"&lt;/span&gt; in &lt;span class="q"&gt;"Datetime values"&lt;/span&gt;.&lt;/p&gt;&lt;/dd&gt;&lt;dt class="dt pt dlterm"&gt;&lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;format-string&lt;/span&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd class="dd pd"&gt;&lt;span class="ph"&gt;The expression must return a value that is a built-in CHAR, VARCHAR, numeric, or datetime data type. If the value is not a CHAR or VARCHAR data type, it is implicitly cast to VARCHAR before evaluating the function. In a Unicode database, if the supplied argument is a GRAPHIC or VARGRAPHIC data type, it is first converted to VARCHAR before evaluating the function. The actual length must not be greater than 254 bytes (SQLSTATE 22007). The value is a template for how &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;timestamp-expression&lt;/span&gt;&lt;/span&gt; is to be formatted.&lt;/span&gt; &lt;div class="p"&gt;A valid &lt;var class="keyword varname"&gt;format-string&lt;/var&gt; must contain a combination of the format elements listed below (SQLSTATE 22007). Two format elements can optionally be separated by one or more of the following separator characters: &lt;ul class="ul"&gt;&lt;li class="li"&gt;minus sign (-)&lt;/li&gt;&lt;li class="li"&gt;period (.)&lt;/li&gt;&lt;li class="li"&gt;slash (/)&lt;/li&gt;&lt;li class="li"&gt;comma (,)&lt;/li&gt;&lt;li class="li"&gt;apostrophe (')&lt;/li&gt;&lt;li class="li"&gt;semi-colon (;)&lt;/li&gt;&lt;li class="li"&gt;colon (:)&lt;/li&gt;&lt;li class="li"&gt;blank ( )&lt;/li&gt;&lt;/ul&gt;Separator characters can also be specified at the start or end of &lt;var class="keyword varname"&gt;format-string&lt;/var&gt;.&lt;/div&gt;&lt;div class="tablenoborder"&gt;&lt;a name="r0007110__fefvff"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;table id="r0007110__fefvff" class="table" border="1" rules="all" cellspacing="0" summary="" cellpadding="4" frame="border"&gt;&lt;caption&gt;&lt;span class="tablecap"&gt;Table 1. Format elements for the VARCHAR_FORMAT function&lt;/span&gt;&lt;/caption&gt;&lt;thead class="thead" align="left"&gt;&lt;tr class="row" valign="bottom"&gt;&lt;th id="d1929425e225" class="entry" valign="bottom"&gt;Format element&lt;/th&gt;&lt;th id="d1929425e227" class="entry" valign="bottom"&gt;Description&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody class="tbody"&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;AM or PM&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Meridian indicator (morning or evening) without periods. This format element is dependent on &lt;var class="keyword varname"&gt;locale-name&lt;/var&gt;, if specified; otherwise, it is dependent on the value of the special register CURRENT LOCALE LC_TIME.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;A.M. or P.M.&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Meridian indicator (morning or evening) with periods. This format element uses the exact strings &amp;#8216;A.M.' or &amp;#8216;P.M.' and is independent of the locale name in effect. &lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;CC&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;&lt;span class="ph"&gt;Century (01-99).&lt;/span&gt; If the last two digits of the four-digit year are zero, the result is the first two digits of the year; otherwise, the result is the first two digits of the year plus one.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;DAY, Day, or day&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Name of the day in uppercase, titlecase, or lowercase format. The language used is dependent on &lt;var class="keyword varname"&gt;locale-name&lt;/var&gt;, if specified; otherwise, it is dependent on the value of the special register CURRENT LOCALE LC_TIME.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;DY, Dy, or dy&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Abbreviated name of the day in uppercase, titlecase, or lowercase format. The language used is dependent on &lt;var class="keyword varname"&gt;locale-name&lt;/var&gt;, if specified; otherwise, it is dependent on the value of the special register CURRENT LOCALE LC_TIME.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;D&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Day of the week (1-7). The first day of the week is dependent on &lt;var class="keyword varname"&gt;locale-name&lt;/var&gt;, if specified; otherwise, it is dependent on the value of the special register CURRENT LOCALE LC_TIME.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;DD&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Day of month (01-31).&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;DDD&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Day of year (001-366).&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;&lt;span class="ph"&gt;FF or FF&lt;em class="ph i"&gt;n&lt;/em&gt;&lt;/span&gt;&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;&lt;span class="ph"&gt;Fractional seconds (0-999999999999). The number &lt;em class="ph i"&gt;n&lt;/em&gt; is used to specify the number of digits to include in the returned value. Valid values for &lt;em class="ph i"&gt;n&lt;/em&gt; are 1-12 with no leading zeros. &lt;span class="ph"&gt;Specifying FF is equivalent to specifying FF6. &lt;/span&gt;If the timestamp precision of &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;timestamp-expression&lt;/span&gt;&lt;/span&gt; is less than what is specified by the format, zero digits are padded onto the right of the specified digits.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;HH&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;HH behaves the same as HH12. &lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;HH12&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Hour of the day (01-12) in 12-hour format.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;HH24&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Hour of the day (00-24) in 24-hour format. &lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;IW&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;ISO week of the year (01-53). The week starts on Monday and includes seven days. Week 1 is the first week of the year to contain a Thursday, which is equivalent to the first week of the year to contain January 4.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;I&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;ISO year (0-9). The last digit of the year based on the ISO week that is returned.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;IY&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;ISO year (00-99). The last two digits of the year based on the ISO week that is returned.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;IYY&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;ISO year (000-999). The last three digits of the year based on the ISO week that is returned.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;IYYY&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;ISO year (0000-9999). The 4-digit year based on the ISO week that is returned.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;J&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Julian day (number of days since January 1, 4713 BC).&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;MI&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Minute (00-59).&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;MM&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Month (01-12).&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;NNNNNN&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Microseconds (000000-999999). Same as FF6.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;MONTH, Month, or month&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Name of the month in uppercase, titlecase, or lowercase format. The language used is dependent on &lt;var class="keyword varname"&gt;locale-name&lt;/var&gt;, if specified; otherwise, it is dependent on the value of the special register CURRENT LOCALE LC_TIME.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;MON, Mon, or mon&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Abbreviated name of the month in uppercase, titlecase, or lowercase format. The language used is dependent on &lt;var class="keyword varname"&gt;locale-name&lt;/var&gt;, if specified; otherwise, it is dependent on the value of the special register CURRENT LOCALE LC_TIME.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;Q&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Quarter (1-4), where the months January through March return 1.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;RR&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;RR behaves the same as YY.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;RRRR&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;RRRR behaves the same as YYYY.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;SS&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Seconds (00-59).&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;SSSSS&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Seconds since previous midnight (00000-86400).&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;W&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Week of the month (1-5), where week 1 starts on the first day of the month and ends on the seventh day.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;WW&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Week of the year (01-53), where week 1 starts on January 1 and ends on January 7.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;Y&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Last digit of the year (0-9).&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;YY&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Last two digits of the year (00-99).&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;YYY&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;Last three digits of the year (000-999).&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" headers="d1929425e225 "&gt;YYYY&lt;/td&gt;&lt;td class="entry" valign="top" headers="d1929425e227 "&gt;4-digit year (0000-9999).&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class="note note"&gt;&lt;span class="notetitle"&gt;Note:&lt;/span&gt; The format elements in &lt;a class="xref" href="http://www.cnblogs.com/millen/admin/r0007110.html#r0007110__fefvff"&gt;Table 1&lt;/a&gt; are not case sensitive, except for the following: &lt;ul class="ul"&gt;&lt;li class="li"&gt;AM, PM&lt;/li&gt;&lt;li class="li"&gt;A.M., P.M.&lt;/li&gt;&lt;li class="li"&gt;DAY, Day, day&lt;/li&gt;&lt;li class="li"&gt;DY, Dy, dy&lt;/li&gt;&lt;li class="li"&gt;D&lt;/li&gt;&lt;li class="li"&gt;MONTH, Month, month&lt;/li&gt;&lt;li class="li"&gt;MON, Mon, mon&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;p class="p"&gt;In cases where format elements are ambiguous, the case insensitive format elements will be considered first. For example, DDYYYY would be interpreted as DD followed by YYYY, rather than D followed by DY, followed by YYY.&lt;/p&gt;&lt;p class="p"&gt;If &lt;var class="keyword varname"&gt;format-string&lt;/var&gt; is not specified, the format used is based on the value of the special register CURRENT LOCALE LC_TIME.&lt;/p&gt;&lt;/dd&gt;&lt;dt class="dt pt dlterm"&gt;&lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;locale-name&lt;/span&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd class="dd pd"&gt;A character constant that specifies the locale used for the following format elements: &lt;ul class="ul"&gt;&lt;li class="li"&gt;AM, PM&lt;/li&gt;&lt;li class="li"&gt;DAY, Day, day&lt;/li&gt;&lt;li class="li"&gt;DY, Dy, dy&lt;/li&gt;&lt;li class="li"&gt;D&lt;/li&gt;&lt;li class="li"&gt;MONTH, Month, month&lt;/li&gt;&lt;li class="li"&gt;MON, Mon, mon&lt;/li&gt;&lt;/ul&gt;&lt;p class="p"&gt;The value of &lt;var class="keyword varname"&gt;locale-name&lt;/var&gt; is not case sensitive and must be a valid locale (SQLSTATE 42815). &lt;span class="ph"&gt;For information on valid locales and their naming, see &lt;span class="q"&gt;"Locale names for SQL and XQuery"&lt;/span&gt;.&lt;/span&gt; If &lt;var class="keyword varname"&gt;locale-name&lt;/var&gt; is not specified, the value of the special register CURRENT LOCALE LC_TIME is used.&lt;/p&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;p class="p"&gt;The result is a representation of &lt;var class="keyword varname"&gt;timestamp-expression&lt;/var&gt; in the format specified by &lt;var class="keyword varname"&gt;format-string&lt;/var&gt;. The &lt;var class="keyword varname"&gt;format-string&lt;/var&gt; is interpreted as a series of format elements that can optionally be separated by one or more separator characters. A string of characters in &lt;var class="keyword varname"&gt;format-string&lt;/var&gt; is interpreted as the longest matching format element in &lt;a class="xref" href="http://www.cnblogs.com/millen/admin/r0007110.html#r0007110__fefvff"&gt;Table 1&lt;/a&gt;. If two format elements containing the same characters are not delimited by a separator character, the specification is interpreted, starting from the left, as the longest matching format element in the table, and continues until matches are found for the remainder of the format string. For example, 'YYYYYYDD' is interpreted as the format elements 'YYYY', 'YY', and 'DD'.&lt;/p&gt;&lt;p class="p"&gt;The result is a varying-length character string. The length attribute is 254. The &lt;var class="keyword varname"&gt;format-string&lt;/var&gt; determines the actual length of the result. If the resulting string exceeds the length attribute of the result, the result is truncated.&lt;/p&gt;&lt;dl class="dl"&gt;&lt;dt class="dt dlterm"&gt;&lt;span class="ph"&gt;Decimal floating-point to varchar&lt;/span&gt;&lt;/dt&gt;&lt;dd class="dd"&gt;&lt;dl class="dl parml"&gt;&lt;dt class="dt pt dlterm"&gt;&lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd class="dd pd"&gt;&lt;span class="ph"&gt;An expression that returns a value of any built-in numeric data type. If the argument is not a decimal floating-point value, it is converted to DECFLOAT(34) for processing.&lt;/span&gt;&lt;/dd&gt;&lt;dt class="dt pt dlterm"&gt;&lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;format-string&lt;/span&gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd class="dd pd"&gt;&lt;span class="ph"&gt;The expression must return a value that is a built-in CHAR, VARCHAR, numeric, or datetime data type. If the value is not a CHAR or VARCHAR data type, it is implicitly cast to VARCHAR before evaluating the function. In a Unicode database, if the supplied argument is a GRAPHIC or VARGRAPHIC data type, it is first converted to VARCHAR before evaluating the function.&lt;/span&gt; The actual length must not be greater than 254 bytes (SQLSTATE 22018). The value is a template for how &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is to be formatted. Format elements specified as a prefix can be used only at the beginning of the template. Format elements specified as a suffix can be used only at the end of the template. The format elements are case sensitive. The template must not contain more than one of the MI, S, or PR format elements (SQLSTATE 22018). &lt;div class="p"&gt;&lt;div class="tablenoborder"&gt;&lt;table class="table" border="1" rules="all" cellspacing="0" summary="" cellpadding="4" frame="border"&gt;&lt;caption&gt;&lt;span class="tablecap"&gt;Table 2. Format elements for the VARCHAR_FORMAT function&lt;/span&gt;&lt;/caption&gt;&lt;thead class="thead" align="left"&gt;&lt;tr class="row" valign="bottom"&gt;&lt;th id="d1929425e560" class="entry" valign="bottom" width="13.06%"&gt;Format element&lt;/th&gt;&lt;th id="d1929425e562" class="entry" valign="bottom" width="86.93%"&gt;Description&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody class="tbody"&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" width="13.06%" headers="d1929425e560 "&gt;0&lt;/td&gt;&lt;td class="entry" valign="top" width="86.93%" headers="d1929425e562 "&gt;Each 0 represents a significant digit. Leading zeros in a number are displayed as zeros.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" width="13.06%" headers="d1929425e560 "&gt;9&lt;/td&gt;&lt;td class="entry" valign="top" width="86.93%" headers="d1929425e562 "&gt;Each 9 represents a significant digit. Leading zeros in a number are displayed as blanks.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" width="13.06%" headers="d1929425e560 "&gt;MI&lt;/td&gt;&lt;td class="entry" valign="top" width="86.93%" headers="d1929425e562 "&gt;Suffix: If &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is a negative number, a trailing minus sign (&amp;#8722;) is included in the result. If &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is a positive number, a trailing blank is included in the result.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" width="13.06%" headers="d1929425e560 "&gt;S&lt;/td&gt;&lt;td class="entry" valign="top" width="86.93%" headers="d1929425e562 "&gt;Prefix: If &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is a negative number, a leading minus sign (&amp;#8722;) is included in the result. If &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is a positive number, a leading plus sign (+) is included in the result.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" width="13.06%" headers="d1929425e560 "&gt;PR&lt;/td&gt;&lt;td class="entry" valign="top" width="86.93%" headers="d1929425e562 "&gt;Suffix: If &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is a negative number, a leading less than character (&amp;lt;) and a trailing greater than character (&amp;gt;) are included in the result. If &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is a positive number, a leading space and a trailing space are included in the result.&lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" width="13.06%" headers="d1929425e560 "&gt;$&lt;/td&gt;&lt;td class="entry" valign="top" width="86.93%" headers="d1929425e562 "&gt;Prefix: A leading dollar sign ($) is included in the result. &lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" width="13.06%" headers="d1929425e560 "&gt;,&lt;/td&gt;&lt;td class="entry" valign="top" width="86.93%" headers="d1929425e562 "&gt;Specifies that a comma be included in that location in the result. This comma is used as a group separator. &lt;/td&gt;&lt;/tr&gt;&lt;tr class="row"&gt;&lt;td class="entry" valign="top" width="13.06%" headers="d1929425e560 "&gt;.&lt;/td&gt;&lt;td class="entry" valign="top" width="86.93%" headers="d1929425e562 "&gt;Specifies that a period be included in that location in the result. This period is used as a decimal point.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;p class="p"&gt;If format-string is not specified, &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is formatted in the form of an SQL decimal floating-point constant. If &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is negative, the first character of the result is a minus sign; otherwise, the first character is a digit. If &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is zero, the result is 0.&lt;/p&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;p class="p"&gt;The result is a varying-length character string representation of &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt;. The length attribute is 254. The actual length of the result is determined by the &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;format-string&lt;/span&gt;&lt;/span&gt;, if specified; otherwise, the actual length of the result is the smallest number of characters that can represent the value of &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt;. If the resulting string exceeds the length attribute of the result, the result will be truncated.&lt;/p&gt;&lt;p class="p"&gt;If the value of &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is the special value Infinity, sNaN, or NaN, the strings "INFINITY", "SNAN", and "NAN", respectively, are returned. If the special value is negative, the first character of the result is a minus sign. The decimal floating-point special value sNaN does not result in an exception when converted to a string.&lt;/p&gt;&lt;p class="p"&gt;If &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;format-string&lt;/span&gt;&lt;/span&gt; does not include any of the format elements MI, S, or PR, and the value of &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is negative, then a minus sign (&amp;#8722;) will be included in the result; otherwise, a blank will be included in the result.&lt;/p&gt;&lt;p class="p"&gt;If the number of digits to the left of the decimal point in &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is greater than the number of digits to the left of the decimal point in &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;format-string&lt;/span&gt;&lt;/span&gt;, the result is a string of number sign (#) characters. If the number of digits to the right of the decimal point in &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; is greater than the number of digits to the right of the decimal point in &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;format-string&lt;/span&gt;&lt;/span&gt;, the result is &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;decimal-floating-point-expression&lt;/span&gt;&lt;/span&gt; rounded to the number of digits to the right of the decimal point in &lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;format-string&lt;/span&gt;&lt;/span&gt;. The DECFLOAT rounding mode will not be used. The rounding behavior of VARCHAR_FORMAT corresponds to a value of ROUND_HALF_UP.&lt;/p&gt;&lt;p class="p"&gt;The code page of the result is the code page of the section.&lt;/p&gt;&lt;/div&gt;&lt;div class="section"&gt;&lt;h2 class="title sectiontitle"&gt;Notes:&lt;/strong&gt;&lt;/p&gt;&lt;ul class="ul"&gt;&lt;li class="li"&gt;&lt;strong class="ph b"&gt;&lt;em class="ph i"&gt;Julian and Gregorian calendar&lt;/em&gt;&lt;/strong&gt;: For Timestamp to varchar, the transition from the Julian calendar to the Gregorian calendar on 15 October 1582 is taken into account by this function.&lt;/li&gt;&lt;li class="li"&gt;&lt;strong class="ph b"&gt;&lt;em class="ph i"&gt;Determinism:&lt;/em&gt;&lt;/strong&gt; VARCHAR_FORMAT is a deterministic function. However, the following invocations of the function depend on the value of the special register CURRENT LOCALE LC_TIME. &lt;ul class="ul"&gt;&lt;li class="li"&gt;Timestamp to varchar, when format-string is not explicitly specified, or when locale-name is not explicitly specified and one of the following is true: &lt;ul class="ul"&gt;&lt;li class="li"&gt;&lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;format-string&lt;/span&gt;&lt;/span&gt; is not a constant &lt;/li&gt;&lt;li class="li"&gt;&lt;span class="ph synph"&gt;&lt;span class="ph var"&gt;format-string&lt;/span&gt;&lt;/span&gt; is a constant and includes format elements that are locale sensitive &lt;/li&gt;&lt;/ul&gt;These invocations that depend on the value of a special register cannot be used wherever special registers cannot be used (SQLSTATE 42621 or 428EC ). &lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li class="li"&gt;&lt;strong class="ph b"&gt;&lt;em class="ph i"&gt;Syntax alternatives:&lt;/em&gt;&lt;/strong&gt; TO_CHAR is a synonym for VARCHAR_FORMAT.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="section"&gt;&lt;h2 class="title sectiontitle"&gt;Examples&lt;/strong&gt;&lt;/p&gt;&lt;ul class="ul"&gt;&lt;li class="li"&gt;Display the table names and creation timestamps for all of the system tables whose name starts with 'SYSU'.    &lt;strong class="ph b"&gt;SELECT VARCHAR&lt;/strong&gt;(TABNAME, 20) &lt;strong class="ph b"&gt;AS&lt;/strong&gt; TABLE_NAME,&lt;br/&gt;     &lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')&lt;br/&gt;       &lt;strong class="ph b"&gt;AS&lt;/strong&gt; CREATION_TIME&lt;br/&gt;     &lt;strong class="ph b"&gt;FROM&lt;/strong&gt; SYSCAT.TABLES&lt;br/&gt;     &lt;strong class="ph b"&gt;WHERE&lt;/strong&gt; TABNAME &lt;strong class="ph b"&gt;LIKE&lt;/strong&gt; 'SYSU%'This example returns the following:    TABLE_NAME           CREATION_TIME&lt;br/&gt;   -------------------- -------------------&lt;br/&gt;   SYSUSERAUTH          2000-05-19 08:18:56&lt;br/&gt;   SYSUSEROPTIONS       2000-05-19 08:18:56&lt;/li&gt;&lt;li class="li"&gt;Assume that the variable TMSTAMP &lt;span class="ph"&gt;is defined as a TIMESTAMP and&lt;/span&gt; has the following value: 2007-03-09-14.07.38.123456. The following examples show several invocations of the function and the resulting string values. The result &lt;span class="ph"&gt;data&lt;/span&gt; type in each case is VARCHAR(254).&lt;strong class="ph b"&gt;Function invocation&lt;/strong&gt;                          &lt;strong class="ph b"&gt;Result&lt;/strong&gt;&lt;br/&gt;&lt;strong class="ph b"&gt;-------------------                          ------&lt;/strong&gt;&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'YYYYMMDDHHMISSFF3')  20070309020738123&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'YYYYMMDDHH24MISS')   20070309140738&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'YYYYMMDDHHMI')       200703090207&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'DD/MM/YY')           09/03/07&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'MM-DD-YYYY')         03-09-2007&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'J')                  2454169&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'Q')                  1&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'W')                  2&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'IW')                 10&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'WW')                 10&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'Month','en_US')      March &lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'MONTH','en_US')      MARCH &lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'MON','en_US')        MAR &lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'Day','en_US')        Friday &lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'DAY','en_US')        FRIDAY &lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'Dy','en_US')         Fri &lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'Month','de_DE')      M&amp;#228;rz &lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'MONTH','de_DE')      M&amp;#196;RZ &lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'MON','de_DE')        MRZ &lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'Day','de_DE')        Freitag &lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'DAY','de_DE')        FREITAG &lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(TMSTAMP,'Dy','de_DE')         Fr&lt;/li&gt;&lt;li class="li"&gt;Assume that the variable DTE is &lt;span class="ph"&gt;defined as&lt;/span&gt; a DATE and has the following value: 2007-03-09. The following examples show several invocations of the function and the resulting string values. The result &lt;span class="ph"&gt;data&lt;/span&gt; type in each case is VARCHAR(254).&lt;strong class="ph b"&gt;Function invocation&lt;/strong&gt;                          &lt;strong class="ph b"&gt;Result&lt;/strong&gt;&lt;br/&gt;&lt;strong class="ph b"&gt;-------------------                          ------&lt;/strong&gt;&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(DTE,'YYYYMMDD')               20070309&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(DTE,'YYYYMMDDHH24MISS')       20070309000000&lt;/li&gt;&lt;li class="li"&gt;Assume that the variables POSNUM and NEGNUM are &lt;span class="ph"&gt;defined as&lt;/span&gt; DECFLOAT(34) and have the following values: 1234.56 and -1234.56, respectively. The following examples show several invocations of the function and the resulting string values. The result &lt;span class="ph"&gt;data&lt;/span&gt; type in each case is VARCHAR(254).&lt;strong class="ph b"&gt;Function invocation&lt;/strong&gt;                          &lt;strong class="ph b"&gt;Result&lt;/strong&gt;&lt;br/&gt;&lt;strong class="ph b"&gt;-------------------                          ------&lt;/strong&gt;&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(POSNUM)                       '1234.56'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(NEGNUM)                       '-1234.56'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(POSNUM,'9999.99')             '1234.56'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(NEGNUM,'9999.99')             '1234.56'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(POSNUM,'99999.99')            ' 1234.56'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(NEGNUM,'99999.99')            ' 1234.56'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(POSNUM,'00000.00')            '01234.56'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(NEGNUM,'00000.00')            '01234.56'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(POSNUM,'9999.99MI')           '1234.56 '&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(NEGNUM,'9999.99MI')           '1234.56-'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(POSNUM,'S9999.99')            '+1234.56'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(NEGNUM,'S9999.99')            '-1234.56'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(POSNUM,'9999.99PR')           ' 1234.56 '&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(NEGNUM,'9999.99PR')           '&amp;lt;1234.56&amp;gt;'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(POSNUM,'S$9,999.99')          '+$1,234.56'&lt;br/&gt;&lt;strong class="ph b"&gt;VARCHAR_FORMAT&lt;/strong&gt;(NEGNUM,'S$9,999.99')          '-$1,234.56'&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://www.cnblogs.com/millen/aggbug/2287700.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/millen/archive/2011/12/14/2287700.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/millen/archive/2011/12/14/2287684.html</id><title type="text">数据类型格式化函数(PostgreSQL),ORACLE支持</title><summary type="text">9.8. 数据类型格式化函数PostgreSQL 格式化函数提供一套有效的工具用于把各种数据类型 （日期/时间，integer，floating point，numeric） 转换成格式化的字符串以及反过来从格式化的字符串转换成 指定的数据类型。 Table 9-20 列出了这些函数。 这些函数都遵循一个公共的调用习惯： 第一个参数是待格式化的值，而第二个是一个定义输出或输出格式的模板。 to_timestamp 函数也能接受一个 double precision 参数， 把它从 Unix 纪元转换成 timestamp with time zone。 （Integer Unix 纪元隐含地转</summary><published>2011-12-14T07:50:00Z</published><updated>2011-12-14T07:50:00Z</updated><author><name>catch22</name><uri>http://www.cnblogs.com/millen/</uri></author><link rel="alternate" href="http://www.cnblogs.com/millen/archive/2011/12/14/2287684.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/millen/archive/2011/12/14/2287684.html"/><content type="html">&lt;h1 class="SECT1"&gt;&lt;a name="FUNCTIONS-FORMATTING"&gt;9.8. 数据类型格式化函数&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;a name="AEN9944"&gt;&lt;/a&gt;&lt;a name="AEN9946"&gt;&lt;/a&gt;&lt;a name="AEN9948"&gt;&lt;/a&gt;&lt;a name="AEN9950"&gt;&lt;/a&gt;&lt;a name="AEN9952"&gt;&lt;/a&gt;&lt;p&gt;&lt;span class="PRODUCTNAME"&gt;PostgreSQL&lt;/span&gt; 格式化函数提供一套有效的工具用于把各种数据类型 （日期/时间，integer，floating point，numeric） 转换成格式化的字符串以及反过来从格式化的字符串转换成 指定的数据类型。 &lt;a href="http://www.pgsqldb.org/pgsqldoc-cvs/functions-formatting.html#FUNCTIONS-FORMATTING-TABLE"&gt;Table 9-20&lt;/a&gt; 列出了这些函数。 这些函数都遵循一个公共的调用习惯： 第一个参数是待格式化的值，而第二个是一个定义输出或输出格式的模板。 &lt;/p&gt;&lt;p&gt;&lt;code class="FUNCTION"&gt;to_timestamp&lt;/code&gt; 函数也能接受一个 &lt;tt class="TYPE"&gt;double precision&lt;/tt&gt; 参数， 把它从 Unix 纪元转换成 &lt;tt class="TYPE"&gt;timestamp with time zone&lt;/tt&gt;。 （&lt;tt class="TYPE"&gt;Integer&lt;/tt&gt; Unix 纪元隐含地转换成了 &lt;tt class="TYPE"&gt;double precision&lt;/tt&gt;。） &lt;/p&gt;&lt;div class="TABLE"&gt;&lt;a name="FUNCTIONS-FORMATTING-TABLE"&gt;&lt;/a&gt;&lt;p&gt;&lt;strong&gt;Table 9-20. 格式化函数&lt;/strong&gt;&lt;/p&gt;&lt;table class="CALSTABLE" border="1"&gt;&lt;colgroup&gt;&lt;col&gt;&lt;col&gt;&lt;col&gt;&lt;col&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;函数&lt;/th&gt;&lt;th&gt;返回类型&lt;/th&gt;&lt;th&gt;描述&lt;/th&gt;&lt;th&gt;例子&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;&lt;code class="FUNCTION"&gt;to_char&lt;/code&gt;(&lt;tt class="TYPE"&gt;timestamp&lt;/tt&gt;, &lt;tt class="TYPE"&gt;text&lt;/tt&gt;)&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="TYPE"&gt;text&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;把时间戳转换成字串&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(current_timestamp, 'HH12:MI:SS')&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;&lt;code class="FUNCTION"&gt;to_char&lt;/code&gt;(&lt;tt class="TYPE"&gt;interval&lt;/tt&gt;, &lt;tt class="TYPE"&gt;text&lt;/tt&gt;)&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="TYPE"&gt;text&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;把时间间隔转为字串&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(interval '15h&amp;nbsp;2m&amp;nbsp;12s', 'HH24:MI:SS')&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;&lt;code class="FUNCTION"&gt;to_char&lt;/code&gt;(&lt;tt class="TYPE"&gt;int&lt;/tt&gt;, &lt;tt class="TYPE"&gt;text&lt;/tt&gt;)&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="TYPE"&gt;text&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;把整数转换成字串&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(125, '999')&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;&lt;code class="FUNCTION"&gt;to_char&lt;/code&gt;(&lt;tt class="TYPE"&gt;double precision&lt;/tt&gt;, &lt;tt class="TYPE"&gt;text&lt;/tt&gt;)&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="TYPE"&gt;text&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;把实数/双精度数转换成字串&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(125.8::real, '999D9')&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;&lt;code class="FUNCTION"&gt;to_char&lt;/code&gt;(&lt;tt class="TYPE"&gt;numeric&lt;/tt&gt;, &lt;tt class="TYPE"&gt;text&lt;/tt&gt;)&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="TYPE"&gt;text&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;把 numeric 转换成字串&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(-125.8, '999D99S')&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;&lt;code class="FUNCTION"&gt;to_date&lt;/code&gt;(&lt;tt class="TYPE"&gt;text&lt;/tt&gt;, &lt;tt class="TYPE"&gt;text&lt;/tt&gt;)&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="TYPE"&gt;date&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;把字串转换成日期&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_date('05&amp;nbsp;Dec&amp;nbsp;2000', 'DD&amp;nbsp;Mon&amp;nbsp;YYYY')&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;&lt;code class="FUNCTION"&gt;to_timestamp&lt;/code&gt;(&lt;tt class="TYPE"&gt;text&lt;/tt&gt;, &lt;tt class="TYPE"&gt;text&lt;/tt&gt;)&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="TYPE"&gt;timestamp with time zone&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;把字串转换成时间戳&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_timestamp('05&amp;nbsp;Dec&amp;nbsp;2000', 'DD&amp;nbsp;Mon&amp;nbsp;YYYY')&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;&lt;code class="FUNCTION"&gt;to_timestamp&lt;/code&gt;(&lt;tt class="TYPE"&gt;double precision&lt;/tt&gt;)&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="TYPE"&gt;timestamp with time zone&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;把 UNIX 纪元转换成时间戳&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_timestamp(200120400)&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;&lt;code class="FUNCTION"&gt;to_number&lt;/code&gt;(&lt;tt class="TYPE"&gt;text&lt;/tt&gt;, &lt;tt class="TYPE"&gt;text&lt;/tt&gt;)&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="TYPE"&gt;numeric&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;把字串转换成 numeric&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_number('12,454.8-', '99G999D9S')&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;在输出模板字串里（对 &lt;code class="FUNCTION"&gt;to_char&lt;/code&gt; 而言），该函数族可以识别一些特定的模式，并且 把待格式化的数值正确地格式化成相应的数据。 任何不属于模板模式的文本都简单地照字拷贝。同样，在一个输入 模板字串里（对除 &lt;code class="FUNCTION"&gt;to_char&lt;/code&gt; 外的任何东西），模板模式标识要查看的输入数据字串，并且将在该位置 寻找数值。 &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pgsqldb.org/pgsqldoc-cvs/functions-formatting.html#FUNCTIONS-FORMATTING-DATETIME-TABLE"&gt;Table 9-21&lt;/a&gt; 显示了 可以用于格式化日期和时间值的模版。 &lt;/p&gt;&lt;div class="TABLE"&gt;&lt;a name="FUNCTIONS-FORMATTING-DATETIME-TABLE"&gt;&lt;/a&gt;&lt;p&gt;&lt;strong&gt;Table 9-21. 用于日期/时间格式化的模式&lt;/strong&gt;&lt;/p&gt;&lt;table class="CALSTABLE" border="1"&gt;&lt;colgroup&gt;&lt;col&gt;&lt;col&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;模式&lt;/th&gt;&lt;th&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;HH&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;一天的小时数 （01-12）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;HH12&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;一天的小时数 （01-12）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;HH24&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;一天的小时数 （00-23）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;MI&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;分钟 （00-59）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;SS&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;秒 （00-59）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;MS&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;毫秒 (000-999)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;US&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;微秒 (000000-999999)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;SSSS&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;午夜后的秒 （0-86399）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;AM&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;A.M.&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;PM&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;P.M.&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;正午标识（大写）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;am&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;a.m.&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;pm&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;p.m.&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;正午标识（小写）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;Y,YYY&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;带逗号的年（4 和更多位）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;YYYY&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;年（4和更多位）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;YYY&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;年的后三位&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;YY&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;年的后两位&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;Y&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;年的最后一位&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;IYYY&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;ISO 年（4位或更多位）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;IYY&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;ISO 年的最后 3 位&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;IY&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;ISO 年的最后 2 位&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;I&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;ISO 年的最后一位&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;BC&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;B.C.&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;AD&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;A.D.&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;纪元标识（大写）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;bc&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;b.c.&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;ad&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;a.d.&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;纪元标识（小写）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;MONTH&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;全长大写月份名（空白填充为9字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;Month&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;全长混合大小写月份名（空白填充为9字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;month&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;全长小写月份名（空白填充为9字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;MON&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;大写缩写月份名（3字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;Mon&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;缩写混合大小写月份名（3字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;mon&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;小写缩写月份名（3字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;MM&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;月份号（01-12）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;DAY&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;全长大写日期名（空白填充为9字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;Day&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;全长混合大小写日期名（空白填充为9字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;day&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;全长小写日期名（空白填充为9字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;DY&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;缩写大写日期名（3字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;Dy&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;缩写混合大小写日期名（3字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;dy&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;缩写小写日期名（3字符）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;DDD&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;一年里的日子（001-366）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;DD&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;一个月里的日子（01-31）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;D&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;一周里的日子（1-7；周日是1）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;W&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;一个月里的周数（1-5）（第一周从该月第一天开始）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;WW&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;一年里的周数（1-53）（第一周从该年的第一天开始）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;IW&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;ISO 一年里的周数（第一个星期四在第一周里）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;CC&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;世纪（2 位）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;J&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;儒略日（自公元前4712年1月1日来的天数）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;Q&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;季度&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;RM&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;罗马数字的月份（I-XII；I=JAN）（大写）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;rm&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;罗马数字的月份（I-XII；I=JAN）（小写）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;TZ&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;时区名 （大写）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;tz&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;时区名 （小写）&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;有一些修饰词可以应用于模板来修改它们的行为。比如， &lt;tt class="LITERAL"&gt;FMMonth&lt;/tt&gt; 就是 带着 &lt;tt class="LITERAL"&gt;FM&lt;/tt&gt; 前缀的 &lt;tt class="LITERAL"&gt;Month&lt;/tt&gt; 模式。 &lt;a href="http://www.pgsqldb.org/pgsqldoc-cvs/functions-formatting.html#FUNCTIONS-FORMATTING-DATETIMEMOD-TABLE"&gt;Table 9-22&lt;/a&gt; 显示了 用于日期/时间格式化的修饰词模式。 &lt;/p&gt;&lt;div class="TABLE"&gt;&lt;a name="FUNCTIONS-FORMATTING-DATETIMEMOD-TABLE"&gt;&lt;/a&gt;&lt;p&gt;&lt;strong&gt;Table 9-22. 日期/时间格式化的模板模式修饰词&lt;/strong&gt;&lt;/p&gt;&lt;table class="CALSTABLE" border="1"&gt;&lt;colgroup&gt;&lt;col&gt;&lt;col&gt;&lt;col&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;修饰词&lt;/th&gt;&lt;th&gt;描述&lt;/th&gt;&lt;th&gt;例子&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;FM&lt;/tt&gt; 前缀&lt;/td&gt;&lt;td&gt;填充模式(抑制填充空白和零)&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;FMMonth&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;TH&lt;/tt&gt; 后缀&lt;/td&gt;&lt;td&gt;大写顺序数后缀&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;DDTH&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;th&lt;/tt&gt; 后缀&lt;/td&gt;&lt;td&gt;小写顺序数后缀&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;DDth&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;FX&lt;/tt&gt; 前缀&lt;/td&gt;&lt;td&gt;固定格式全局选项（见用法须知）&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;&amp;gt;FX&amp;nbsp;Month&amp;nbsp;DD&amp;nbsp;Day&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;SP&lt;/tt&gt; suffix&lt;/td&gt;&lt;td&gt;拼写模式（还未实现）&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;DDSP&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;日期/时间格式化的用法须知： &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;tt class="LITERAL"&gt;FM&lt;/tt&gt; 抑制前导的零或尾随的空白， 如果没有使用它的话，会在输出中增加这些填充最终把输出变成固定宽度的模式。 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;如果没有使用 &lt;tt class="LITERAL"&gt;FX&lt;/tt&gt; 选项， &lt;code class="FUNCTION"&gt;to_timestamp&lt;/code&gt; 和 &lt;code class="FUNCTION"&gt;to_date&lt;/code&gt; 在转换字串的时候忽略多个空白。 &lt;tt class="LITERAL"&gt;FX&lt;/tt&gt; 必须做为模板里的第一个项声明。 比如 &lt;tt class="LITERAL"&gt;to_timestamp('2000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;JUN', 'YYYY MON')&lt;/tt&gt; 是正确的， &lt;tt class="LITERAL"&gt;to_timestamp('2000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;JUN', 'FXYYYY MON')&lt;/tt&gt; 会返回一个错误，因为&lt;code class="FUNCTION"&gt;to_timestamp&lt;/code&gt; 只预料会有一个空白。 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;在 &lt;code class="FUNCTION"&gt;to_char&lt;/code&gt; 模板 里可以有普通文本，并且它们会被照字输出。 你可以把一个字串放到双引号里强迫它解释成一个文本， 即使它里面包含模式关键字也如此。比如，在 &lt;tt class="LITERAL"&gt;'"Hello Year "YYYY'&lt;/tt&gt;， &lt;tt class="LITERAL"&gt;YYYY&lt;/tt&gt; 将被年份数据代替，但是&lt;tt class="LITERAL"&gt;Year&lt;/tt&gt;里单独 的 &lt;tt class="LITERAL"&gt;Y&lt;/tt&gt; 不会。 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;如果你想在输出里有双引号，那么你必须在它们 前面放双反斜杠，比如 &lt;tt class="LITERAL"&gt;'\\"YYYY Month\\"'&lt;/tt&gt;. （需要两个反斜杠是因为反斜杠在字串常量里已经有特殊含义了。） &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;如果你使用的年份长于 4 位字符，那么用 &lt;tt class="LITERAL"&gt;YYYY&lt;/tt&gt; 从字串向&lt;tt class="TYPE"&gt;timestamp&lt;/tt&gt;或者&lt;tt class="TYPE"&gt;date&lt;/tt&gt; 做转换时要受到限制。 你必须在 &lt;tt class="LITERAL"&gt;YYYY&lt;/tt&gt; 后面使用一些非数字字符或者模板， 否则年份总是解释为 4 位数字。比如（对于 20000 年）： &lt;tt class="LITERAL"&gt;to_date('200001131', 'YYYYMMDD')&lt;/tt&gt; 将会被解释成一个 4 位数字的年份， 最好在年后面使用一个非数字的分隔符，象 &lt;tt class="LITERAL"&gt;to_date('20000-1131', 'YYYY-MMDD')&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;to_date('20000Nov31', 'YYYYMonDD')&lt;/tt&gt;。 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;在从字串向 &lt;tt class="TYPE"&gt;timestamp&lt;/tt&gt; 或 &lt;tt class="TYPE"&gt;date&lt;/tt&gt; 转换的时候， 如果有 &lt;tt class="LITERAL"&gt;YYY&lt;/tt&gt;，&lt;tt class="LITERAL"&gt;YYYY&lt;/tt&gt; 或者 &lt;tt class="LITERAL"&gt;Y,YYY&lt;/tt&gt; 字段， 那么 &lt;tt class="LITERAL"&gt;CC&lt;/tt&gt; 字段会被忽略。 如果 &lt;tt class="LITERAL"&gt;CC&lt;/tt&gt; 和 &lt;tt class="LITERAL"&gt;YY&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;Y&lt;/tt&gt; 一起使用， 那么年份时用公式 &lt;tt class="LITERAL"&gt;(CC-1)*100+YY&lt;/tt&gt; 计算的。 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;将字串转化为&lt;tt class="TYPE"&gt;timestamp&lt;/tt&gt;时， 毫秒（&lt;tt class="LITERAL"&gt;MS&lt;/tt&gt;）和微秒（&lt;tt class="LITERAL"&gt;US&lt;/tt&gt;）都是用字串 的小数点后面的部分转换的。比如 &lt;tt class="LITERAL"&gt;to_timestamp('12:3', 'SS:MS')&lt;/tt&gt; 不是 3 毫秒, 而是 300，因为转换把它看做 12 + 0.3 秒。 这意味着对于格式 'SS:MS'而言，输入值为 &lt;tt class="LITERAL"&gt;12:3&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;12:30&lt;/tt&gt;或&lt;tt class="LITERAL"&gt;12:300&lt;/tt&gt; 声明了相同数目的 毫秒。对于三毫秒，你必须使用 &lt;tt class="LITERAL"&gt;12:003&lt;/tt&gt;，那么转换会把它看做 12 + 0.003 = 12.003 秒。 &lt;/p&gt;&lt;p&gt;下面是一个更复杂的 例子&amp;#8758; &lt;tt class="LITERAL"&gt;to_timestamp('15:12:02.020.001230', 'HH:MI:SS.MS.US')&lt;/tt&gt; 是 15 小时，12 分钟，和 2 秒 + 20 毫秒 + 1230微秒 = 2.021230 秒。 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code class="FUNCTION"&gt;to_char&lt;/code&gt; 的星期几的编号（参阅 'D' 格式化模式）与 &lt;code class="FUNCTION"&gt;extract&lt;/code&gt; 的不同。 &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pgsqldb.org/pgsqldoc-cvs/functions-formatting.html#FUNCTIONS-FORMATTING-NUMERIC-TABLE"&gt;Table 9-23&lt;/a&gt; 显示了 可以用于数值格式化的模版模式。 &lt;/p&gt;&lt;div class="TABLE"&gt;&lt;a name="FUNCTIONS-FORMATTING-NUMERIC-TABLE"&gt;&lt;/a&gt;&lt;p&gt;&lt;strong&gt;Table 9-23. 用于数值格式化的模板模式&lt;/strong&gt;&lt;/p&gt;&lt;table class="CALSTABLE" border="1"&gt;&lt;colgroup&gt;&lt;col&gt;&lt;col&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;模式&lt;/th&gt;&lt;th&gt;描述&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;9&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;带有指定数值位数的值&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;0&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;带前导零的值&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;.&lt;/tt&gt; (句点)&lt;/td&gt;&lt;td&gt;小数点&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;,&lt;/tt&gt; (逗号)&lt;/td&gt;&lt;td&gt;分组（千）分隔符&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;PR&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;尖括号内负值&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;S&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;带符号的数值（使用区域设置）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;L&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;货币符号（使用区域设置）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;D&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;小数点（使用区域设置）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;G&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;分组分隔符（使用区域设置）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;MI&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;在指明的位置的负号（如果数字 &amp;lt; 0）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;PL&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;在指明的位置的正号（如果数字 &amp;gt; 0）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;SG&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;在指明的位置的正/负号&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;RN&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;罗马数字（输入在 1 和 3999 之间）&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;TH&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;th&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;序数后缀&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;V&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;移动指定位（小数）（参阅注解） &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;EEEE&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;科学记数。（现在还未实现）&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;p&gt;数字格式化的用法须知： &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;使用&lt;tt class="LITERAL"&gt;SG&lt;/tt&gt;，&lt;tt class="LITERAL"&gt;PL&lt;/tt&gt; 或 &lt;tt class="LITERAL"&gt;MI&lt;/tt&gt; 生成的符号并不挂在数字上面； 比如， &lt;tt class="LITERAL"&gt;to_char(-12, 'S9999')&lt;/tt&gt;生成 &lt;tt class="LITERAL"&gt;'&amp;nbsp;&amp;nbsp;-12'&lt;/tt&gt;, 而&lt;tt class="LITERAL"&gt;to_char(-12， 'MI9999')&lt;/tt&gt;生成 &lt;tt class="LITERAL"&gt;'-&amp;nbsp;&amp;nbsp;12'&lt;/tt&gt;。 Oracle 里的实现不允许在 &lt;tt class="LITERAL"&gt;9&lt;/tt&gt; 前面使用 &lt;tt class="LITERAL"&gt;MI&lt;/tt&gt;，而是要求&lt;tt class="LITERAL"&gt;9&lt;/tt&gt; 在 &lt;tt class="LITERAL"&gt;MI&lt;/tt&gt; 前面。 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;tt class="LITERAL"&gt;9&lt;/tt&gt; 声明和 &lt;tt class="LITERAL"&gt;9&lt;/tt&gt; 的个数 相同的数字位数的数值。如果某个数值位没有数字，则输出一个空白。 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;tt class="LITERAL"&gt;TH&lt;/tt&gt; 不会转换小于零的数值，也不会转换小数。 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;tt class="LITERAL"&gt;PL&lt;/tt&gt;，&lt;tt class="LITERAL"&gt;SG&lt;/tt&gt; 和 &lt;tt class="LITERAL"&gt;TH&lt;/tt&gt; 是 &lt;span class="PRODUCTNAME"&gt;PostgreSQL&lt;/span&gt; 扩展。 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;tt class="LITERAL"&gt;V&lt;/tt&gt; 方便地把输入值乘以 &lt;tt class="LITERAL"&gt;10^&lt;tt class="REPLACEABLE"&gt;&lt;em&gt;n&lt;/em&gt;&lt;/tt&gt;&lt;/tt&gt;，这里 &lt;tt class="REPLACEABLE"&gt;&lt;em&gt;n&lt;/em&gt;&lt;/tt&gt; 是跟在 &lt;tt class="LITERAL"&gt;V&lt;/tt&gt;后面的数字。 &lt;code class="FUNCTION"&gt;to_char&lt;/code&gt; 不支持把 &lt;tt class="LITERAL"&gt;V&lt;/tt&gt; 与一个小数点组合在一起使用 （也就是说，&lt;tt class="LITERAL"&gt;99.9V99&lt;/tt&gt; 是不允许的）。 &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pgsqldb.org/pgsqldoc-cvs/functions-formatting.html#FUNCTIONS-FORMATTING-EXAMPLES-TABLE"&gt;Table 9-24&lt;/a&gt; 显示了 一些使用 &lt;code class="FUNCTION"&gt;to_char&lt;/code&gt; 函数的用法。 &lt;/p&gt;&lt;div class="TABLE"&gt;&lt;a name="FUNCTIONS-FORMATTING-EXAMPLES-TABLE"&gt;&lt;/a&gt;&lt;p&gt;&lt;strong&gt;Table 9-24. &lt;code class="FUNCTION"&gt;to_char&lt;/code&gt; 例子&lt;/strong&gt;&lt;/p&gt;&lt;table class="CALSTABLE" border="1"&gt;&lt;colgroup&gt;&lt;col&gt;&lt;col&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;表达式&lt;/th&gt;&lt;th&gt;结果&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(current_timestamp, 'Day,&amp;nbsp;DD&amp;nbsp;&amp;nbsp;HH12:MI:SS')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'Tuesday&amp;nbsp;&amp;nbsp;,&amp;nbsp;06&amp;nbsp;&amp;nbsp;05:39:18'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(current_timestamp, 'FMDay,&amp;nbsp;FMDD&amp;nbsp;&amp;nbsp;HH12:MI:SS')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'Tuesday,&amp;nbsp;6&amp;nbsp;&amp;nbsp;05:39:18'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(-0.1, '99.99')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;&amp;nbsp;-.10'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(-0.1, 'FM9.99')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'-.1'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(0.1, '0.9')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;0.1'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(12, '9990999.9')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0012.0'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(12, 'FM9990999.9')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'0012.'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(485, '999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;485'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(-485, '999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'-485'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(485,'9&amp;nbsp;9&amp;nbsp;9')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;4&amp;nbsp;8&amp;nbsp;5'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(1485, '9,999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;1,485'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(1485, '9G999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;1&amp;nbsp;485'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(148.5, '999.999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;148.500'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(148.5, 'FM999.999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'148.5'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(148.5, 'FM999.990')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'148.500'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(148.5, '999D999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;148,500'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(3148.5, '9G999D999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;3&amp;nbsp;148,500'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(-485, '999S')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'485-'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(-485, '999MI')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'485-'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(485, '999MI')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'485&amp;nbsp;'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(485, 'FM999MI')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'485'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(485, 'PL999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'+485'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(485, 'SG999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'+485'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(-485, 'SG999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'-485'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(-485, '9SG99')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'4-85'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(-485, '999PR')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;lt;485&amp;gt;'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(485, 'L999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'DM&amp;nbsp;485&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(485, 'RN')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CDLXXXV'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(485, 'FMRN')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'CDLXXXV'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(5.2, 'FMRN')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'V'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(482, '999th')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;482nd'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(485, '"Good&amp;nbsp;number:"999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'Good&amp;nbsp;number:&amp;nbsp;485'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(485.8, '"Pre:"999"&amp;nbsp;Post:"&amp;nbsp;.999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'Pre:&amp;nbsp;485&amp;nbsp;Post:&amp;nbsp;.800'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(12, '99V999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;12000'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(12.4, '99V999')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;12400'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;to_char(12.45, '99V9')&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;&lt;tt class="LITERAL"&gt;'&amp;nbsp;125'&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;img src="http://www.cnblogs.com/millen/aggbug/2287684.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/millen/archive/2011/12/14/2287684.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry><entry><id>http://www.cnblogs.com/millen/archive/2011/12/01/2270561.html</id><title type="text">了解 DB2 Version 9.5 中的全局变量(转)</title><summary type="text">转自：http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/简介在关系数据库系统内部，应用程序和实际数据库之间的主要交互都是以会话或连接的 SQL 语句形式来实现的。过去，为了在相同会话中实现不同 SQL 语句之间的信息共享，发出 SQL 语句的应用程序必须将语句输出参数集（本地变量）的值复制到另一个语句的输入本地变量中。此外，数据库系统本身定义或包含的 SQL 语句，例如用来定义触发器和视图的 SQL 语句，根本不能够访问这些共享信息。总之，种种约束限制了关系数据库系统的灵活性，并因此限制了.</summary><published>2011-12-01T06:38:00Z</published><updated>2011-12-01T06:38:00Z</updated><author><name>catch22</name><uri>http://www.cnblogs.com/millen/</uri></author><link rel="alternate" href="http://www.cnblogs.com/millen/archive/2011/12/01/2270561.html"/><link rel="alternate" type="text/html" href="http://www.cnblogs.com/millen/archive/2011/12/01/2270561.html"/><content type="html">&lt;span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium Simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="Apple-style-span"&gt;&lt;span style="text-align: left" class="Apple-style-span"&gt; &lt;p&gt;转自：&lt;a href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/"&gt;http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="1.Introduction|outline"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;简介&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;在关系数据库系统内部，应用程序和实际数据库之间的主要交互都是以会话或连接的 SQL 语句形式来实现的。过去，为了在相同会话中实现不同 SQL 语句之间的信息共享，发出 SQL 语句的应用程序必须将语句输出参数集（本地变量）的值复制到另一个语句的输入本地变量中。此外，数据库系统本身定义或包含的 SQL 语句，例如用来定义触发器和视图的 SQL 语句，根本不能够访问这些共享信息。&lt;/p&gt;&lt;p&gt;总之，种种约束限制了关系数据库系统的灵活性，并因此限制了系统用户在数据库内部实现复杂、交互式模型的能力。这类系统的用户不得不在自己的应用程序或 SQL 过程中添加支持逻辑，以便在关系数据库系统中访问和传递用户应用程序信息和内部数据库信息。用户还需对其应用程序逻辑进行增强，以确保被传递和访问的信息的安全性。&lt;/p&gt;&lt;p&gt;为克服这种约束并最大化实现关系数据库系统的灵活性，DB2 V9.5 引入了全局变量的概念。通过引入全局变量，用户现在可以在关系数据库内部轻松地构建复杂系统，同时可在同一会话的 SQL 语句之间共享信息，或者使用数据库系统定义或包含的 SQL 语句访问信息。实现这些任务无需任何应用程序逻辑，从而支持信息传递。本文的目的是介绍这种新特性并解释如何使用它才能发挥其潜力。&lt;/p&gt;&lt;p&gt;首先，了解什么是全局变量以及它涉及的基本操作。然后查看一些有趣的场景，了解全局变量的使用。最后，本文将更加深入地阐述一些与全局变量有关的主题。&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="What is a global variable?"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;什么是全局变量？&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;全局变量表示一个可以使用 SQL 语句访问和修改的可变值。在 DB2 中，这些变量被实现为一种新型数据库对象，其定义保存在数据库编目中。编目中保存的是全局变量的定义而非实际的值，了解这一点非常重要。这样做是因为全局变量具有一个会话（连接）范围。这意味着每个会话都可以使用编目中保存的全局变量，但是每个会话拥有自己的私有值来操作和使用。其他会话都不能访问这个值。&lt;/p&gt;&lt;p&gt;全局变量的另一重要方面是，当考虑到信息安全问题时，可以控制对信息的访问。需要有特定的权限才能创建或删除全局变量，以及读取或修改其内容。这条规则同样适用于全局变量的定义 &amp;#8212;&amp;#8212; 与全局变量相关的权限也在系统编目中进行了定义。&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="3.Creating and dropping global variables|outline"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;创建和删除全局变量&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;要创建一个全局变量，可以使用新的&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;CREATE VARIABLE SQL&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;语句。您需要对模式使用&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;SYSADM, DBADM&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;权限或&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;CREATE_IN&lt;/code&gt;。例如，要创建一个全局变量来表示默认的打印机，应该发出如下语句：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt; CREATE VARIABLE mySchema.defaultPrinter VARCHAR(30)&lt;br/&gt;      DEFAULT 'Printer001'&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;&lt;strong&gt;mySchema.defaultPrinter&lt;/strong&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;表示变量的名称。请注意，全局变量的名称由两部分组成，即模式的名称和其中的变量的名称。如果没有具体指定模式，则默认为当前模式。&lt;/p&gt;&lt;p&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;&lt;strong&gt;VARCHAR(30)&lt;/strong&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;表示变量的数据类型。数据类型可以是 DB2 内置数据类型、独特的类型或引用类型。注意，不能为全局变量指定 CLOB、DBCLOB、BLOB、LONG VARCHAR、LONG VARGRAPHIC、XML、ARRAY 或结构化类型。&lt;/p&gt;&lt;p&gt;如果在第一次引用全局变量没有为全局变量指定其他值，那么使用&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;&lt;strong&gt;DEFAULT &amp;#8216;Printer001&amp;#8217;&lt;/strong&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;表示它的默认值。默认指定的子句可以为一个常量、一个特殊的寄存器、另一个全局变量、一个表达式或关键字 NULL。表达式可以是 SQL Reference Guide 的 &amp;#8220;Expressions&amp;#8221; 部分中定义的任何类型的表达式（请参见&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;a style="color: rgb(76,110,148)" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/#resources"&gt;参考资料&lt;/a&gt;）。如果没有指定默认值，则初始变量为 NULL。表达式的最大大小为 64K。在第一次引用时，默认表达式将为全局变量计算一个值。只要不修改 SQL 中的数据或不会在 DB2 引擎以外执行任何操作，则可以使用 DB2 允许的任何表达式。此外，表达式在分配时必须与变量数据类型兼容。&lt;/p&gt;&lt;p&gt;下面列出了其他一些全局变量示例：&lt;/p&gt;&lt;p&gt;要创建表示用户第一次连接时间的变量，使用以下语句：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;CREATE VARIABLE loginTime TIMESTAMP DEFAULT CURRENT TIMESTAMP&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;要创建表示员工所属部门的变量，使用以下语句：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;CREATE VARIABLE schema1.gvDeptno INTEGER DEFAULT&lt;br/&gt;      ((select deptno from hr.employees where empUser = SESSION_USER));&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;如果希望创建一个全局变量表示最高级安全级别，使用下面的语句：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;CREATE VARIABLE mySchema.SecurityLevel CHAR(5) DEFAULT NULL&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;请注意，一旦创建完毕，全局变量的 length 属性和数据类型将不能更改。此外，您不能更改全局变量定义，包括其默认值。&lt;/p&gt;&lt;p&gt;如果您不希望再保存全局变量的定义，则需要删除它。删除全局变量和删除其他数据库对象需要使用相同的权限（请参考 SQL Reference 中的完整权限列表）。例如，要删除我们前面创建的表示默认打印机的全局变量，应使用以下语句：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;DROP VARIABLE mySchema.defaultPrinter&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;where:&lt;/p&gt;&lt;p&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;&lt;strong&gt;mySchema.defaultPrinter&lt;/strong&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;是变量的名称。如果没有指定模式，则遵守特定规则来确定模式名称。本文稍后的内容将讨论名称解析。&lt;/p&gt;&lt;p&gt;请注意，如果函数、方法、触发器或视图中引用了某个全局变量，则不能删除该变量。&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="4.Using global variables|outline"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;使用全局变量&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;创建了全局变量之后，如果拥有相应的权限，数据库中的任何会话都可以使用它。&lt;code style="font-family: monospace; font-size: small !important"&gt;READ&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;权限用于引用全局变量，而&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;WRITE&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;权限用于修改全局变量的值。&lt;code style="font-family: monospace; font-size: small !important"&gt;GRANT&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;语句允许授权用户对这些权限进行授权，而&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;REVOKE&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;语句用于删除这些权限。全局变量的所有者被显式授予了有关该变量的所有权限。&lt;/p&gt;&lt;p&gt;任何表达式都可以引用全局变量，只要该表达式不需要保持确定性。以下这些情况需要确定性表达式，因此不能使用全局变量：&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;检查约束&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;生成的列的定义&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;刷新直接 Materialized Query Tables (MQTs)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;如上文所述，每个会话对于给定的全局变量都具有自己的私有值。当在会话中第一次引用时，全局变量将进行实例化来获得其默认值。&lt;/p&gt;&lt;p&gt;要查询当前用户所在部门的全部员工，使用以下语句：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;SELECT * FROM hr.employees WHERE&amp;gt; deptno = schema1.gvDeptno&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;要查询本地变量 hv_depnot 的用户部门编号，使用以下语句：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;EXEC SQL VALUES schema1.gvDeptno INTO :hv_deptno&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;要查询用户的部门编号，使用以下语句：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;VALUES schema1.gvDeptno&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;可以使用&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;SET, SELECT INTO, VALUES INTO&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;语句改变全局变量的值。也可以作为调用语句的 out 或 input 参数的实参进行修改。&lt;/p&gt;&lt;p&gt;例如，要将 mySchema.defaultPrinter 变量的值修改为 &amp;#8220;Printer002&amp;#8221;，使用以下语句：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;SET mySchema.defaultPrinter = 'Printer002'&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;要修改 schema1.activeEmployees 的值，使用以下语句：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;EXEC SQL SELECT count(*) INTO schema1.activeEmployees &lt;br/&gt; FROM hr.employees WHERE active = &amp;#8216;Y&amp;#8217;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="5.Examples|outline"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;示例&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;现在您已经了解了如何使用全局变量执行简单的操作，本节将提供一些有趣的场景以展示如何使用它们。&lt;/p&gt;&lt;p&gt;&lt;a name="N1012C"&gt;&lt;span style="font-size: 1.2em; font-weight: bold" class="smalltitle"&gt;使用全局变量关闭触发器以进行维护&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;全局变量的一项有趣应用就是控制触发器的行为。例如，如果您的表具有以下触发器：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;CREATE TRIGGER validate_t&lt;br/&gt;BEFORE INSERT ON T&lt;br/&gt;REFERENCING NEW AS  N  FOR EACH ROW&lt;br/&gt;WHEN  (N.ORDER_DATE &amp;lt;  CURRENT TIMESTAMP  &amp;#8211; 7 DAYS)&lt;br/&gt;SIGNAL SQLSTATE  &amp;#8216;38000&amp;#8217;&lt;br/&gt;SET MESSAGE TEXT  = &amp;#8216;ORDER DATE TOO OLD&amp;#8217;;&lt;br/&gt;            &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;如果 DBA 希望进行一些维护并向表插入一些较旧的数据，他必须阻止其他用户向表插入新的数据、删除触发器、执行维护、重新创建触发器，维护完之后才能允许用户插入数据。&lt;/p&gt;&lt;p&gt;通过创建可以控制触发器行为的全局变量，可以简化这个任务并提高并发行。要执行维护并向表插入较旧的数据，您将使用全局变量并完成以下步骤：&lt;/p&gt;&lt;p&gt;1. 创建一个全局变量：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;CREATE VARIABLE schema1.disableTriggers CHAR(1) DEFAULT &amp;#8216;N&amp;#8217;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;2. 向所有用户授予对变量的读权限：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;GRANT READ on VARIABLE shema1.disableTriggers TO PUBLIC&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;3. 只向 DBA 用户 ID 授予对变量的写权限：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt; GRANT WRITE ON VARIABLE shema1.disableTriggers TO dba_user&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;4. 创建触发器（在&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;WHEN&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;子句中添加对全局变量的检查）：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;CREATE TRIGGER  validate_t&lt;br/&gt;BEFORE INSERT ON  T &lt;br/&gt;REFERENCING NEW AS  N  FOR EACH ROW&lt;br/&gt;WHEN  (schema1.disableTriggers = 'N'   AND  N.ORDER_DATE&amp;lt; CURRENT TIMESTAMP  - 7 DAYS)&lt;br/&gt;SIGNAL SQLSTATE  '38000'&lt;br/&gt;SET MESSAGE TEXT  = 'ORDER DATE TOO OLD':&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;之后，如果需要对表执行任何维护，您所需做的就是修改会话中全局变量的值：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;SET disable_triggers = &amp;#8216;Y&amp;#8217;;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;修改了全局变量的值之后就可以执行维护了，同时其他用户可以向表插入新的纪录。维护完成之后，将值改回来即可：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;SET disable_triggers = &amp;#8216;N&amp;#8217;;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="N1016D"&gt;&lt;span style="font-size: 1.2em; font-weight: bold" class="smalltitle"&gt;使用全局变量降低复杂性并提升性能&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;在使用全局变量之前，可以使用它们计算变量值，从而可提升其他 SQL 实体的性能并降低复杂性。例如，通过调用一个可以为 SESSION_USER 特殊寄存器提供值的函数来设置变量，使用它取回当前用户的部门编号。视图可以在谓词中使用该全局变量的值，从而只选择分配给用户所在部门的行。视图不需要包含子查询。因此，降低了复杂性并且视图操作更加高效和快捷。&lt;/p&gt;&lt;p&gt;1. 像以前一样，创建全局变量：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;CREATE VARIABLE schema1.gv_deptno INTEGER &lt;br/&gt;      DEFAULT(get_deptno (SESSION_USER))&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;2. 或者，在变量创建定义中使用 fullselect 来代替函数调用：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;CREATE VARIABLE schema1.gv_deptno INTEGER DEFAULT&lt;br/&gt; ((SELECT deptno FROM hr.employees WHERE empUser = SESSION_USER));&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;3. 创建视图：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;CREATE VIEW schema1.emp_filtered AS SELECT * FROM employee&lt;br/&gt;      WHERE deptno = schema1.gv_deptno;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;4. 调整权限以使其他用户只能在视图中进行选择：&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;REVOKE ALL ON schema1.emp_filtered FROM PUBLIC&lt;br/&gt;GRANT SELECT ON schema1.emp_filtered TO PUBLIC&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;因此，使用该视图的任何用户只能够查看视图中属于所在部门的行。&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="6.Name Resolution|outline"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;名称解析&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;全局变量名称由两部分构成。如果在没有使用模式名情况下引用全局变量，则使用 SQL 路径协助解析名称。对于静态 SQL 语句，使用 FUNCPATH 绑定选项指定 SQL 路径。对于动态 SQL 语句，SQL 路径为 CURRENT PATH 特殊寄存器的值。这与函数、过程和数据类型使用的是相同的算法。&lt;/p&gt;&lt;p&gt;只有确定变量名与列、SQL 变量、SQL 参数、转换变量或特殊寄存器的名称不匹配时，才能将它视为一个全局变量。虽然 CURRENT PATH 特殊寄存器可能包含多个模式，用户也可能不具备足够的权限访问一个或多个模式中的对象。函数和过程使用&lt;code style="font-family: monospace; font-size: small !important"&gt;EXECUTE&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;权限执行例程解析 &amp;#8212;&amp;#8212; 例如，如果用户不具备&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;EXECUTE&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;权限访问最符合指定内容的例程，DB2 将移至列表中下一个最符合的例程。但不能对&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;VARIABLES&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;执行这个操作。如果用户不具备针对某个变量的&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;READ&lt;/code&gt;（或&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;WRITE&lt;/code&gt;）权限，DB2 不会移至下一个模式 &amp;#8212;&amp;#8212; 而仅仅是不能进行编辑。&lt;/p&gt;&lt;p&gt;在对函数和数据类型使用全局变量时，必要时可以使用保守的绑定语义。在很多实例中，在处理语句时将解析全局变量，并且数据库管理器必须能够重复这种解析。这条规则适用于&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;包中的静态 DML 语句&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;视图&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;触发器&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;SQL 例程&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;对于包中的静态 DML 语句，将在进行绑定时解析全局变量。在视图、触发器和 SQL 例程中，将在创建数据库对象时进行解析。&lt;/p&gt;&lt;p&gt;在对全局变量进行解析时，如果同一个 SQL 路径中的不同模式新添了一个具有相同名称的全局变量，则可能会更改行为。为避免这个问题，数据库管理器将在必要时应用保守的绑定语义。这意味着，在 SQL 路径中，只有在最后一次显式绑定时间戳之前定义的全局变量才会进行名称解析。&lt;/p&gt;&lt;p&gt;如果 DML SQL 语句、触发器、视图或例程内引用了一个全局变量，将为语句或对象记录关于完全限定全局变量名的依赖关系。同样，如果可以的话，将对语句使用的授权 ID 进行检查，以查看是否拥有对全局变量的&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;&lt;code style="font-family: monospace; font-size: small !important"&gt;READ&lt;/code&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp;&lt;/span&gt;权限。&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="Transactions"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;事务&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;如果全局变量是在会话内创建，则其他会话不能使用它，除非已经提交了这个工作单元。然而，在创建全局变量的会话的内部，在提交工作单元之前也可以使用新创建的变量。这种行为与其他创建对象（例如表）是一致的。&lt;/p&gt;&lt;p&gt;对全局变量值的设定是非事务性的。因此，应用程序无法回滚全局变量的值设置。注意以下事项：&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;如果回滚全局变量的创建，那么该变量将不再存在。&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;如果要回滚全局变量的删除，变量值将为删除前的值（如果在删除前会话引用了全局变量，则为旧值，如果之前没有发生引用，则为未初始化的值）。&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a name="N101E9"&gt;&lt;span style="font-size: 1.2em; font-weight: bold" class="smalltitle"&gt;XA 交互&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;全局变量的范围被规定为 XA 事务内的单一会话级别，并且不可用于其他加入事务的会话。&lt;/p&gt;&lt;p&gt;全局变量是非事务性状态对象。因此，在 XA 环境中（包括紧密耦合的事务和松散耦合的事务），全局变量对象（实体和值）不会针对 XAend 发生更改（对诸如 XAstart、XArollback 等其他 XA API 也是如此）。&lt;/p&gt;&lt;p&gt;注意：和事务性状态对象一样，DB2 实现了声明式的全局临时表。因此，在执行以下 XA API 时，将删除声明式全局临时表。&lt;/p&gt;&lt;p&gt;XArollback&lt;/p&gt;&lt;p&gt;XAend(SUCCESS)&lt;/p&gt;&lt;p&gt;XAstart(NOFLAGS)&lt;/p&gt;&lt;p&gt;XAstart(JOIN)&lt;/p&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="8.Auditing global variables|outline"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;全局变量审计&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;您可以对全局变量的信息进行审计。将生成如下所示的审计记录：&lt;/p&gt;&lt;ul style="padding-bottom: 5px; margin-top: 0px; padding-right: 5px; margin-bottom: 0px; font-size: 0.76em; padding-top: 0px"&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;在对变量执行创建或删除操作时生成 OBJMAINT 审计记录&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;当对全局变量授予或撤销权限时生成 SECMAINT 审计记录&lt;/li&gt;&lt;li style="padding-bottom: 3px; margin-top: 0px; padding-right: 5px; font-family: arial, nsimsun, sans-serif; margin-bottom: 0px; padding-top: 0px"&gt;当对全局变量检查权限时生成 CHECKING 审计记录&lt;/li&gt;&lt;/ul&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="9.A comparison with Oracle package variables|outline"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;对照 Oracle 包变量&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;在将应用程序从 Oracle 迁移到 DB2 时，开发人员发现 DB2 的新全局变量支持非常有用，因为 Oracle 中经常会使用包变量。要迁移到 DB2，将包名映射为模式名并使用特定的模式创建变量。下面的示例演示了这一点：&lt;/p&gt;&lt;p&gt;&lt;a name="N10222"&gt;&lt;span style="font-size: 1.2em; font-weight: bold" class="smalltitle"&gt;示例 1. 为数值数据类型创建变量&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Oracle&lt;/strong&gt;&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;   CREATE PACKAGE trans_data AS&lt;br/&gt;   min_balance CONSTANT REAL := 10.00;&lt;br/&gt;   number_processed INT;&lt;br/&gt;   END trans_data;&lt;br/&gt;   /&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;DB2&lt;/strong&gt;&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;   CREATE SCHEMA trans_data!&lt;br/&gt;&lt;br/&gt;   CREATE VARIABLE trans_data.min_balance DOUBLE DEFAULT (10.00)!&lt;br/&gt;&lt;br/&gt;   CREATE VARIABLE trans_data.number_processed INTEGER!&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="N1023C"&gt;&lt;span style="font-size: 1.2em; font-weight: bold" class="smalltitle"&gt;示例 2. 在存储过程中使用变量&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Oracle&lt;/strong&gt;&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;   CREATE OR REPLACE PACKAGE emp_actions AS&lt;br/&gt;      PROCEDURE hire_employee (&lt;br/&gt;         ename  VARCHAR2,&lt;br/&gt;         job    VARCHAR2,&lt;br/&gt;         mgr    NUMBER,&lt;br/&gt;         sal    NUMBER,&lt;br/&gt;         comm   NUMBER,&lt;br/&gt;         deptno NUMBER);&lt;br/&gt;      END emp_actions;&lt;br/&gt;   Empname VARCHAR2;&lt;br/&gt;   /&lt;br/&gt;&lt;br/&gt;   CREATE OR REPLACE PACKAGE BODY emp_actions AS&lt;br/&gt;      PROCEDURE hire_employee (&lt;br/&gt;         ename  VARCHAR2,&lt;br/&gt;         job    VARCHAR2,&lt;br/&gt;         mgr    NUMBER,&lt;br/&gt;         sal    NUMBER,&lt;br/&gt;         comm   NUMBER,&lt;br/&gt;         deptno NUMBER) IS&lt;br/&gt;      BEGIN&lt;br/&gt;         INSERT INTO emp VALUES (empno_seq.NEXTVAL, empname, job,&lt;br/&gt;            mgr, SYSDATE, sal, comm, deptno);&lt;br/&gt;      END hire_employee;&lt;br/&gt;   END emp_actions;&lt;br/&gt;   /&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;DB2&lt;/strong&gt;&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;   CREATE SCHEMA emp_actions!&lt;br/&gt;&lt;br/&gt;   CREATE VARIABLE emp_actions.empname VARCHAR(4000)!&lt;br/&gt;&lt;br/&gt;   CREATE PROCEDURE emp_actions.hire_employee (ename VARCHAR(4000), &lt;br/&gt;                                            job VARCHAR(4000), &lt;br/&gt;                                            mgr FLOAT, &lt;br/&gt;                                            sal FLOAT, &lt;br/&gt;                                            comm FLOAT, &lt;br/&gt;                                            deptno FLOAT )&lt;br/&gt;   LANGUAGE SQL&lt;br/&gt;   BEGIN&lt;br/&gt;      INSERT INTO emp VALUES (empno_seq.NEXTVAL, &lt;br/&gt;         emp_actions.empname, job,mgr, CURRENT TIMESTAMP , &lt;br/&gt;         sal,comm,deptno);&lt;br/&gt;   END!&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;&lt;a name="N10256"&gt;&lt;span style="font-size: 1.2em; font-weight: bold" class="smalltitle"&gt;示例 3. 为更加复杂的数据类型创建变量&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Oracle&lt;/strong&gt;&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;   CREATE OR REPLACE PACKAGE uw_constants IS&lt;br/&gt;   cStartDate  CONSTANT DATE := TO_DATE('07-JAN-2006');&lt;br/&gt;   cInstructor CONSTANT VARCHAR2(30) := 'A. Morgan';&lt;br/&gt;   cPi  CONSTANT NUMBER(8,7) := 3.1415926;&lt;br/&gt;   END uw_constants;&lt;br/&gt;   /&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;DB2&lt;/strong&gt;&lt;/p&gt;&lt;table style="font-size: 0.8em" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="border-bottom: rgb(204,204,204) 1px solid; border-left: rgb(204,204,204) 1px solid; padding-bottom: 5px; background-color: rgb(247,247,247) !important; padding-left: 2px; padding-right: 2px; font-family: arial, nsimsun, sans-serif; border-top: rgb(204,204,204) 1px solid; border-right: rgb(204,204,204) 1px solid; padding-top: 2px" class="code-outline"&gt;   CREATE SCHEMA uw_constants!&lt;br/&gt;&lt;br/&gt;   CREATE VARIABLE uw_constants.cStartDate TIMESTAMP&lt;br/&gt;      DEFAULT (TIMESTAMP('2006-01-07-00.00.00.000000'))!&lt;br/&gt;&lt;br/&gt;   CREATE VARIABLE uw_constants.cInstructor VARCHAR(30) &lt;br/&gt;      DEFAULT &amp;#8216;A.Morgan&amp;#8217;!&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div style="background-image: url(http://1.www.s81c.com/i/solid.gif); background-color: rgb(255,255,255); height: 1px; clear: both; background-origin: initial; background-clip: initial" class="ibm-alternate-rule"&gt;&lt;/div&gt;&lt;p class="ibm-ind-link ibm-back-to-top"&gt;&lt;a style="background-image: url(http://1.www.s81c.com/i/v16/icons/u_bold.gif); padding-bottom: 0px; margin: 0px; padding-left: 18px; padding-right: 0px; display: inline; background-position: 0px -1px; color: rgb(76,110,148); font-weight: bold; text-decoration: none; padding-top: 0px; background-origin: initial; background-clip: initial" class="ibm-anchor-up-link" href="http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/#ibm-pcon"&gt;回页首&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a name="10.Summary|outline"&gt;&lt;span style="font-size: 1.5em; font-weight: bold" class="atitle"&gt;结束语&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;在本文中，我介绍了 DB2 V9.5 中最新引入的全局变量支持。通过使用这些新的数据库对象，用户可以轻松构建复杂的系统，其中可以在各个 SQL 语句之间共享信息，同时不需要使用任何应用程序逻辑就可支持信息传递。创建全局变量之后，将其定义保存在编目中，并且任何会话都可以使用它们。并且由于每个全局变量以会话为范围，所有会话都拥有自己的私有值进行操作和使用，而其他会话无法访问这些私有值。全局变量的另一重要方面是，在考虑到信息安全性时，可以对访问进行控制。总之，全局变量易于使用，同时还提供了强大的功能和灵活性。&lt;/p&gt;&lt;/span&gt;&lt;/span&gt;&lt;img src="http://www.cnblogs.com/millen/aggbug/2270561.html?type=1" width="1" height="1" alt=""/&gt;&lt;p&gt;&lt;a href="http://www.cnblogs.com/millen/archive/2011/12/01/2270561.html" target="_blank"&gt;本文链接&lt;/a&gt;&lt;/p&gt;</content></entry></feed>
