Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : sql

SQL Öн«Ò»¸ö±íת»¯³É½¨±íÓï¾äµÄ´æ´¢¹ý³Ì

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pGetInsertSQL (@TableName varchar(256))
as
begin
    set nocount on
    declare @sqlstr varchar(4000)
    declare @sqlstr1 varchar(4000)
    declare @sqlstr2 varchar(4000)
    select @sqlstr='select ''insert '+@tablename
    select @sqlstr1=''
    select @sqlstr2=' ('
    select @sqlstr1= ' values ( ''+'
    select @sqlstr1=@sqlstr1+col+'+'',''+' ,@sqlstr2=@sqlstr2+name +',' from (select case
--    when a.xtype =173 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end'
    when a.xtype =104 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(1),'+a.name +')'+' end'
    when a.xtype =175 then 'case when '+a.name+' is ......

¾¡Á¿±ÜÃâÔÚSQLÓï¾äµÄWHERE×Ó¾äÖÐʹÓú¯Êý

----start
    ÔÚSQLÓï¾äµÄ WHERE ×Ó¾äÖÐÓ¦¸Ã¾¡Á¿±ÜÃâÔÚ×Ö¶ÎÉÏʹÓú¯Êý£¬ÒòΪÕâÑù×ö»áʹ¸Ã×Ö¶ÎÉϵÄË÷ÒýʧЧ£¬Ó°ÏìSQLÓï¾äµÄÐÔÄÜ¡£¼´Ê¹¸Ã×Ö¶ÎÉÏûÓÐË÷Òý£¬Ò²Ó¦¸Ã±ÜÃâÔÚ×Ö¶ÎÉÏʹÓú¯Êý¡£¿¼ÂÇÏÂÃæµÄÇé¿ö£º
CREATE TABLE USER
(
NAME VARCHAR(20) NOT NULL,---ÐÕÃû
REGISTERDATE TIMESTAMP---×¢²áʱ¼ä
); 
ÏÖÔÚÒªÇóÄã°Ñ2009.9.24×¢²áµÄÓû§¶¼²é³öÀ´£¬Ôõô°ì£¿¿ÉÄÜÓÐÈË»áÕâôд£º
SELECT * from USER WHERE REGISTERDATE='2009-9-24'; 
²»¹ýºÜÒź¶£¬Õâ¸öÓï¾äÊÇ´íÎóµÄ£¬ÒòΪREGISTERDATEÊÇTIMESTAMPÀàÐÍ£¬¶ø'2009-9-24'ĬÈÏÊÇDATEÀàÐÍ£¬ÀàÐͲ»Æ¥Åä¡£¼´È»ÀàÐͲ»Æ¥Å䣬ºÜ×ÔÈ»»áÏëµ½ÀûÓú¯Êý½øÐÐÀàÐÍת»»£¬Òò´Ë£¬ºÜ×ÔÈ»»áд³öÏÂÃæµÄÓï¾ä£º
SELECT * from USER WHERE DATE(REGISTERDATE)='2009-9-24'; 
ÉÏÊöÓï¾äÍêÈ«ÕýÈ·£¬µ«ÊǼÙÈçREGISTERDATE×Ö¶ÎÉÏÓÐË÷Òý£¬ÄÇô»áʹË÷ÒýʧЧ£¬¼´Ê¹Ã»ÓÐË÷Òý£¬Ò²²»Ó¦¸ÃÕâô×ö¡£ÄÇôµ½µ×ÈçºÎ´¦ÀíÄØ£¿´ð°¸Êǽ«Ëüת»¯Îª·¶Î§É¨Ã裬ÈçÏ£º
SELECT * from USER WHERE REGISTERDATE>='2009-9-24 00:00:00.0' AND REGISTERDATE<'2009-9-25 00:00:00.0'; 
---¸ü¶à²Î¼û£ºDB2 SQL ¾«Òª
----ÉùÃ÷£ ......

sql ÈÕÆڱȽÏ

sql ºÜ¾Ã²»Óã¬Í»È»¼äÒªÇó×ö±¨±í¡£ËùÒÔÓÖ¿ÉÒÔ²¹Ò»²¹sql֪ʶÁË¡£µ«¾­³£»áÓöµ½Ò»Ð©ÈõÖÇÎÊÌâ.
дÁËÒ»Ìõsql£ºselect to_date('2009-09-24 12:20:0') Äܽ«¸Ä×Ö·û´®×ª»»ÎªÈÕÆÚ
µ«ÁíÍâÒ»Ìõsqlȴת»»²»ÁË...¸Ð¾õºÜÆæ¹Ö.ÓÚÊǺõ¡£ÔÙ×Ðϸ¿´Ò»±é ·¢ÏÖ
¸øÒ»¸öÈÕÆÚ×Ö¶ÎÉèÖñðÃûʱÉèÖóÉÁËsib.fbizDate as dateÎÒ×Ô¼º¶¼ÎÞÓïÁË¡£Ôõô»áÉèÖóÉÁËsql¹Ø¼ü×Ö¡£
ËùÒÔ¸ÄһϱðÃû¾ÍokÁË¡£sqlÖÐto_date()·½·¨¿ÉÒÔ½«×Ö·û´®×ª»¯ÎªÈÕÆÚÀàÐÍ. ......

SQLÓÅ»¯½éÉÜÒ»

Ò»¡¢Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)
 
ORACLEµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû,Òò´Ëfrom×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦Àí. ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í.µ±ORACLE´¦Àí¶à¸ö±íʱ, »áÔËÓÃÅÅÐò¼°ºÏ²¢µÄ·½Ê½Á¬½ÓËüÃÇ.Ê×ÏÈ,ɨÃèµÚÒ»¸ö±í(from×Ó¾äÖÐ×îºóµÄÄǸö±í)²¢¶Ô¼Ç¼½øÐÐÅÉÐò,È»ºóɨÃèµÚ¶þ¸ö±í(from×Ó¾äÖÐ×îºóµÚ¶þ¸ö±í),×îºó½«ËùÓдӵڶþ¸ö±íÖмìË÷³öµÄ¼Ç¼ÓëµÚÒ»¸ö±íÖкÏÊʼǼ½øÐкϲ¢.
 
 
ÀýÈç:
 
±í TAB1 16,384 Ìõ¼Ç¼
 
±í TAB2 1 Ìõ¼Ç¼
 
Ñ¡ÔñTAB2×÷Ϊ»ù´¡±í (×îºÃµÄ·½·¨)
 
select count(*) from tab1,tab2 Ö´ÐÐʱ¼ä0.96Ãë
 
Ñ¡ÔñTAB1×÷Ϊ»ù´¡±í (²»¼ÑµÄ·½·¨)
 
select count(*) from tab2,tab1 Ö´ÐÐʱ¼ä26.09Ãë
 
 
Èç¹ûÓÐ3¸öÒÔÉϵıíÁ¬½Ó²éѯ, ÄǾÍÐèҪѡÔñ½»²æ±í(intersection table)×÷Ϊ»ù´¡±í, ½»²æ±íÊÇÖ¸ÄǸö±»ÆäËû±íËùÒýÓõıí.
 
 
ÀýÈç:
 
EMP±íÃèÊöÁËLOCATION±íºÍCATEGORY±íµÄ½»¼¯.
 
SELECT * from LOCATION L , CATEGORY C, EMP E ......

sql²éѯԭÀíºÍSelectÖ´ÐÐ˳Ðò


Ò» sqlÓï¾äµÄÖ´Ðв½Öè
1£©Óï·¨·ÖÎö£¬·ÖÎöÓï¾äµÄÓï·¨ÊÇ·ñ·ûºÏ¹æ·¶£¬ºâÁ¿Óï¾äÖи÷±í´ïʽµÄÒâÒå¡£
2£© ÓïÒå·ÖÎö£¬¼ì²éÓï¾äÖÐÉæ¼°µÄËùÓÐÊý¾Ý¿â¶ÔÏóÊÇ·ñ´æÔÚ£¬ÇÒÓû§ÓÐÏàÓ¦µÄȨÏÞ¡£
3£©ÊÓͼת»»£¬½«Éæ¼°ÊÓͼµÄ²éѯÓï¾äת»»ÎªÏàÓ¦µÄ¶Ô»ù±í²éѯÓï¾ä¡£
4£©±í´ïʽת»»£¬ ½«¸´Ô SQL ±í´ïʽת»»Îª½Ï¼òµ¥µÄµÈЧÁ¬½Ó±í´ïʽ¡£
5£©Ñ¡ÔñÓÅ»¯Æ÷£¬²»Í¬µÄÓÅ»¯Æ÷Ò»°ã²úÉú²»Í¬µÄ“Ö´Ðмƻ®”
6£©Ñ¡ÔñÁ¬½Ó·½Ê½£¬ ORACLE ÓÐÈýÖÖÁ¬½Ó·½Ê½£¬¶Ô¶à±íÁ¬½Ó ORACLE ¿ÉÑ¡ÔñÊʵ±µÄÁ¬½Ó·½Ê½¡£
7£©Ñ¡ÔñÁ¬½Ó˳Ðò£¬ ¶Ô¶à±íÁ¬½Ó ORACLE Ñ¡ÔñÄÄÒ»¶Ô±íÏÈÁ¬½Ó£¬Ñ¡ÔñÕâÁ½±íÖÐÄĸö±í×öΪԴÊý¾Ý±í¡£
8£©Ñ¡ÔñÊý¾ÝµÄËÑË÷·¾¶£¬¸ù¾ÝÒÔÉÏÌõ¼þÑ¡ÔñºÏÊʵÄÊý¾ÝËÑË÷·¾¶£¬ÈçÊÇÑ¡ÓÃÈ«±íËÑË÷»¹ÊÇÀûÓÃË÷Òý»òÊÇÆäËûµÄ·½Ê½¡£
9£©ÔËÐГִÐмƻ®”
¶þ oracle ¹²ÏíÔ­Àí
ORACLE½«Ö´ÐйýµÄSQLÓï¾ä´æ·ÅÔÚÄÚ´æµÄ¹²Ïí³Ø(shared buffer pool)ÖУ¬¿ÉÒÔ±»ËùÓеÄÊý¾Ý¿âÓû§¹²Ïí
µ±ÄãÖ´ÐÐÒ»¸öSQLÓï¾ä(ÓÐʱ±»³ÆΪһ¸öÓαê)ʱ,Èç¹ûËüºÍ֮ǰµÄÖ´ÐйýµÄÓï¾äÍêÈ«Ïàͬ, ORACLE¾ÍÄܺܿì»ñµÃÒѾ­±»½âÎöµÄÓï¾äÒÔ¼°×îºÃµÄ Ö´Ðз¾¶. Õâ¸ö¹¦ÄÜ´ó´óµØÌá¸ßÁËSQLµÄÖ´ÐÐÐÔÄܲ¢½ÚÊ¡ÁËÄÚ´æµÄʹÓÃ
Èý oracle Óï¾äÌ ......

oracle sql ʱ¼ä¼ä¸ô¼ÆËã

¼ÆËã¼ä¸ôʱ¼ä£º
select f_date,f_cstime,f_cetime, (((SYSDATE- TO_DATE(f_date||f_cstime,'YYYYMMDDHH24MISS')) * 86400000)-((SYSDATE- TO_DATE(f_date||f_cetime,'YYYYMMDDHH24MISS')) * 86400000))/1000  CURRENT_MILLI from ycsq_t_hauthlog where f_cstime<>'999999'
½«×Ö·û´®×ª»»³ÉÈÕÆÚÀà:SYSDATE- TO_DATE(f_date||f_cstime,'YYYYMMDDHH24MISS'),
SYSDATE- TO_DATE(f_date||f_cstime,'YYYYMMDDHH24MISS')*86400000 ת»»³ÉºÁÃë ......

oracle sql ʱ¼ä¼ä¸ô¼ÆËã

¼ÆËã¼ä¸ôʱ¼ä£º
select f_date,f_cstime,f_cetime, (((SYSDATE- TO_DATE(f_date||f_cstime,'YYYYMMDDHH24MISS')) * 86400000)-((SYSDATE- TO_DATE(f_date||f_cetime,'YYYYMMDDHH24MISS')) * 86400000))/1000  CURRENT_MILLI from ycsq_t_hauthlog where f_cstime<>'999999'
½«×Ö·û´®×ª»»³ÉÈÕÆÚÀà:SYSDATE- TO_DATE(f_date||f_cstime,'YYYYMMDDHH24MISS'),
SYSDATE- TO_DATE(f_date||f_cstime,'YYYYMMDDHH24MISS')*86400000 ת»»³ÉºÁÃë ......
×ܼǼÊý:4346; ×ÜÒ³Êý:725; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [703] [704] [705] [706] 707 [708] [709] [710] [711] [712]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ