??xml version="1.0" encoding="utf-8" standalone="yes"?>99久久精品免费看国产小宝寻花,蜜乳av一区,日本中文字幕一区二区有码在线http://www.aygfsteel.com/japper/category/51720.html好的xL无穷无尽zh-cnThu, 27 Jun 2013 01:44:41 GMTThu, 27 Jun 2013 01:44:41 GMT60ORACLE复制千万U数据表时用的存储过E?/title><link>http://www.aygfsteel.com/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.aygfsteel.com/japper/archive/2012/07/09/382610.html</guid><wfw:comment>http://www.aygfsteel.com/japper/comments/382610.html</wfw:comment><comments>http://www.aygfsteel.com/japper/archive/2012/07/09/382610.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/japper/comments/commentRss/382610.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/japper/services/trackbacks/382610.html</trackback:ping><description><![CDATA[CREATE OR REPLACE PROCEDURE "LARGEDATA_INSERT" (ip_table_name   in varchar2, --目标?br />                                          ip_table_column in varchar2, --目标字段<br />                                          ip_table_select in varchar2, --SELECT 查询语句<br />                                          return_result   out number --q回的结?,表示成功Q0表示p|<br />                                          ) as<br />--适合大数据量的插入模?nbsp; create Templates by chenzhoumin 20110614<br />  runTime number;--q行L?br />  i       number;--当前行数<br />  amount  number;--总行?br />  s_sql   varchar2(10000);--SQL语句<br />  e_sql   varchar2(10000);--执行SQL语句<br />  countNumber number;--一ơ插入的数据?br />begin<br />  --set serveroutput on size 20000000000000<br />  countNumber := 10000;<br />  return_result := 0; --开始初始化?<br />  --核必逻辑内容Q可Ҏ具体的业务逻辑来定?l计数据总行?br />  s_sql := 'select count(1) from (' || ip_table_select || ')';<br />  execute immediate s_sql<br />    into amount;<br />  --?00万提交一?br />  runTime := amount mod countNumber;<br />  if (runTime > 0) then<br />    runTime := 1 + trunc(amount / countNumber);<br />  end if;<br />  if (runTime = 0) then<br />    runTime := 0 + trunc(amount / countNumber);<br />  end if;<br />  FOR i IN 1 .. runTime LOOP<br />    e_sql := 'insert into '||ip_table_name ||'<br />    ('||ip_table_column ||')<br />     select '|| ip_table_column ||'<br />     from<br />     (select selectSec.*, rownum rownumType<br />          from ('|| ip_table_select ||') selectSec<br />         WHERE ROWNUM <= '|| i * countNumber ||')<br />    WHERE rownumType > '||(i - 1) * countNumber;<br />    dbms_output.enable(99999999999999);<br />    dbms_output.put_line(e_sql);<br />    execute immediate e_sql;<br />    --提交<br />    commit;<br />  END LOOP;<br />  return_result := 1;<br />  return;<br />exception<br />  when others then<br />    return_result := 0;<br />    raise;<br />    dbms_output.enable(99999999999999);<br />    dbms_output.put_line('l束');<br />    return;<br />end;<br /><br /><br /><br />以上试通过?img src ="http://www.aygfsteel.com/japper/aggbug/382610.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/japper/" target="_blank">japper</a> 2012-07-09 15:06 <a href="http://www.aygfsteel.com/japper/archive/2012/07/09/382610.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ORACLE所在linux盘符I间不的解军_?/title><link>http://www.aygfsteel.com/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.aygfsteel.com/japper/archive/2012/07/02/381987.html</guid><wfw:comment>http://www.aygfsteel.com/japper/comments/381987.html</wfw:comment><comments>http://www.aygfsteel.com/japper/archive/2012/07/02/381987.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/japper/comments/commentRss/381987.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/japper/services/trackbacks/381987.html</trackback:ping><description><![CDATA[<div>ORACLE数据库空间不I会发生登录出错,数据无法插入{错误发生,可以Ҏ实际错误代码查询原因Q不q更多是qx多看看数据库I间是否_Q?br />解决办法有两个:<br />1、用linux命o或者工具增加空间或者增加硬盘,没有实际操作q;<br />2、给oracel数据库增加系l表I间和时表I间Q记录下操作ҎQ?br /> <p>如果临时表空间或者SYSTEM表空间不I可以q行新增数据文g到其它盘W(增加opt盘符目录Q:<br />select ts#, name from v$datafile;--查看当前的表I间状况<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; --新增临时文g<br />alter database default temporary tablespace "TEMP2";  --修改默认临时文g讄<br />alter database tempfile '/home/oracle/oracle/oradata/portal/temp01.dbf' autoextend off;  --关闭原来的时文件自增长<br />增加pȝ表空_<br />alter tablespace SYSTEM add datafile '/opt/oracle/oracle_tmp/system02.dbf' size 500M autoextend on next 5M; <br /><br /></p> <p>如果startup数据库时Q提C:prifile文g找不刎ͼ可以从一?ORACLE_BASE/admin/portal/pfile目录下拷贝内容过d可以(注意文g命名和原来用的保持一P只是内容不同)Q?br />当前正在使用的pfileQstartup force pfile='/home/oracle/oracle/product/11.0.1/db_1/dbs/initportal.ora';<br />拯Qcp $ORACLE_BASE/admin/portal/pfile/init.ora.452011185827   /home/oracle/oracle/product/11.0.1/db_1/dbs/spfileportal.ora</p></div><img src ="http://www.aygfsteel.com/japper/aggbug/381987.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/japper/" target="_blank">japper</a> 2012-07-02 14:14 <a href="http://www.aygfsteel.com/japper/archive/2012/07/02/381987.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle 临时表空间的增删Ҏhttp://www.aygfsteel.com/japper/archive/2012/06/28/381721.htmljapperjapperThu, 28 Jun 2012 06:54:00 GMThttp://www.aygfsteel.com/japper/archive/2012/06/28/381721.htmlhttp://www.aygfsteel.com/japper/comments/381721.htmlhttp://www.aygfsteel.com/japper/archive/2012/06/28/381721.html#Feedback0http://www.aygfsteel.com/japper/comments/commentRss/381721.htmlhttp://www.aygfsteel.com/japper/services/trackbacks/381721.htmloracle 临时表空间的增删Ҏ

1、查看时表I间 Qdba_temp_files视图Q(v_$tempfile视图Q?br />select tablespace_name,file_name,bytes/1024/1024 file_size,autoextensible from dba_temp_files;
select status,enabled, name, bytes/1024/1024 file_size from v_$tempfile;--sys用户查看

2、羃时表I间大小
alter database tempfile 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\TELEMT\TEMP01.DBF' resize 100M;

3、扩展时表I间Q?/strong>
Ҏ一、增大时文件大:
SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp01.dbf’ resize 100m;
Ҏ二、将临时数据文g设ؓ自动扩展Q?br />SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp01.dbf’ autoextend on next 5m maxsize unlimited;
Ҏ三、向临时表空间中d数据文gQ?br />SQL> alter tablespace temp add tempfile ‘/u01/app/oracle/oradata/orcl/temp02.dbf’ size 100m;

4、创Z时表I间Q?br />SQL> create temporary tablespace temp1 tempfile ‘/u01/app/oracle/oradata/orcl/temp11.dbf’ size 10M;

5、更改系l的默认临时表空_
--查询默认临时表空?br />select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';
--修改默认临时表空?br />alter database default temporary tablespace temp1;
所有用L默认临时表空间都切换ؓ新的临时表空_
select username,temporary_tablespace,default_ from dba_users;
--更改某一用户的时表I间Q?br />alter user scott temporary tablespace temp;

6、删除时表I间
删除临时表空间的一个数据文Ӟ
SQL> alter database tempfile ‘/u01/app/oracle/oradata/orcl/temp02.dbf’ drop;
删除临时表空?d删除)Q?br />SQL> drop tablespace temp1 including contents and datafiles cascade constraints;

7、查看时表I间的用情?/strong>QGV_$TEMP_SPACE_HEADER视图必须在sys用户下才能查询)
GV_$TEMP_SPACE_HEADER视图记录了时表I间的用大与未用的大小
dba_temp_files视图的bytes字段记录的是临时表空间的d?br />SELECT temp_used.tablespace_name,
       total - used as "Free",
       total as "Total",
       round(nvl(total - used, 0) * 100 / total, 3) "Free percent"
  FROM (SELECT tablespace_name, SUM(bytes_used) / 1024 / 1024 used
          FROM GV_$TEMP_SPACE_HEADER
         GROUP BY tablespace_name) temp_used,
       (SELECT tablespace_name, SUM(bytes) / 1024 / 1024 total
          FROM dba_temp_files
         GROUP BY tablespace_name) temp_total
 WHERE temp_used.tablespace_name = temp_total.tablespace_name

8、查找消耗资源比较的sql语句
Select se.username,
       se.sid,
       su.extents,
       su.blocks * to_number(rtrim(p.value)) as Space,
       tablespace,
       segtype,
       sql_text
  from v$sort_usage su, v$parameter p, v$session se, v$sql s
 where p.name = 'db_block_size'
   and su.session_addr = se.saddr
   and s.hash_value = su.sqlhash
   and s.address = su.sqladdr
 order by se.username, se.sid
 
9、查看当前时表I间使用大小与正在占用时表I间的sql语句
select sess.SID, segtype, blocks * 8 / 1000 "MB", sql_text
  from v$sort_usage sort, v$session sess, v$sql sql
 where sort.SESSION_ADDR = sess.SADDR
   and sql.ADDRESS = sess.SQL_ADDRESS
 order by blocks desc;

10、时表I间l介l?/strong>
  1Q创Z时表I间l:
create temporary tablespace tempts1 tempfile '/home/oracle/temp1_02.dbf' size 2M tablespace group group1;
create temporary tablespace tempts2 tempfile '/home/oracle/temp2_02.dbf' size 2M tablespace group group2;
 
 2Q查询时表I间l:dba_tablespace_groups视图
select * from dba_tablespace_groups;
GROUP_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1                         TEMPTS1
GROUP2                         TEMPTS2

 3Q将表空间从一个时表I间l移动到另外一个时表I间l:
alter tablespace tempts1 tablespace group GROUP2 ;
select * from dba_tablespace_groups;

GROUP_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
GROUP2                         TEMPTS1
GROUP2                         TEMPTS2

 4Q把临时表空间组指定l用?br />alter user scott temporary tablespace GROUP2;

 5Q在数据库讄临时表空?br />alter database <db_name> default temporary tablespace GROUP2;

 6Q删除时表I间l?(删除l成临时表空间组的所有时表I间)
drop tablespace tempts1 including contents and datafiles;
select * from dba_tablespace_groups;
GROUP_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
GROUP2                         TEMPTS2

drop tablespace tempts2 including contents and datafiles;
select * from dba_tablespace_groups;
GROUP_NAME                     TABLESPACE_NAME

11、对临时表空间进行shrinkQ?1g新增的功能)
--temp表空间收~ؓ20M
alter tablespace temp shrink space keep 20M;
--自动表I间的时文件羃到最可能的大小
ALTER TABLESPACE temp SHRINK TEMPFILE ’/u02/oracle/data/lmtemp02.dbf’;

临时表空间作?/strong>
Oracle临时表空间主要用来做查询和存放一些缓冲区数据。时表I间消耗的主要原因是需要对查询的中间结果进行排序?br />重启数据库可以释放时表I间Q如果不能重启实例,而一直保持问题sql语句的执行,temp表空间会一直增ѝ直到耗尽盘I间?br />|上有h猜测在磁盘空间的分配上,oracle使用的是贪心法Q如果上ơ磁盘空间消耗达?GBQ那么时表I间是1GB?br />也就是说当前临时表空间文件的大小是历史上使用临时表空间最大的大小?br />
临时表空间的主要作用Q?br />  索引create或rebuildQ?br />  Order by ?group byQ?br />  Distinct 操作Q?br />  Union ?intersect ?minusQ?br />  Sort-merge joinsQ?br />  analyze.



japper 2012-06-28 14:54 发表评论
]]>
oracle sql日期比较Q{Q?/title><link>http://www.aygfsteel.com/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.aygfsteel.com/japper/archive/2012/05/21/378659.html</guid><wfw:comment>http://www.aygfsteel.com/japper/comments/378659.html</wfw:comment><comments>http://www.aygfsteel.com/japper/archive/2012/05/21/378659.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/japper/comments/commentRss/378659.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/japper/services/trackbacks/378659.html</trackback:ping><description><![CDATA[<pre>Q{Qoracle 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> <span style="color: #808080">*</span> <span style="color: #0000ff">from</span><span style="color: #000000"> up_date </span><span style="color: #0000ff">where</span> <span style="color: #0000ff">update</span> <span style="color: #808080"><</span><span style="color: #000000"> to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07 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 hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)<br /></span><span style="color: #0000ff">select</span> <span style="color: #808080">*</span> <span style="color: #0000ff">from</span><span style="color: #000000"> up_date </span><span style="color: #0000ff">where</span> <span style="color: #0000ff">update</span> <span style="color: #808080"><=</span><span style="color: #000000"> to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07 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 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> <span style="color: #808080">*</span> <span style="color: #0000ff">from</span><span style="color: #000000"> up_date </span><span style="color: #0000ff">where</span> <span style="color: #0000ff">update</span> <span style="color: #808080">></span><span style="color: #000000"> to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07 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 hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)<br /></span><span style="color: #0000ff">select</span> <span style="color: #808080">*</span> <span style="color: #0000ff">from</span><span style="color: #000000"> up_date </span><span style="color: #0000ff">where</span> <span style="color: #0000ff">update</span> <span style="color: #808080">>=</span><span style="color: #000000"> to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07 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 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> <span style="color: #808080">*</span> <span style="color: #0000ff">from</span><span style="color: #000000"> up_date </span><span style="color: #0000ff">where</span> <span style="color: #0000ff">update</span> <span style="color: #808080">=</span><span style="color: #000000"> to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07 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 hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)</span></div><br />在某D|间内:<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> <span style="color: #808080">*</span> <span style="color: #0000ff">from</span><span style="color: #000000"> up_date </span><span style="color: #0000ff">where</span> <span style="color: #0000ff">update</span> <span style="color: #808080">between</span><span style="color: #000000"> to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-07-07 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 hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">) </span><span style="color: #808080">and</span><span style="color: #000000"> to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07 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 hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)<br /></span><span style="color: #0000ff">select</span> <span style="color: #808080">*</span> <span style="color: #0000ff">from</span><span style="color: #000000"> up_date </span><span style="color: #0000ff">where</span> <span style="color: #0000ff">update</span> <span style="color: #808080"><</span><span style="color: #000000"> to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07 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 hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">) </span><span style="color: #808080">and</span> <span style="color: #0000ff">update</span> <span style="color: #808080">></span><span style="color: #000000"> to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-07-07 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 hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)<br /></span><span style="color: #0000ff">select</span> <span style="color: #808080">*</span> <span style="color: #0000ff">from</span><span style="color: #000000"> up_date </span><span style="color: #0000ff">where</span> <span style="color: #0000ff">update</span> <span style="color: #808080"><=</span><span style="color: #000000"> to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-09-07 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 hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">) </span><span style="color: #808080">and</span> <span style="color: #0000ff">update</span> <span style="color: #808080">>=</span><span style="color: #000000"> to_date(</span><span style="color: #ff0000">'</span><span style="color: #ff0000">2007-07-07 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 hh24:mi:ss</span><span style="color: #ff0000">'</span><span style="color: #000000">)</span></div><div><span style="color: #000000"><br /></span></div><p> </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">. 当前pȝ日期、时?br style="line-height: normal" />select getdate() <br style="line-height: normal" /></span><span style="line-height: normal; color: #800080">2</span><span style="line-height: normal; color: #000000">. dateadd 在向指定日期加上一D|间的基础上,q回新的 datetime ?br style="line-height: normal" />例如Q向日期加上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">) --q回Q?/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> <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 q回跨两个指定日期的日期和时间边界数?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">) --q回Q?/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 q回代表指定日期的指定日期部分的整数?br style="line-height: normal" />SELECT DATEPART(month, </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">) --q回 </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 q回代表指定日期的指定日期部分的字符?br style="line-height: normal" />SELECT datename(weekday, </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">) --q回Q星期五<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 本年W多周=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" />函数 参数/功能 <br style="line-height: normal" />GetDate( ) --q回pȝ目前的日期与旉 <br style="line-height: normal" />DateDiff (interval,date1,date2) --以interval 指定的方式,q回date2 与date1两个日期之间的差?date2-date1 <br style="line-height: normal" />DateAdd (interval,number,date) --以interval指定的方式,加上number之后的日?nbsp;<br style="line-height: normal" />DatePart (interval,date) ---q回日期date中,interval指定部分所对应的整数?nbsp;<br style="line-height: normal" />DateName (interval,date) --q回日期date中,interval指定部分所对应的字W串名称 <br style="line-height: normal" /><br style="line-height: normal" />参数 interval的设定值如下:<br style="line-height: normal" /><br style="line-height: normal" />?~?写(Sql ServerQ?Access ?ASP 说明 <br style="line-height: normal" />Year Yy yyyy q?nbsp;</span><span style="line-height: normal; color: #800080">1753</span><span style="line-height: normal; color: #000000"> ~ </span><span style="line-height: normal; color: #800080">9999</span><span style="line-height: normal; color: #000000"> <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"> ~ </span><span style="line-height: normal; color: #800080">4</span><span style="line-height: normal; color: #000000"> <br style="line-height: normal" />Month Mm m ? ~ </span><span style="line-height: normal; color: #800080">12</span><span style="line-height: normal; color: #000000"> <br style="line-height: normal" />Day of year Dy y 一q的日数,一q中的第几日 </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"> <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"> <br style="line-height: normal" />Weekday Dw w 一周的日数Q一周中的第几日 </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"> <br style="line-height: normal" />Week Wk ww 周,一q中的第几周 </span><span style="line-height: normal; color: #800080">0</span><span style="line-height: normal; color: #000000"> ~ </span><span style="line-height: normal; color: #800080">51</span><span style="line-height: normal; color: #000000"> <br style="line-height: normal" />Hour Hh h ? ~ </span><span style="line-height: normal; color: #800080">23</span><span style="line-height: normal; color: #000000"> <br style="line-height: normal" />Minute Mi n 分钟0 ~ </span><span style="line-height: normal; color: #800080">59</span><span style="line-height: normal; color: #000000"> <br style="line-height: normal" />Second Ss s U?nbsp;</span><span style="line-height: normal; color: #800080">0</span><span style="line-height: normal; color: #000000"> ~ </span><span style="line-height: normal; color: #800080">59</span><span style="line-height: normal; color: #000000"> <br style="line-height: normal" />Millisecond Ms - 毫秒 </span><span style="line-height: normal; color: #800080">0</span><span style="line-height: normal; color: #000000"> ~ </span><span style="line-height: normal; color: #800080">999</span><span style="line-height: normal; color: #000000"> <br style="line-height: normal" /><br style="line-height: normal" />access ?asp 中用date()和now()取得pȝ日期旉Q其中DateDiff,DateAdd,DatePart也同是能用于Access和asp中,q些函数的用法也cM<br style="line-height: normal" /><br style="line-height: normal" />举例Q?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">)q回gؓ </span><span style="line-height: normal; color: #800080">514592</span><span style="line-height: normal; color: #000000"> U?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">)q回gؓ </span><span style="line-height: normal; color: #800080">5</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">.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">)q回gؓ </span><span style="line-height: normal; color: #800080">2</span><span style="line-height: normal; color: #000000"> x期一(周日?Q周六ؓ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">)q回gؓ 25?5?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">)q回gؓ 206卌一q中W?06?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">)q回gؓ 2005?005q?nbsp;<br style="line-height: normal" /><br style="line-height: normal" />SQL Server DATEPART() 函数q回 SQLServer datetime 字段的一部分?nbsp;<br style="line-height: normal" /><br style="line-height: normal" />SQL Server DATEPART() 函数的语法是Q?nbsp;<br style="line-height: normal" />DATEPART(portion, datetime)<br style="line-height: normal" /><br style="line-height: normal" />其中 datetime ?SQLServer datetime 字段和部分的名称是下列之一Q?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">.~写函数Q实现按?/span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">q月日,星期?上午下午晚上</span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000">输出旉信息(2009q??6日星期一下午)<br style="line-height: normal" />select datename(yy,getdate()) + </span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #800000">q?/span><span style="line-height: normal; color: #800000">'</span><span style="line-height: normal; color: #000000"> +<br style="line-height: normal" />       datename(mm,getdate()) + </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"> + <br style="line-height: normal" />       datename(dd,getdate()) + </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"> +<br style="line-height: normal" />       datename(weekday,getdate()) +<br style="line-height: normal" />       case when datename(hh,getdate()) < </span><span style="line-height: normal; color: #800080">12</span><span style="line-height: normal; color: #000000"> then </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"> else </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                                                                                                                          <br style="line-height: normal" />--</span><span style="line-height: normal; color: #800080">2</span><span style="line-height: normal; color: #000000">.~写函数Q根据输入时间。输天是该年的第几天<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">.求出随机输出字符‘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.aygfsteel.com/japper/aggbug/378659.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/japper/" target="_blank">japper</a> 2012-05-21 10:44 <a href="http://www.aygfsteel.com/japper/archive/2012/05/21/378659.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">¬</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">¡</a>| <a href="http://" target="_blank">ͨ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">żҿ</a>| <a href="http://" target="_blank">ϰ</a>| <a href="http://" target="_blank">Է</a>| <a href="http://" target="_blank">Զ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank">³ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">鴨</a>| <a href="http://" target="_blank">ݰ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɶ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̩</a>| <a href="http://" target="_blank">人</a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank">˳</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>