﻿<?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/japper/category/51720.html</link><description>好的想法总是无穷无尽</description><language>zh-cn</language><lastBuildDate>Thu, 27 Jun 2013 01:44:41 GMT</lastBuildDate><pubDate>Thu, 27 Jun 2013 01:44:41 GMT</pubDate><ttl>60</ttl><item><title>ORACLE复制千万级数据表时用的存储过程</title><link>http://www.blogjava.net/japper/archive/2012/07/09/382610.html</link><dc:creator>japper</dc:creator><author>japper</author><pubDate>Mon, 09 Jul 2012 07:06:00 GMT</pubDate><guid>http://www.blogjava.net/japper/archive/2012/07/09/382610.html</guid><wfw:comment>http://www.blogjava.net/japper/comments/382610.html</wfw:comment><comments>http://www.blogjava.net/japper/archive/2012/07/09/382610.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/japper/comments/commentRss/382610.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/japper/services/trackbacks/382610.html</trackback:ping><description><![CDATA[CREATE OR REPLACE PROCEDURE "LARGEDATA_INSERT" (ip_table_name&nbsp;&nbsp; in varchar2, --目标表<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ip_table_column in varchar2, --目标字段<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ip_table_select in varchar2, --SELECT 查询语句<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return_result&nbsp;&nbsp; out number --返回的结果1,表示成功，０表示失败<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) as<br />--适合大数据量的插入模板&nbsp; create Templates by chenzhoumin 20110614<br />&nbsp; runTime number;--运行总次数<br />&nbsp; i&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; number;--当前行数<br />&nbsp; amount&nbsp; number;--总行数<br />&nbsp; s_sql&nbsp;&nbsp; varchar2(10000);--SQL语句<br />&nbsp; e_sql&nbsp;&nbsp; varchar2(10000);--执行SQL语句<br />&nbsp; countNumber number;--一次插入的数据量<br />begin<br />&nbsp; --set serveroutput on size 20000000000000<br />&nbsp; countNumber := 10000;<br />&nbsp; return_result := 0; --开始初始化为0<br />&nbsp; --核必逻辑内容，可根据具体的业务逻辑来定义,统计数据总行数<br />&nbsp; s_sql := 'select count(1) from (' || ip_table_select || ')';<br />&nbsp; execute immediate s_sql<br />&nbsp;&nbsp;&nbsp; into amount;<br />&nbsp; --每100万提交一次<br />&nbsp; runTime := amount mod countNumber;<br />&nbsp; if (runTime &gt; 0) then<br />&nbsp;&nbsp;&nbsp; runTime := 1 + trunc(amount / countNumber);<br />&nbsp; end if;<br />&nbsp; if (runTime = 0) then<br />&nbsp;&nbsp;&nbsp; runTime := 0 + trunc(amount / countNumber);<br />&nbsp; end if;<br />&nbsp; FOR i IN 1 .. runTime LOOP<br />&nbsp;&nbsp;&nbsp; e_sql := 'insert into '||ip_table_name ||'<br />&nbsp;&nbsp;&nbsp; ('||ip_table_column ||')<br />&nbsp;&nbsp;&nbsp;&nbsp; select '|| ip_table_column ||'<br />&nbsp;&nbsp;&nbsp;&nbsp; from<br />&nbsp;&nbsp;&nbsp;&nbsp; (select selectSec.*, rownum rownumType<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from ('|| ip_table_select ||') selectSec<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE ROWNUM &lt;= '|| i * countNumber ||')<br />&nbsp;&nbsp;&nbsp; WHERE rownumType &gt; '||(i - 1) * countNumber;<br />&nbsp;&nbsp;&nbsp; dbms_output.enable(99999999999999);<br />&nbsp;&nbsp;&nbsp; dbms_output.put_line(e_sql);<br />&nbsp;&nbsp;&nbsp; execute immediate e_sql;<br />&nbsp;&nbsp;&nbsp; --提交<br />&nbsp;&nbsp;&nbsp; commit;<br />&nbsp; END LOOP;<br />&nbsp; return_result := 1;<br />&nbsp; return;<br />exception<br />&nbsp; when others then<br />&nbsp;&nbsp;&nbsp; return_result := 0;<br />&nbsp;&nbsp;&nbsp; raise;<br />&nbsp;&nbsp;&nbsp; dbms_output.enable(99999999999999);<br />&nbsp;&nbsp;&nbsp; dbms_output.put_line('结束');<br />&nbsp;&nbsp;&nbsp; return;<br />end;<br /><br /><br /><br />以上测试通过。<img src ="http://www.blogjava.net/japper/aggbug/382610.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/japper/" target="_blank">japper</a> 2012-07-09 15:06 <a href="http://www.blogjava.net/japper/archive/2012/07/09/382610.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ORACLE所在linux盘符空间不足的解决办法</title><link>http://www.blogjava.net/japper/archive/2012/07/02/381987.html</link><dc:creator>japper</dc:creator><author>japper</author><pubDate>Mon, 02 Jul 2012 06:14:00 GMT</pubDate><guid>http://www.blogjava.net/japper/archive/2012/07/02/381987.html</guid><wfw:comment>http://www.blogjava.net/japper/comments/381987.html</wfw:comment><comments>http://www.blogjava.net/japper/archive/2012/07/02/381987.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/japper/comments/commentRss/381987.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/japper/services/trackbacks/381987.html</trackback:ping><description><![CDATA[<div>ORACLE数据库空间不足，会发生登录出错，数据无法插入等错误发生，可以根据实际错误代码查询原因，不过更多是平时多看看数据库空间是否足够；<br />解决办法有两个：<br />1、使用linux命令或者工具增加空间或者增加硬盘，没有实际操作过；<br />2、给oracel数据库增加系统表空间和临时表空间，记录下操作方法：<br />
<p>如果临时表空间或者SYSTEM表空间不足，可以进行新增数据文件到其它盘符（增加opt盘符目录）：<br />select ts#, name from v$datafile;--查看当前的表空间状况<br />select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';--查看默认的临时文件<br />create temporary tablespace temp2 tempfile '/opt/oracle/oracle_tmp/temp02.dbf' size 5000M autoextend on next 100M; --新增临时文件<br />alter database default temporary tablespace "TEMP2";&nbsp; --修改默认临时文件设置<br />alter database tempfile '/home/oracle/oracle/oradata/portal/temp01.dbf' autoextend off;&nbsp; --关闭原来的临时文件自增长<br />增加系统表空间：<br />alter tablespace SYSTEM add datafile '/opt/oracle/oracle_tmp/system02.dbf' size 500M autoextend on next 5M; <br /><br /></p>
<p>如果startup数据库时，提示：prifile文件找不到，可以从一个$ORACLE_BASE/admin/portal/pfile目录下拷贝内容过去就可以(注意文件命名和原来使用的保持一样，只是内容不同)：<br />当前正在使用的pfile：startup force pfile='/home/oracle/oracle/product/11.0.1/db_1/dbs/initportal.ora';<br />拷贝：cp $ORACLE_BASE/admin/portal/pfile/init.ora.452011185827&nbsp;&nbsp; /home/oracle/oracle/product/11.0.1/db_1/dbs/spfileportal.ora</p></div><img src ="http://www.blogjava.net/japper/aggbug/381987.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/japper/" target="_blank">japper</a> 2012-07-02 14:14 <a href="http://www.blogjava.net/japper/archive/2012/07/02/381987.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle 临时表空间的增删改查</title><link>http://www.blogjava.net/japper/archive/2012/06/28/381721.html</link><dc:creator>japper</dc:creator><author>japper</author><pubDate>Thu, 28 Jun 2012 06:54:00 GMT</pubDate><guid>http://www.blogjava.net/japper/archive/2012/06/28/381721.html</guid><wfw:comment>http://www.blogjava.net/japper/comments/381721.html</wfw:comment><comments>http://www.blogjava.net/japper/archive/2012/06/28/381721.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/japper/comments/commentRss/381721.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/japper/services/trackbacks/381721.html</trackback:ping><description><![CDATA[<h2 class="title content-title">oracle 临时表空间的增删改查</h2>
<div id="content" class="content text-content clearfix">
<p><strong>1、查看临时表空间 </strong>（dba_temp_files视图）（v_$tempfile视图）<br />select tablespace_name,file_name,bytes/1024/1024 file_size,autoextensible from dba_temp_files;<br />select status,enabled, name, bytes/1024/1024 file_size from v_$tempfile;--sys用户查看<br /><br /><strong>2、缩小临时表空间大小</strong><br />alter database tempfile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\TELEMT\TEMP01.DBF' resize 100M;<br /><br /><strong>3、扩展临时表空间：</strong><br />方法一、增大临时文件大小：<br />SQL&gt; alter database tempfile &#8216;/u01/app/oracle/oradata/orcl/temp01.dbf&#8217; resize 100m;<br />方法二、将临时数据文件设为自动扩展：<br />SQL&gt; alter database tempfile &#8216;/u01/app/oracle/oradata/orcl/temp01.dbf&#8217; autoextend on next 5m maxsize unlimited;<br />方法三、向临时表空间中添加数据文件：<br />SQL&gt; alter tablespace temp add tempfile &#8216;/u01/app/oracle/oradata/orcl/temp02.dbf&#8217; size 100m;<br /><br /><strong>4、创建临时表空间</strong>：<br />SQL&gt; create temporary tablespace temp1 tempfile &#8216;/u01/app/oracle/oradata/orcl/temp11.dbf&#8217; size 10M;<br /><br /><strong>5、更改系统的默认临时表空间：</strong><br />--查询默认临时表空间<br />select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';<br />--修改默认临时表空间<br />alter database default temporary tablespace temp1;<br />所有用户的默认临时表空间都将切换为新的临时表空间：<br />select username,temporary_tablespace,default_ from dba_users;<br />--更改某一用户的临时表空间：<br />alter user scott temporary tablespace temp;<br /><br /><strong>6、删除临时表空间</strong><br />删除临时表空间的一个数据文件：<br />SQL&gt; alter database tempfile &#8216;/u01/app/oracle/oradata/orcl/temp02.dbf&#8217; drop;<br />删除临时表空间(彻底删除)：<br />SQL&gt; drop tablespace temp1 including contents and datafiles cascade constraints;<br /><br /><strong>7、查看临时表空间的使用情况</strong>（GV_$TEMP_SPACE_HEADER视图必须在sys用户下才能查询）<br />GV_$TEMP_SPACE_HEADER视图记录了临时表空间的使用大小与未使用的大小<br />dba_temp_files视图的bytes字段记录的是临时表空间的总大小<br />SELECT temp_used.tablespace_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; total - used as "Free",<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; total as "Total",<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; round(nvl(total - used, 0) * 100 / total, 3) "Free percent"<br />&nbsp; FROM (SELECT tablespace_name, SUM(bytes_used) / 1024 / 1024 used<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM GV_$TEMP_SPACE_HEADER<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GROUP BY tablespace_name) temp_used,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (SELECT tablespace_name, SUM(bytes) / 1024 / 1024 total<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM dba_temp_files<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GROUP BY tablespace_name) temp_total<br />&nbsp;WHERE temp_used.tablespace_name = temp_total.tablespace_name<br /><br /><strong>8、查找消耗资源比较的sql语句</strong><br />Select se.username,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se.sid,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; su.extents,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; su.blocks * to_number(rtrim(p.value)) as Space,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tablespace,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; segtype,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sql_text<br />&nbsp; from v$sort_usage su, v$parameter p, v$session se, v$sql s<br />&nbsp;where p.name = 'db_block_size'<br />&nbsp;&nbsp; and su.session_addr = se.saddr<br />&nbsp;&nbsp; and s.hash_value = su.sqlhash<br />&nbsp;&nbsp; and s.address = su.sqladdr<br />&nbsp;order by se.username, se.sid<br />&nbsp;<br /><strong>9、查看当前临时表空间使用大小与正在占用临时表空间的sql语句</strong><br />select sess.SID, segtype, blocks * 8 / 1000 "MB", sql_text<br />&nbsp; from v$sort_usage sort, v$session sess, v$sql sql<br />&nbsp;where sort.SESSION_ADDR = sess.SADDR<br />&nbsp;&nbsp; and sql.ADDRESS = sess.SQL_ADDRESS<br />&nbsp;order by blocks desc;<br /><br /><strong>10、临时表空间组介绍</strong><br />&nbsp; 1）创建临时表空间组：<br />create temporary tablespace tempts1 tempfile '/home/oracle/temp1_02.dbf' size 2M tablespace group group1;<br />create temporary tablespace tempts2 tempfile '/home/oracle/temp2_02.dbf' size 2M tablespace group group2;<br />&nbsp;<br />&nbsp;2）查询临时表空间组：dba_tablespace_groups视图<br />select * from dba_tablespace_groups;<br />GROUP_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TABLESPACE_NAME<br />------------------------------ ------------------------------<br />GROUP1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TEMPTS1<br />GROUP2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TEMPTS2<br /><br />&nbsp;3）将表空间从一个临时表空间组移动到另外一个临时表空间组：<br />alter tablespace tempts1 tablespace group GROUP2 ;<br />select * from dba_tablespace_groups;<br /><br />GROUP_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TABLESPACE_NAME<br />------------------------------ ------------------------------<br />GROUP2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TEMPTS1<br />GROUP2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TEMPTS2<br /><br />&nbsp;4）把临时表空间组指定给用户<br />alter user scott temporary tablespace GROUP2;<br /><br />&nbsp;5）在数据库级设置临时表空间<br />alter database &lt;db_name&gt; default temporary tablespace GROUP2; <br /><br />&nbsp;6）删除临时表空间组 (删除组成临时表空间组的所有临时表空间)<br />drop tablespace tempts1 including contents and datafiles;<br />select * from dba_tablespace_groups;<br />GROUP_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TABLESPACE_NAME<br />------------------------------ ------------------------------<br />GROUP2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TEMPTS2<br /><br />drop tablespace tempts2 including contents and datafiles;<br />select * from dba_tablespace_groups;<br />GROUP_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TABLESPACE_NAME<br /><br /><strong>11、对临时表空间进行shrink（11g新增的功能）</strong><br />--将temp表空间收缩为20M<br />alter tablespace temp shrink space keep 20M; <br />--自动将表空间的临时文件缩小到最小可能的大小<br />ALTER TABLESPACE temp SHRINK TEMPFILE &#8217;/u02/oracle/data/lmtemp02.dbf&#8217;; <br /><br /><strong>临时表空间作用</strong><br />Oracle临时表空间主要用来做查询和存放一些缓冲区数据。临时表空间消耗的主要原因是需要对查询的中间结果进行排序。<br />重启数据库可以释放临时表空间，如果不能重启实例，而一直保持问题sql语句的执行，temp表空间会一直增长。直到耗尽硬盘空间。<br />网上有人猜测在磁盘空间的分配上，oracle使用的是贪心算法，如果上次磁盘空间消耗达到1GB，那么临时表空间就是1GB。<br />也就是说当前临时表空间文件的大小是历史上使用临时表空间最大的大小。<br /><br />临时表空间的主要作用：<br />&nbsp; 索引create或rebuild；<br />&nbsp; Order by 或 group by；<br />&nbsp; Distinct 操作；<br />&nbsp; Union 或 intersect 或 minus；<br />&nbsp; Sort-merge joins；<br />&nbsp; analyze.</p></div><img src ="http://www.blogjava.net/japper/aggbug/381721.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/japper/" target="_blank">japper</a> 2012-06-28 14:54 <a href="http://www.blogjava.net/japper/archive/2012/06/28/381721.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle sql日期比较（转）</title><link>http://www.blogjava.net/japper/archive/2012/05/21/378659.html</link><dc:creator>japper</dc:creator><author>japper</author><pubDate>Mon, 21 May 2012 02:44:00 GMT</pubDate><guid>http://www.blogjava.net/japper/archive/2012/05/21/378659.html</guid><wfw:comment>http://www.blogjava.net/japper/comments/378659.html</wfw:comment><comments>http://www.blogjava.net/japper/archive/2012/05/21/378659.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/japper/comments/commentRss/378659.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/japper/services/trackbacks/378659.html</trackback:ping><description><![CDATA[<pre>（转）oracle sql日期比较:<br />在今天之前:<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 1006px; padding-right: 5px; font-size: 13px; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><span style="color: #0000ff">select</span>&nbsp;<span style="color: #808080">*</span>&nbsp;<span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;up_date&nbsp;</span><span style="color: #0000ff">where</span>&nbsp;<span style="color: #0000ff">update</span>&nbsp;<span style="color: #808080">&lt;</span><span style="color: #000000">&nbsp;to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07&nbsp;00:00:00</span><span style="color: #ff0000">'</span><span style="color: #000000">,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">yyyy-mm-dd&nbsp;hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)<br /></span><span style="color: #0000ff">select</span>&nbsp;<span style="color: #808080">*</span>&nbsp;<span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;up_date&nbsp;</span><span style="color: #0000ff">where</span>&nbsp;<span style="color: #0000ff">update</span>&nbsp;<span style="color: #808080">&lt;=</span><span style="color: #000000">&nbsp;to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07&nbsp;00:00:00</span><span style="color: #ff0000">'</span><span style="color: #000000">,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">yyyy-mm-dd&nbsp;hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)</span></div><br />在今天只后:<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 1006px; padding-right: 5px; font-size: 13px; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><span style="color: #0000ff">select</span>&nbsp;<span style="color: #808080">*</span>&nbsp;<span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;up_date&nbsp;</span><span style="color: #0000ff">where</span>&nbsp;<span style="color: #0000ff">update</span>&nbsp;<span style="color: #808080">&gt;</span><span style="color: #000000">&nbsp;to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07&nbsp;00:00:00</span><span style="color: #ff0000">'</span><span style="color: #000000">,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">yyyy-mm-dd&nbsp;hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)<br /></span><span style="color: #0000ff">select</span>&nbsp;<span style="color: #808080">*</span>&nbsp;<span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;up_date&nbsp;</span><span style="color: #0000ff">where</span>&nbsp;<span style="color: #0000ff">update</span>&nbsp;<span style="color: #808080">&gt;=</span><span style="color: #000000">&nbsp;to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07&nbsp;00:00:00</span><span style="color: #ff0000">'</span><span style="color: #000000">,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">yyyy-mm-dd&nbsp;hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)</span></div><br />精确时间:<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 1006px; padding-right: 5px; font-size: 13px; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><span style="color: #0000ff">select</span>&nbsp;<span style="color: #808080">*</span>&nbsp;<span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;up_date&nbsp;</span><span style="color: #0000ff">where</span>&nbsp;<span style="color: #0000ff">update</span>&nbsp;<span style="color: #808080">=</span><span style="color: #000000">&nbsp;to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07&nbsp;00:00:00</span><span style="color: #ff0000">'</span><span style="color: #000000">,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">yyyy-mm-dd&nbsp;hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)</span></div><br />在某段时间内:<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 1006px; padding-right: 5px; font-size: 13px; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><span style="color: #0000ff">select</span>&nbsp;<span style="color: #808080">*</span>&nbsp;<span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;up_date&nbsp;</span><span style="color: #0000ff">where</span>&nbsp;<span style="color: #0000ff">update</span>&nbsp;<span style="color: #808080">between</span><span style="color: #000000">&nbsp;to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-07-07&nbsp;00:00:00</span><span style="color: #ff0000">'</span><span style="color: #000000">,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">yyyy-mm-dd&nbsp;hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)&nbsp;</span><span style="color: #808080">and</span><span style="color: #000000">&nbsp;to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07&nbsp;00:00:00</span><span style="color: #ff0000">'</span><span style="color: #000000">,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">yyyy-mm-dd&nbsp;hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)<br /></span><span style="color: #0000ff">select</span>&nbsp;<span style="color: #808080">*</span>&nbsp;<span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;up_date&nbsp;</span><span style="color: #0000ff">where</span>&nbsp;<span style="color: #0000ff">update</span>&nbsp;<span style="color: #808080">&lt;</span><span style="color: #000000">&nbsp;to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07&nbsp;00:00:00</span><span style="color: #ff0000">'</span><span style="color: #000000">,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">yyyy-mm-dd&nbsp;hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)&nbsp;</span><span style="color: #808080">and</span>&nbsp;<span style="color: #0000ff">update</span>&nbsp;<span style="color: #808080">&gt;</span><span style="color: #000000">&nbsp;to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-07-07&nbsp;00:00:00</span><span style="color: #ff0000">'</span><span style="color: #000000">,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">yyyy-mm-dd&nbsp;hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)<br /></span><span style="color: #0000ff">select</span>&nbsp;<span style="color: #808080">*</span>&nbsp;<span style="color: #0000ff">from</span><span style="color: #000000">&nbsp;up_date&nbsp;</span><span style="color: #0000ff">where</span>&nbsp;<span style="color: #0000ff">update</span>&nbsp;<span style="color: #808080">&lt;=</span><span style="color: #000000">&nbsp;to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07&nbsp;00:00:00</span><span style="color: #ff0000">'</span><span style="color: #000000">,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">yyyy-mm-dd&nbsp;hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)&nbsp;</span><span style="color: #808080">and</span>&nbsp;<span style="color: #0000ff">update</span>&nbsp;<span style="color: #808080">&gt;=</span><span style="color: #000000">&nbsp;to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-07-07&nbsp;00:00:00</span><span style="color: #ff0000">'</span><span style="color: #000000">,</span><span style="color: #ff0000">'</span><span style="color: #ff0000">yyyy-mm-dd&nbsp;hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)</span></div><div><span style="color: #000000"><br /></span></div><p>&nbsp;</p><span style="line-height: 18px; font-family: Arial; color: #555b6e; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px"><table style="line-height: normal; width: 1006px; table-layout: fixed"><tbody style="line-height: normal"><tr style="line-height: normal"><td style="filter: none; line-height: normal; zoom: 1 !important; font-family: Arial; word-wrap: break-word; visibility: visible !important; font-size: 12px; word-break: break-all"><div style="position: static; filter: none; line-height: normal; overflow-x: hidden; overflow-y: hidden; zoom: 1 !important; font-family: Arial; word-wrap: break-word; visibility: visible !important; font-size: 12px; word-break: normal"><span style="line-height: normal; color: #800080">1</span><span style="line-height: normal; color: #000000">. 当前系统日期、时间<br style="line-height: normal" />select getdate()&nbsp;<br style="line-height: normal" /></span><span style="line-height: normal; color: #800080">2</span><span style="line-height: normal; color: #000000">. dateadd 在向指定日期加上一段时间的基础上，返回新的 datetime 值<br style="line-height: normal" />例如：向日期加上2天<br style="line-height: normal" />select dateadd(day,</span><span style="line-height: normal; color: #800080">2</span><span style="line-height: normal; color: #000000">,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2004-10-15</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">) --返回：</span><span style="line-height: normal; color: #800080">2004</span><span style="line-height: normal; color: #000000">-</span><span style="line-height: normal; color: #800080">10</span><span style="line-height: normal; color: #000000">-</span><span style="line-height: normal; color: #800080">17</span>&nbsp;<span style="line-height: normal; color: #800080">00</span><span style="line-height: normal; color: #000000">:</span><span style="line-height: normal; color: #800080">00</span><span style="line-height: normal; color: #000000">:</span><span style="line-height: normal; color: #800080">00</span><span style="line-height: normal; color: #000000">.</span><span style="line-height: normal; color: #800080">000</span><span style="line-height: normal; color: #000000"><br style="line-height: normal" /><br style="line-height: normal" /></span><span style="line-height: normal; color: #800080">3</span><span style="line-height: normal; color: #000000">. datediff 返回跨两个指定日期的日期和时间边界数。<br style="line-height: normal" />select datediff(day,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2004-09-01</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2004-09-18</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">) --返回：</span><span style="line-height: normal; color: #800080">17</span><span style="line-height: normal; color: #000000"><br style="line-height: normal" /><br style="line-height: normal" /></span><span style="line-height: normal; color: #800080">4</span><span style="line-height: normal; color: #000000">. datepart 返回代表指定日期的指定日期部分的整数。<br style="line-height: normal" />SELECT DATEPART(month,&nbsp;</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2004-10-15</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">) --返回&nbsp;</span><span style="line-height: normal; color: #800080">10</span><span style="line-height: normal; color: #000000"><br style="line-height: normal" /><br style="line-height: normal" /></span><span style="line-height: normal; color: #800080">5</span><span style="line-height: normal; color: #000000">. datename 返回代表指定日期的指定日期部分的字符串<br style="line-height: normal" />SELECT datename(weekday,&nbsp;</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2004-10-15</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">) --返回：星期五<br style="line-height: normal" /><br style="line-height: normal" /></span><span style="line-height: normal; color: #800080">6</span><span style="line-height: normal; color: #000000">. day(), month(),year() --可以与datepart对照一下<br style="line-height: normal" /><br style="line-height: normal" />select 当前日期=convert(varchar(</span><span style="line-height: normal; color: #800080">10</span><span style="line-height: normal; color: #000000">),getdate(),</span><span style="line-height: normal; color: #800080">120</span><span style="line-height: normal; color: #000000">)<br style="line-height: normal" />,当前时间=convert(varchar(</span><span style="line-height: normal; color: #800080">8</span><span style="line-height: normal; color: #000000">),getdate(),</span><span style="line-height: normal; color: #800080">114</span><span style="line-height: normal; color: #000000">)<br style="line-height: normal" /><br style="line-height: normal" /></span><span style="line-height: normal; color: #800080">7</span><span style="line-height: normal; color: #000000">. select datename(dw,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2004-10-15</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">)<br style="line-height: normal" /><br style="line-height: normal" />select 本年第多少周=datename(week,getdate())<br style="line-height: normal" />,今天是周几=datename(weekday,getdate())<br style="line-height: normal" /><br style="line-height: normal" /><br style="line-height: normal" /><br style="line-height: normal" />函数 参数/功能&nbsp;<br style="line-height: normal" />GetDate( ) --返回系统目前的日期与时间&nbsp;<br style="line-height: normal" />DateDiff (interval,date1,date2) --以interval 指定的方式，返回date2 与date1两个日期之间的差值 date2-date1&nbsp;<br style="line-height: normal" />DateAdd (interval,number,date) --以interval指定的方式，加上number之后的日期&nbsp;<br style="line-height: normal" />DatePart (interval,date) ---返回日期date中，interval指定部分所对应的整数值&nbsp;<br style="line-height: normal" />DateName (interval,date) --返回日期date中，interval指定部分所对应的字符串名称&nbsp;<br style="line-height: normal" /><br style="line-height: normal" />参数 interval的设定值如下：<br style="line-height: normal" /><br style="line-height: normal" />值 缩 写（Sql Server） Access 和 ASP 说明&nbsp;<br style="line-height: normal" />Year Yy yyyy 年&nbsp;</span><span style="line-height: normal; color: #800080">1753</span><span style="line-height: normal; color: #000000">&nbsp;~&nbsp;</span><span style="line-height: normal; color: #800080">9999</span><span style="line-height: normal; color: #000000">&nbsp;<br style="line-height: normal" />Quarter Qq q 季&nbsp;</span><span style="line-height: normal; color: #800080">1</span><span style="line-height: normal; color: #000000">&nbsp;~&nbsp;</span><span style="line-height: normal; color: #800080">4</span><span style="line-height: normal; color: #000000">&nbsp;<br style="line-height: normal" />Month Mm m 月1 ~&nbsp;</span><span style="line-height: normal; color: #800080">12</span><span style="line-height: normal; color: #000000">&nbsp;<br style="line-height: normal" />Day of year Dy y 一年的日数,一年中的第几日&nbsp;</span><span style="line-height: normal; color: #800080">1</span><span style="line-height: normal; color: #000000">-</span><span style="line-height: normal; color: #800080">366</span><span style="line-height: normal; color: #000000">&nbsp;<br style="line-height: normal" />Day Dd d 日，</span><span style="line-height: normal; color: #800080">1</span><span style="line-height: normal; color: #000000">-</span><span style="line-height: normal; color: #800080">31</span><span style="line-height: normal; color: #000000">&nbsp;<br style="line-height: normal" />Weekday Dw w 一周的日数，一周中的第几日&nbsp;</span><span style="line-height: normal; color: #800080">1</span><span style="line-height: normal; color: #000000">-</span><span style="line-height: normal; color: #800080">7</span><span style="line-height: normal; color: #000000">&nbsp;<br style="line-height: normal" />Week Wk ww 周，一年中的第几周&nbsp;</span><span style="line-height: normal; color: #800080">0</span><span style="line-height: normal; color: #000000">&nbsp;~&nbsp;</span><span style="line-height: normal; color: #800080">51</span><span style="line-height: normal; color: #000000">&nbsp;<br style="line-height: normal" />Hour Hh h 时0 ~&nbsp;</span><span style="line-height: normal; color: #800080">23</span><span style="line-height: normal; color: #000000">&nbsp;<br style="line-height: normal" />Minute Mi n 分钟0 ~&nbsp;</span><span style="line-height: normal; color: #800080">59</span><span style="line-height: normal; color: #000000">&nbsp;<br style="line-height: normal" />Second Ss s 秒&nbsp;</span><span style="line-height: normal; color: #800080">0</span><span style="line-height: normal; color: #000000">&nbsp;~&nbsp;</span><span style="line-height: normal; color: #800080">59</span><span style="line-height: normal; color: #000000">&nbsp;<br style="line-height: normal" />Millisecond Ms - 毫秒&nbsp;</span><span style="line-height: normal; color: #800080">0</span><span style="line-height: normal; color: #000000">&nbsp;~&nbsp;</span><span style="line-height: normal; color: #800080">999</span><span style="line-height: normal; color: #000000">&nbsp;<br style="line-height: normal" /><br style="line-height: normal" />access 和 asp 中用date()和now()取得系统日期时间；其中DateDiff,DateAdd,DatePart也同是能用于Access和asp中，这些函数的用法也类似<br style="line-height: normal" /><br style="line-height: normal" />举例：<br style="line-height: normal" /></span><span style="line-height: normal; color: #800080">1</span><span style="line-height: normal; color: #000000">.GetDate() 用于sql server :select GetDate()<br style="line-height: normal" /><br style="line-height: normal" /></span><span style="line-height: normal; color: #800080">2</span><span style="line-height: normal; color: #000000">.DateDiff(</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">s</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2005-07-20</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2005-7-25 22:56:32</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">)返回值为&nbsp;</span><span style="line-height: normal; color: #800080">514592</span><span style="line-height: normal; color: #000000">&nbsp;秒<br style="line-height: normal" />DateDiff(</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">d</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2005-07-20</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2005-7-25 22:56:32</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">)返回值为&nbsp;</span><span style="line-height: normal; color: #800080">5</span><span style="line-height: normal; color: #000000">&nbsp;天<br style="line-height: normal" /><br style="line-height: normal" /></span><span style="line-height: normal; color: #800080">3</span><span style="line-height: normal; color: #000000">.DatePart(</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">w</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2005-7-25 22:56:32</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">)返回值为&nbsp;</span><span style="line-height: normal; color: #800080">2</span><span style="line-height: normal; color: #000000">&nbsp;即星期一(周日为1，周六为7)<br style="line-height: normal" />DatePart(</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">d</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2005-7-25 22:56:32</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">)返回值为 25即25号<br style="line-height: normal" />DatePart(</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">y</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2005-7-25 22:56:32</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">)返回值为 206即这一年中第206天<br style="line-height: normal" />DatePart(</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">yyyy</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">,</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">2005-7-25 22:56:32</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">)返回值为 2005即2005年&nbsp;<br style="line-height: normal" /><br style="line-height: normal" />SQL Server DATEPART() 函数返回 SQLServer datetime 字段的一部分。&nbsp;<br style="line-height: normal" /><br style="line-height: normal" />SQL Server DATEPART() 函数的语法是：&nbsp;<br style="line-height: normal" />DATEPART(portion, datetime)<br style="line-height: normal" /><br style="line-height: normal" />其中 datetime 是 SQLServer datetime 字段和部分的名称是下列之一： Ms for Milliseconds<br style="line-height: normal" />Yy for Year<br style="line-height: normal" />Qq for Quarter of the Year<br style="line-height: normal" />Mm for Month<br style="line-height: normal" />Dy for the Day of the Year<br style="line-height: normal" />Dd for Day of the Month<br style="line-height: normal" />Wk for Week<br style="line-height: normal" />Dw for the Day of the Week<br style="line-height: normal" />Hh for Hour<br style="line-height: normal" />Mi for Minute<br style="line-height: normal" />Ss for Second<br style="line-height: normal" /><br style="line-height: normal" /><br style="line-height: normal" />--</span><span style="line-height: normal; color: #800080">1</span><span style="line-height: normal; color: #000000">.编写函数，实现按照</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">年月日，星期几,上午下午晚上</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">输出时间信息(2009年3月16日星期一下午)<br style="line-height: normal" />select datename(yy,getdate()) +&nbsp;</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">年</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">&nbsp;+<br style="line-height: normal" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; datename(mm,getdate()) +&nbsp;</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">月</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">&nbsp;+&nbsp;<br style="line-height: normal" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; datename(dd,getdate()) +&nbsp;</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">日</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">&nbsp;+<br style="line-height: normal" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; datename(weekday,getdate()) +<br style="line-height: normal" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case when datename(hh,getdate()) &lt;&nbsp;</span><span style="line-height: normal; color: #800080">12</span><span style="line-height: normal; color: #000000">&nbsp;then&nbsp;</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">上午</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">&nbsp;else&nbsp;</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">下午</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">end&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="line-height: normal" />--</span><span style="line-height: normal; color: #800080">2</span><span style="line-height: normal; color: #000000">.编写函数，根据输入时间。输出该天是该年的第几天<br style="line-height: normal" />select datepart(dy,getdate())<br style="line-height: normal" />--</span><span style="line-height: normal; color: #800080">3</span><span style="line-height: normal; color: #000000">.求出随机输出字符&#8216;a-z<br style="line-height: normal" />select char(</span><span style="line-height: normal; color: #800080">97</span><span style="line-height: normal; color: #000000">+abs(checksum(newid()))%</span><span style="line-height: normal; color: #800080">26</span><span style="line-height: normal; color: #000000">)<br style="line-height: normal" />select char(</span><span style="line-height: normal; color: #800080">97</span><span style="line-height: normal; color: #000000">+rand()*</span><span style="line-height: normal; color: #800080">26</span><span style="line-height: normal; color: #000000">)</span></div></td></tr></tbody></table></span></pre><img src ="http://www.blogjava.net/japper/aggbug/378659.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/japper/" target="_blank">japper</a> 2012-05-21 10:44 <a href="http://www.blogjava.net/japper/archive/2012/05/21/378659.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>