﻿<?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-自由飞翔-随笔分类-oracle</title><link>http://www.blogjava.net/GavinMiao/category/49313.html</link><description>我在仰望，java之上</description><language>zh-cn</language><lastBuildDate>Mon, 05 Sep 2011 15:04:13 GMT</lastBuildDate><pubDate>Mon, 05 Sep 2011 15:04:13 GMT</pubDate><ttl>60</ttl><item><title>oracle to_date、to_char、trunc</title><link>http://www.blogjava.net/GavinMiao/archive/2011/08/18/356802.html</link><dc:creator>GavinMiao</dc:creator><author>GavinMiao</author><pubDate>Thu, 18 Aug 2011 09:57:00 GMT</pubDate><guid>http://www.blogjava.net/GavinMiao/archive/2011/08/18/356802.html</guid><wfw:comment>http://www.blogjava.net/GavinMiao/comments/356802.html</wfw:comment><comments>http://www.blogjava.net/GavinMiao/archive/2011/08/18/356802.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/GavinMiao/comments/commentRss/356802.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/GavinMiao/services/trackbacks/356802.html</trackback:ping><description><![CDATA[<div><span style="color: #464646; font-family: simsun; "><div>来源：<a href="http://blog.sina.com.cn/s/blog_4fd11d0a0100kaz4.html">http://blog.sina.com.cn/s/blog_4fd11d0a0100kaz4.html<br /></a><br />日期到字符操作&nbsp;<wbr></div><div>　　select sysdate,to_char(sysdate,&#8217;yyyy-mm-dd hh24:mi:ss&#8217;) from dual &nbsp;<wbr>&nbsp;<wbr></div><div>　　select sysdate,to_char(sysdate,&#8217;yyyy-mm-dd hh:mi:ss&#8217;) from dual &nbsp;<wbr>&nbsp;<wbr></div><div>　　select sysdate,to_char(sysdate,&#8217;yyyy-ddd hh:mi:ss&#8217;) from dual&nbsp;<wbr></div><div>　　select sysdate,to_char(sysdate,&#8217;yyyy-mm iw-d hh:mi:ss&#8217;) from dual&nbsp;<br /><div><div>字符到日期操作 &nbsp;<wbr>&nbsp;<wbr></div><div>　　select to_date(&#8217;2003-10-17 21:15:37&#8217;,&#8217;yyyy-mm-dd hh24:mi:ss&#8217;) from dual<br /><div><div>trunk函数的使用&nbsp;<wbr></div><div>　　select trunc(sysdate ,&#8217;YEAR&#8217;) from dual&nbsp;<wbr></div><div>　　select trunc(sysdate ) from dual&nbsp;<wbr></div><div>　　select to_char(trunc(sysdate ,&#8217;YYYY&#8217;),&#8217;YYYY&#8217;) from dual&nbsp;</div></div></div></div></div></span></div><img src ="http://www.blogjava.net/GavinMiao/aggbug/356802.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/GavinMiao/" target="_blank">GavinMiao</a> 2011-08-18 17:57 <a href="http://www.blogjava.net/GavinMiao/archive/2011/08/18/356802.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle并交差</title><link>http://www.blogjava.net/GavinMiao/archive/2011/08/18/356800.html</link><dc:creator>GavinMiao</dc:creator><author>GavinMiao</author><pubDate>Thu, 18 Aug 2011 09:34:00 GMT</pubDate><guid>http://www.blogjava.net/GavinMiao/archive/2011/08/18/356800.html</guid><wfw:comment>http://www.blogjava.net/GavinMiao/comments/356800.html</wfw:comment><comments>http://www.blogjava.net/GavinMiao/archive/2011/08/18/356800.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/GavinMiao/comments/commentRss/356800.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/GavinMiao/services/trackbacks/356800.html</trackback:ping><description><![CDATA[<div><h3><font class="Apple-style-span" face="Helvetica, Tahoma, Arial, sans-serif"><span class="Apple-style-span" style="font-size: 12px; line-height: 18px;">转载：</span></font><a href="http://chenhua-1984.iteye.com/blog/350354"><span class="Apple-style-span" style="font-size: 12px; font-weight: normal;">http://chenhua-1984.iteye.com/blog/350354</span><br /><br /><div style="display: inline-block; "><div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal; ">集合操作有　并，交，差　３种运算。&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">　union :得到两个查询结果的并集，并且自动去掉重复行。不会排序&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">　union all:得到两个查询结果的并集，不会去掉重复行。也不会排序&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">　intersect:得到两个查询结果的交集，并且按照结果集的第一个列进行排序&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">　minus:得到两个查询结果的减集，以第一列进行排序&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">例子：&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">　　下面是两个表：一个主修课程表，一个选修课程表。&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">这个是主修课程表：minors&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">　　 &nbsp; create table minors(&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; 　minor_id number primary key,&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp; 　 &nbsp;minor_name varchar2(30) not null,&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;　 credit_hour number(2)&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp;　 &nbsp;)&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">插入３条记录：　　　　　　　　　　　　　　　&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">　　 &nbsp; &nbsp;insert into minors values(10101,'计算机原理',4)&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; 　 insert into minors values(10201,'自动控制原理',3)&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; 　 insert into minors values(10301,'工程制图原理',4)&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">下面创建选修课程表minors2&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">　 &nbsp; &nbsp; &nbsp;create table minors2(&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minor_id number primary key,&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minor_name varchar2(30) not null,&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;credit_hour number(2)&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;)&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">插入两条记录：&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; insert into minors2 values(10201,'自动控制原理',3)&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;insert into minors2 values(10301,'工程制图原理',4) &nbsp;&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">两个表使用union all:得到如下结果&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; select minor_id,minor_name,credit_hour from minors union all&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;select minor_id,minor_name,credit_hour from minors2 order by &nbsp; &nbsp; credit_hour&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">结果：&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp;&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">MINOR_ID MINOR_NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CREDIT_HOUR&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">---------- ------------------------------ -----------&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;10201 自动控制原理 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;10201 自动控制原理 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;10101 计算机原理 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;10301 工程制图原理 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;10301 工程制图原理 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">两个表使用union　:得到如下结果&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">select minor_id,minor_name,credit_hour from minors union&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; select minor_id,minor_name,credit_hour from minors2 order by credit_hour&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">结果：&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">MINOR_ID MINOR_NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CREDIT_HOUR&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">---------- ------------------------------ -----------&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;10201 自动控制原理 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;10101 计算机原理 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;10301 工程制图原理 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">两个表使用intersect　:得到如下结果&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;select minor_id,minor_name,credit_hour from minors intersect&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; select minor_id,minor_name,credit_hour from minors2&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">结果：&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">MINOR_ID MINOR_NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CREDIT_HOUR&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">---------- ------------------------------ -----------&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;10201 自动控制原理 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;10301 工程制图原理 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">两个表使用minus　:得到如下结果&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; select minor_id,minor_name,credit_hour from minors minus&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; select minor_id,minor_name,credit_hour from minors2&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">结果：&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;"><br /></span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">MINOR_ID MINOR_NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CREDIT_HOUR&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">---------- ------------------------------ -----------&nbsp;</span></div><div><span class="Apple-style-span" style="font-size: 14px; font-weight: normal;">&nbsp; &nbsp; &nbsp;10101 计算机原理 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4</span></div></div></div><br /></a><div style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 12px; line-height: 18px; color: #006600; "><div style="color: #000000; "><span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; font-weight: normal; "><div><div><div><div><span style="color: #333333; font-family: tahoma, arial, 宋体, sans-serif; font-size: 14px; line-height: 21px; "></span></div></div></div></div></span></div></div><font class="Apple-style-span" face="Helvetica, Tahoma, Arial, sans-serif"><span class="Apple-style-span" style="font-size: 12px; line-height: 18px;"><a href="http://hck.iteye.com/blog/966966"></a></span></font></h3></div><img src ="http://www.blogjava.net/GavinMiao/aggbug/356800.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/GavinMiao/" target="_blank">GavinMiao</a> 2011-08-18 17:34 <a href="http://www.blogjava.net/GavinMiao/archive/2011/08/18/356800.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>