﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-asoka.hang's oracle/java blog</title><link>http://www.blogjava.net/asoka/</link><description /><language>zh-cn</language><lastBuildDate>Mon, 13 Apr 2026 14:05:49 GMT</lastBuildDate><pubDate>Mon, 13 Apr 2026 14:05:49 GMT</pubDate><ttl>60</ttl><item><title>请保持约束条件的一直存在：最好先add后drop</title><link>http://www.blogjava.net/asoka/archive/2006/04/19/41963.html</link><dc:creator>asoka的oracle/java博客</dc:creator><author>asoka的oracle/java博客</author><pubDate>Wed, 19 Apr 2006 09:30:00 GMT</pubDate><guid>http://www.blogjava.net/asoka/archive/2006/04/19/41963.html</guid><wfw:comment>http://www.blogjava.net/asoka/comments/41963.html</wfw:comment><comments>http://www.blogjava.net/asoka/archive/2006/04/19/41963.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/asoka/comments/commentRss/41963.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/asoka/services/trackbacks/41963.html</trackback:ping><description><![CDATA[
		<font face="Courier New" size="2">大家知道，oracle中没有提供修改约束条件的命令，如果要用到修改约束条件时，常规做法就是先drop掉当前约束再重新创建一个新约束条件，从应用层次而言，这样做是不妥的。<br /><br />常规做法如下：<br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">create</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">table</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> test_constraint<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">  (<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
								<span style="COLOR: #000000">  id </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">number</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">,<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
								<span style="COLOR: #000000">  name </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span>
								<span style="COLOR: #000000">(</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">25</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">),<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
								<span style="COLOR: #000000">  age </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">number</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">constraint</span>
								<span style="COLOR: #000000"> age_ct </span>
								<span style="COLOR: #0000ff">check</span>
								<span style="COLOR: #000000">(age </span>
								<span style="COLOR: #808080">between</span>
								<span style="COLOR: #000000"> </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">0</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #808080">and</span>
								<span style="COLOR: #000000"> </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">99</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">  );<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />表已创建。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">alter</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">table</span>
								<span style="COLOR: #000000"> test_constraint </span>
								<span style="COLOR: #0000ff">drop</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">constraint</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> age_ct;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />表已更改。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">alter</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">table</span>
								<span style="COLOR: #000000"> test_constraint </span>
								<span style="COLOR: #0000ff">add</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">constraint</span>
								<span style="COLOR: #000000"> age_ct </span>
								<span style="COLOR: #0000ff">check</span>
								<span style="COLOR: #000000">(age </span>
								<span style="COLOR: #808080">between</span>
								<span style="COLOR: #000000"> </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">18</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #808080">and</span>
								<span style="COLOR: #000000"> </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">99</span>
						</font>
				</font>
				<span style="COLOR: #000000">
						<font face="Courier New" size="2">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />表已更改。</font>
				</span>
		</div>
		<br />
		<font face="Courier New" size="2">tom在一篇文章中这样讲：</font>
		<font face="Courier New" size="2">“我会用两条命令：一条增加一个新的约束，另一条删除旧的约束。”，仔细理解也就是说他会先将新的约束条件进行添加以达到新的要求需求，而事后再对旧的约束条件予以drop，这种做法通过sqlplus表现如下：<br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">drop</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">table</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> test_constraint;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />表已丢弃。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">create</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">table</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> test_constraint<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">  (<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
								<span style="COLOR: #000000">  id </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">number</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">,<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
								<span style="COLOR: #000000">  name </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span>
								<span style="COLOR: #000000">(</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">25</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">),<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
								<span style="COLOR: #000000">  age </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">number</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">constraint</span>
								<span style="COLOR: #000000"> age_ct </span>
								<span style="COLOR: #0000ff">check</span>
								<span style="COLOR: #000000">(age </span>
								<span style="COLOR: #808080">between</span>
								<span style="COLOR: #000000"> </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">0</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #808080">and</span>
								<span style="COLOR: #000000"> </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">99</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">  );<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />表已创建。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">alter</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">table</span>
								<span style="COLOR: #000000"> test_constraint </span>
								<span style="COLOR: #0000ff">add</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">constraint</span>
								<span style="COLOR: #000000"> agenew_ct </span>
								<span style="COLOR: #0000ff">check</span>
								<span style="COLOR: #000000">(age </span>
								<span style="COLOR: #808080">between</span>
								<span style="COLOR: #000000"> </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">18</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #808080">and</span>
								<span style="COLOR: #000000"> </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">99</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />表已更改。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">alter</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">table</span>
								<span style="COLOR: #000000"> test_constraint </span>
								<span style="COLOR: #0000ff">drop</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">constraint</span>
						</font>
				</font>
				<span style="COLOR: #000000">
						<font face="Courier New" size="2"> age_ct;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />表已更改。</font>
				</span>
		</div>
		<br />
		<font face="Courier New" size="2">从应用层面上而言，更改一个约束名称并不会受到影响，通过上面方法既将新的约束条件增加进去了又没有影响到应用(先drop后add的做法在这里显得是一种错误的做法)。</font>
<img src ="http://www.blogjava.net/asoka/aggbug/41963.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/asoka/" target="_blank">asoka的oracle/java博客</a> 2006-04-19 17:30 <a href="http://www.blogjava.net/asoka/archive/2006/04/19/41963.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>很妙的一句SQL语句 ：）</title><link>http://www.blogjava.net/asoka/archive/2006/04/13/40987.html</link><dc:creator>asoka的oracle/java博客</dc:creator><author>asoka的oracle/java博客</author><pubDate>Thu, 13 Apr 2006 15:04:00 GMT</pubDate><guid>http://www.blogjava.net/asoka/archive/2006/04/13/40987.html</guid><wfw:comment>http://www.blogjava.net/asoka/comments/40987.html</wfw:comment><comments>http://www.blogjava.net/asoka/archive/2006/04/13/40987.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/asoka/comments/commentRss/40987.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/asoka/services/trackbacks/40987.html</trackback:ping><description><![CDATA[
		<font face="Courier New" size="2">case：要求在一张销售信息表中查询每件产品的最近销售日期(不用PL/SQL实现)。<br /><br />创建test_purchase表：<br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">create</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">table</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> test_purchase(<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
								<span style="COLOR: #000000">  product_name </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar2</span>
								<span style="COLOR: #000000">(</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">25</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">),<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
								<span style="COLOR: #000000">  salesperson </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar2</span>
								<span style="COLOR: #000000">(</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">),<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">  purchase_date date,<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
								<span style="COLOR: #000000">  quantity </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">number</span>
								<span style="COLOR: #000000">(</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
								<span style="COLOR: #000000">,</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
						</font>
				</font>
				<span style="COLOR: #000000">
						<font face="Courier New" size="2">  );<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />表已创建。</font>
				</span>
		</div>
		<br />
		<font face="Courier New" size="2">往test_purchase表中插入数据：<br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">insert</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">into</span>
								<span style="COLOR: #000000"> test_purchase </span>
								<span style="COLOR: #0000ff">values</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">small widget</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">ca</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,to_date(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">2003-7-14</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">YYYY-MM-DD</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">),</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />已创建 </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> 行。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">insert</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">into</span>
								<span style="COLOR: #000000"> test_purchase </span>
								<span style="COLOR: #0000ff">values</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">medium wodget</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">bb</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,to_date(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">2003-7-14</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">YYYY-MM-DD</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">),</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">75</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />已创建 </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> 行。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">insert</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">into</span>
								<span style="COLOR: #000000"> test_purchase </span>
								<span style="COLOR: #0000ff">values</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">chrome phoobar</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">ga</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,to_date(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">2003-7-14</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">YYYY-MM-DD</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">),</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />已创建 </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> 行。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">insert</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">into</span>
								<span style="COLOR: #000000"> test_purchase </span>
								<span style="COLOR: #0000ff">values</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">small widget</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">ga</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,to_date(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">2003-7-15</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">YYYY-MM-DD</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">),</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">8</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />已创建 </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> 行。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">insert</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">into</span>
								<span style="COLOR: #000000"> test_purchase </span>
								<span style="COLOR: #0000ff">values</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">medium wodget</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">lb</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,to_date(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">2003-7-15</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">YYYY-MM-DD</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">),</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">20</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />已创建 </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> 行。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">insert</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">into</span>
								<span style="COLOR: #000000"> test_purchase </span>
								<span style="COLOR: #0000ff">values</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">round snaphoo</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">ca</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,to_date(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">2003-7-16</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">YYYY-MM-DD</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">),</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />已创建 </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
								<span style="COLOR: #000000"> 行。</span>
						</font>
				</font>
		</div>
		<p>
				<font face="Courier New" size="2">关键的select 子查询语句来了，呵呵<br /></font>
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">select</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #808080">*</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">from</span>
								<span style="COLOR: #000000"> test_purchase </span>
								<span style="COLOR: #0000ff">where</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">(product_name,purchase_date)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
								<span style="COLOR: #000000">  </span>
								<span style="COLOR: #808080">in</span>
						</font>
				</font>
				<span style="COLOR: #000000">
						<br />
						<font face="Courier New" size="2">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </font>
				</span>
				<font size="2">
						<font face="Courier New">
								<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
								<span style="COLOR: #000000">  (</span>
								<span style="COLOR: #0000ff">select</span>
								<span style="COLOR: #000000"> product_name,</span>
								<span style="COLOR: #ff00ff">max</span>
								<span style="COLOR: #000000">(purchase_date) </span>
								<span style="COLOR: #0000ff">from</span>
								<span style="COLOR: #000000"> test_purchase </span>
								<span style="COLOR: #0000ff">group</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">by</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> product_name);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />PRODUCT_NAME              SAL PURCHASE_D   QUANTITY<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
								<span style="COLOR: #008080">--</span>
								<span style="COLOR: #008080">----------------------- --- ---------- ----------</span>
						</font>
				</font>
				<span style="COLOR: #008080">
						<br />
						<font face="Courier New" size="2">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						</font>
				</span>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">chrome phoobar            ga  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2003</span>
								<span style="COLOR: #808080">-</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">07</span>
								<span style="COLOR: #808080">-</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">14</span>
								<span style="COLOR: #000000">          </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
						</font>
				</font>
				<span style="COLOR: #000000">
						<br />
						<font face="Courier New" size="2">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />medium wodget             lb  </font>
				</span>
				<font size="2">
						<font face="Courier New">
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2003</span>
								<span style="COLOR: #808080">-</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">07</span>
								<span style="COLOR: #808080">-</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">15</span>
								<span style="COLOR: #000000">         </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">20</span>
						</font>
				</font>
				<span style="COLOR: #000000">
						<br />
						<font face="Courier New" size="2">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						</font>
				</span>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #ff00ff">round</span>
								<span style="COLOR: #000000"> snaphoo             ca  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2003</span>
								<span style="COLOR: #808080">-</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">07</span>
								<span style="COLOR: #808080">-</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">16</span>
								<span style="COLOR: #000000">          </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
						</font>
				</font>
				<span style="COLOR: #000000">
						<br />
						<font face="Courier New" size="2">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />small widget              ga  </font>
				</span>
				<font size="2">
						<font face="Courier New">
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2003</span>
								<span style="COLOR: #808080">-</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">07</span>
								<span style="COLOR: #808080">-</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">15</span>
								<span style="COLOR: #000000">          </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">8</span>
						</font>
				</font>
		</div>
		<p>
				<font face="Courier New" size="2">其实仔细想一想也不是很复杂，不过这条语句乍一想来如何写还真有点困难，所以用了个妙字，:p<br /><br /></font>
		</p>
<img src ="http://www.blogjava.net/asoka/aggbug/40987.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/asoka/" target="_blank">asoka的oracle/java博客</a> 2006-04-13 23:04 <a href="http://www.blogjava.net/asoka/archive/2006/04/13/40987.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ORACLE中的OOP：可变数组的运用</title><link>http://www.blogjava.net/asoka/archive/2006/04/13/40925.html</link><dc:creator>asoka的oracle/java博客</dc:creator><author>asoka的oracle/java博客</author><pubDate>Thu, 13 Apr 2006 08:18:00 GMT</pubDate><guid>http://www.blogjava.net/asoka/archive/2006/04/13/40925.html</guid><wfw:comment>http://www.blogjava.net/asoka/comments/40925.html</wfw:comment><comments>http://www.blogjava.net/asoka/archive/2006/04/13/40925.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/asoka/comments/commentRss/40925.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/asoka/services/trackbacks/40925.html</trackback:ping><description><![CDATA[
		<font face="Courier New" size="2">
				<font color="#ff1493">case:在scott.emp中有一个字段为deptno用来存储部门编号，在关系型数据库中一个字段只能够存储一列值(像ENAME列只能够存储员工姓名的值)，要想查询emp与dept两表间的关联值还得运用主从表间的关系，查询效率不高，在emp表中deptno字段并不是很复杂(因为dept表中仅三个字段)的情况下，oracle允许在emp表中的deptno字段里存储一个表，这虽然违反关系型数据库的规则，但是提高了性能。<br /></font>
				<br />我们将举一个入库明细的例子来说明可变数组在上面类似情况的应用。<br /><br />创建一个入库的明细类型mingxitype：<br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">create</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #808080">or</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #ff00ff">replace</span>
								<span style="COLOR: #000000"> type mingxitype </span>
								<span style="COLOR: #0000ff">as</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> object<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">  (<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
								<span style="COLOR: #000000">     goodsid </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span>
								<span style="COLOR: #000000">(</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">15</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">),<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
								<span style="COLOR: #000000">     incount </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">int</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">,<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
								<span style="COLOR: #000000">     providerid </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span>
								<span style="COLOR: #000000">(</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">10</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">  );<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">7</span>
								<span style="COLOR: #000000">  </span>
								<span style="COLOR: #808080">/</span>
						</font>
				</font>
		</div>
		<br />
		<font face="Courier New" size="2">创建一个基于mingxitype类型的可变数组：<br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">create</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #808080">or</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #ff00ff">replace</span>
								<span style="COLOR: #000000"> type arrmingxitype </span>
								<span style="COLOR: #0000ff">as</span>
								<span style="COLOR: #000000"> varray(</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">100</span>
								<span style="COLOR: #000000">) </span>
								<span style="COLOR: #0000ff">of</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> mingxitype;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
								<span style="COLOR: #000000">  </span>
								<span style="COLOR: #808080">/</span>
						</font>
				</font>
		</div>
		<br />
		<font face="Courier New" size="2">创建一个产品入库主表：<br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">create</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">table</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> instock<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">  (<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
								<span style="COLOR: #000000">     orderid </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">int</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">primary</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">key</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">,<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">     indate date,<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">     mingxi arrmingxitype<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
								<span style="COLOR: #000000">  );</span>
						</font>
				</font>
		</div>
		<br />
		<font face="Courier New" size="2">向主表中插入数据：<br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">insert</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">into</span>
								<span style="COLOR: #000000"> instock </span>
								<span style="COLOR: #0000ff">values</span>
								<span style="COLOR: #000000">(</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">1001</span>
								<span style="COLOR: #000000">,to_date(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">2006-1-1</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">YYYY-MM-DD</span>
								<span style="COLOR: #ff0000">'</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">),arrmingxitype<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
								<span style="COLOR: #000000">  (mingxitype(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">101</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">10</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">S01</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">),mingxitype(</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">102</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">,</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">30</span>
								<span style="COLOR: #000000">,</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #ff0000">S05</span>
								<span style="COLOR: #ff0000">'</span>
								<span style="COLOR: #000000">)));</span>
						</font>
				</font>
		</div>
		<br />
		<font face="Courier New" size="2">通过查询可以查出主表instock中的字段mingxi中其实包括了一张表的内容，因为显示出来的arrmingxitype可变数组内容比较零乱，降低了可读性，运用PL/SQL可以读出，但是这里我们用table()函数即可完成这个输出修改，SQL语句如下：<br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">select</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #808080">*</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">from</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">table</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #0000ff">select</span>
								<span style="COLOR: #000000"> s.mingxi </span>
								<span style="COLOR: #0000ff">from</span>
								<span style="COLOR: #000000"> instock s </span>
								<span style="COLOR: #0000ff">where</span>
								<span style="COLOR: #000000"> orderid</span>
								<span style="COLOR: #808080">=</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">1001</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />GOODSID            INCOUNT PROVIDERID<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
								<span style="COLOR: #008080">--</span>
								<span style="COLOR: #008080">------------- ---------- ----------</span>
						</font>
				</font>
				<span style="COLOR: #008080">
						<br />
						<font face="Courier New" size="2">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						</font>
				</span>
				<font size="2">
						<font face="Courier New">
								<span style="FONT-WEIGHT: bold; COLOR: #800000">101</span>
								<span style="COLOR: #000000">                     </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">10</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> S01<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">102</span>
								<span style="COLOR: #000000">                     </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">30</span>
								<span style="COLOR: #000000"> S05</span>
						</font>
				</font>
		</div>
		<br />
		<font face="Courier New" size="2">这样，通过在表中插入一个可变数组就将文中case里的问题给解决了。<br /><br />可变数组也有一定的缺陷，比如更新起来比较麻烦，因为不能更新varray中的单个元素，也就意味着，如果要去更新varray中的某个字段，需得将整个varray中的数据全部重新输入一次，所以，可变数组在应用过程中需得慎重选择，可以将其应用于一些平常不需要去修改数据的环境中，比如医院里医生开的处方归档资料库等case中。<br /></font>
<img src ="http://www.blogjava.net/asoka/aggbug/40925.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/asoka/" target="_blank">asoka的oracle/java博客</a> 2006-04-13 16:18 <a href="http://www.blogjava.net/asoka/archive/2006/04/13/40925.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ORACLE中的OOP：继承</title><link>http://www.blogjava.net/asoka/archive/2006/04/12/40654.html</link><dc:creator>asoka的oracle/java博客</dc:creator><author>asoka的oracle/java博客</author><pubDate>Wed, 12 Apr 2006 06:37:00 GMT</pubDate><guid>http://www.blogjava.net/asoka/archive/2006/04/12/40654.html</guid><wfw:comment>http://www.blogjava.net/asoka/comments/40654.html</wfw:comment><comments>http://www.blogjava.net/asoka/archive/2006/04/12/40654.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/asoka/comments/commentRss/40654.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/asoka/services/trackbacks/40654.html</trackback:ping><description><![CDATA[
		<font face="Courier New" size="2">先提一下抽象数据类型的的概念，然后我们用抽象数据类型的扩展性来讲述继承在oracle中应用。<br /><br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font face="Courier New" size="2">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</font>
				<span style="COLOR: #000000">
						<font face="Courier New" size="2">抽象数据类型：包含一个或多个子类型的数据类型，不局限于oracle的标准数据类型，可以用于其他数据类型中<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />语法：create type type_name as object(columns..)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />not final关键字限制派生子类型</font>
				</span>
		</div>
		<font face="Courier New" size="2">
				<br />先创建一个抽象数据类型对象：<br /><br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">create</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #808080">or</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #ff00ff">replace</span>
								<span style="COLOR: #000000"> type person </span>
								<span style="COLOR: #0000ff">as</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> object<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">  (<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
								<span style="COLOR: #000000">     personname </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span>
								<span style="COLOR: #000000">(</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">10</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">),<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
								<span style="COLOR: #000000">     personsex </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">varchar</span>
								<span style="COLOR: #000000">(</span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">),<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">5</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">     personbirth date<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
								<span style="COLOR: #000000">  ) </span>
								<span style="COLOR: #808080">not</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> final;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">7</span>
								<span style="COLOR: #000000">  </span>
								<span style="COLOR: #808080">/</span>
						</font>
				</font>
		</div>
		<font face="Courier New" size="2">
				<br />后面的not final表示该类型不是最终类型，是可以进行扩展的，就是后面我们继承所需要用到的功能。<br /><br />再创建一个类型，并通过under关键字来对上面的类型进行扩展，也就是继承。<br /><br /></font>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font size="2">
						<font face="Courier New">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
								<span style="COLOR: #000000">SQL</span>
								<span style="COLOR: #808080">&gt;</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">create</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #808080">or</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #ff00ff">replace</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000"> type employeetype under person<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">2</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">  (<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">3</span>
								<span style="COLOR: #000000">     empid </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">int</span>
						</font>
				</font>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">,<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">4</span>
								<span style="COLOR: #000000">     empsalary </span>
								<span style="FONT-WEIGHT: bold; COLOR: #000000">int</span>
						</font>
				</font>
				<span style="COLOR: #000000">
						<br />
						<font face="Courier New" size="2">
								<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </font>
				</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">
						<font face="Courier New" size="2">5</font>
				</span>
				<font size="2">
						<font face="Courier New">
								<span style="COLOR: #000000">  );<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
								<span style="FONT-WEIGHT: bold; COLOR: #800000">6</span>
								<span style="COLOR: #000000">  </span>
								<span style="COLOR: #808080">/</span>
						</font>
				</font>
		</div>
		<font face="Courier New" size="2">
				<br />通过desc employeetype查看表结构时发现，后面创建的employeetype类型已经默认继承了person类型的属性。<br /><br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">SQL</span><span style="COLOR: #808080">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">desc</span><span style="COLOR: #000000"> employeetype;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /> studenttype extends SCOTT.PERSON<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /> 名称                                                  是否为空? 类型<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /> </span><span style="COLOR: #008080">--</span><span style="COLOR: #008080">--------------------------------------------------- -------- -------------</span><span style="COLOR: #008080"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000"> PERSONNAME                                                     </span><span style="FONT-WEIGHT: bold; COLOR: #000000">VARCHAR2</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #800000">10</span><span style="COLOR: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /> PERSONSEX                                                      </span><span style="FONT-WEIGHT: bold; COLOR: #000000">VARCHAR2</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #800000">2</span><span style="COLOR: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /> PERSONBIRTH                                                    DATE<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /> EMPID                                                          </span><span style="FONT-WEIGHT: bold; COLOR: #000000">NUMBER</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #800000">38</span><span style="COLOR: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /> EMPSALARY                                                      </span><span style="FONT-WEIGHT: bold; COLOR: #000000">NUMBER</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #800000">38</span><span style="COLOR: #000000">)</span></div><br />类似的，可以将该类型应用到学生信息表、员工信息表中等类似的环境中去。<br /><br />待续....</font>
<img src ="http://www.blogjava.net/asoka/aggbug/40654.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/asoka/" target="_blank">asoka的oracle/java博客</a> 2006-04-12 14:37 <a href="http://www.blogjava.net/asoka/archive/2006/04/12/40654.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>