ÕÒµ½ÒýÆð´ÅÅÌÅÅÐòµÄSQL
ÏÂÃæµÄÕâЩ½Å±¾¶¼¿ÉÒÔÕÒµ½ÒýÆð´ÅÅÌÅÅÐòµÄSQL¡£
SELECT /*+ rule */ DISTINCT a.SID, a.process, a.serial#,
TO_CHAR (a.logon_time, 'YYYYMMDD HH24:MI:SS') LOGON, a.osuser,TABLESPACE, b.sql_text
from v$session a, v$sql b, v$sort_usage c
WHERE a.sql_address = b.address AND a.saddr = c.session_addr;
SELECT a.SID,TABLESPACE, b.sql_text
from v$session a, v$sql b, v$sort_usage c
WHERE a.sql_address = b.address AND a.saddr = c.session_addr;
select a.sid,a.username,a.program,c.sql_text from v$session a,v$tempseg_usage b,v$sql c where a.saddr=b.session_addr and a.sql_address=c.address ;
Àý×Ó:
SQL> select a.sid,a.username,a.program,c.sql_text from v$session a,v$tempseg_usage b,v$sql c where a.saddr=b.session_addr and a.sql_address=c.address ;
SID USERNAME PROGRAM SQL_TEXT
---------- ---------- ---------------------------------------------------------------- ---------------------------------------------------------------------------
146 ROBINSON sqlplus.exe select a.table_name,a.comments from dict a,dict b order by a.table_name
145 ROBINSON sqlplus.exe &
Ïà¹ØÎĵµ£º
Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseËÑË÷º¯Êý¡£
--¼òµ¥Caseº¯Êý
CASE sex
WHEN '1' THEN 'ÄÐ'
WHEN '2' THEN 'Å®'
ELSE 'ÆäËû' END
--CaseËÑË÷º¯Êý
CASE WHEN sex = '1' THEN 'ÄÐ'
WHEN sex = '2' THEN 'Å®'
ELSE 'ÆäËû' END
ÕâÁ½ÖÖ·½Ê½£¬¿ÉÒÔʵÏÖÏàͬµÄ¹¦ÄÜ¡£¼òµ¥Caseº¯ÊýµÄд·¨Ïà ......
ÊìϤSQL SERVER 2000µÄÊý¾Ý¿â¹ÜÀíÔ±¶¼ÖªµÀ£¬ÆäDTS¿ÉÒÔ½øÐÐÊý¾ÝµÄµ¼Èëµ¼³ö£¬Æäʵ£¬ÎÒÃÇÒ²¿ÉÒÔʹÓÃTransact-SQLÓï¾ä½øÐе¼Èëµ¼³ö²Ù×÷¡£ÔÚTransact-SQLÓï¾äÖУ¬ÎÒÃÇÖ÷ҪʹÓÃOpenDataSourceº¯Êý¡¢OPENROWSET º¯Êý£¬¹ØÓÚº¯ÊýµÄÏêϸ˵Ã÷£¬Çë²Î¿¼SQLÁª»ú°ïÖú¡£ÀûÓÃÏÂÊö·½·¨£¬¿ÉÒÔÊ®·ÖÈÝÒ×µØʵÏÖSQL SERVER¡¢ACCESS¡¢EXCELÊý¾Ýת»»£ ......
Ò»¡¢ÄÚ²¿º¯Êý
1¡¢ÄÚ²¿ºÏ¼Æº¯Êý
1£©COUNT£¨*£© ·µ»ØÐÐÊý
2£©COUNT£¨DISTINCT COLNAME£©·µ»ØÖ¸¶¨ÁÐÖÐΨһֵµÄ¸öÊý
3£©SUM£¨COLNAME/EXPRESSION£©·µ»ØÖ¸¶¨Áлò±í´ïʽµÄÊýÖµºÍ£»
4£©SUM£¨DISTINCT COLNAME£© ·µ»ØÖ¸¶¨ÁÐÖÐΨһֵµÄºÍ
5£©AVG£¨COLNAME/EXPRESSION£©·µ»ØÖ¸¶¨Áлò±í´ïʽÖеÄÊýֵƽ¾ùÖµ
6£©AV ......
Êýѧº¯Êý
1.¾ø¶ÔÖµ
S:select abs(-1) value
O:select abs(-1) value from dual
2.È¡Õû(´ó)
S:select ceiling(-1.001) value
O:select ceil(-1.001) value from dual
3.È¡Õû£¨Ð¡£©
S:select floor(-1.001) value
O:select floor(-1.001) value from dual
4.È¡Õû£¨½ØÈ¡£©
S:select cast(-1.002 as in ......
Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseËÑË÷º¯Êý¡£
--¼òµ¥Caseº¯Êý
CASE sex
WHEN '1' THEN 'ÄÐ'
WHEN '2' THEN 'Å®'
ELSE 'ÆäËû' END
--CaseËÑË÷º¯Êý
CASE WHEN sex = '1' THEN 'ÄÐ'
  ......