SQL ³£Óú¯Êý ±Ê¼Ç
Garin Zhang
SQL³£Óú¯Êý£º
1. ASCII()£º·µ»Ø×Ö·û´®×î×ó¶Ë×Ö·ûµÄASCIIÂë¡£
2. CHAR()£º½«ASCIIת»»³É×Ö·û¡£(0~255)
3. LOWER()ºÍUPPER()¡£
4. STR()£º°ÑÊýÖµÐÍÊý¾Ýת»»Îª×Ö·ûÐÍÊý¾Ý
SRT(<float_expression>[,length[,<decimal>]])
LTRIM()°Ñ×Ö·û´®Í·²¿¿Õ¸ñÈ¥µô£¬RTRIM()°Ñ×Ö·û´®Î²¿Õ¸ñÈ¥µô¡£
È¡×Ó´®º¯Êý£º
1. LEFT(<chars>, length)£º·µ»Øchar×óÆðlength¸ö×Ö·û¡£
2. RIGHT(<chars>, length)£º·µ»ØcharÓÒÆðlength¸ö×Ö·û¡£
3. SUBSTRING(<chars>, <position>, length)£º·µ»Øchars×ó±ßµÚposition¸ö×Ö·ûÆðlength¸ö×Ö·û²¿·Ö¡£
×Ö·û´®±È½Ï£º
1. QUOTENAME(<chars>[,quote_char])£º·µ»Ø±»Ìض¨×Ö·ûÀ¨ÆðÀ´µÄ×Ö·û´®¡£quote_charȱʡΪ"[]"
2. REPLICATE(<chars>, integer)£º·µ»ØÒ»¸öÖظ´integer´ÎÊýµÄchars¡£
3. REVERSE(<chars>)£º½«chars×Ö·û´®µÄ×Ö·ûÅÅÁÐ˳Ðòµßµ¹¡£
4. REPLACE(str1, str2, str3)£ºÓÃstr3Ìæ»»ÔÚstr1ÖеÄ×Ó´®str2.
5. SPACE(length)£º·µ»ØÒ»¸öÓÐÖ¸¶¨³¤¶ÈµÄ¿Õ°××Ö·û´®¡£
6. STUFF(str1, start, length, str2)£ºÓÃstr2Ìæ»»str1ÖдÓstart¿ªÊ¼µÄlength³¤¶ÈµÄ×Ö·û´®¡£
Êý¾ÝÀàÐÍת»»º¯Êý£º
1. CAST(str1 AS <data_type>[length])£º½«str1ÏÔʾµÄת»»ÎªÁíÒ»Êý¾ÝÀàÐÍ¡£
2. CONVERT(<data_type>[length], <expression>[, style])¡£
ÔÚ±ê×¼SQLÖÐÓÃÓÚת»¯encoding£ºCONVERT('abc' USING utf8); // MySQL
CONVERT('abc', 'UTF8', 'LATIN'); // postgres
ÔÚSQL ServerÖУºÓëCASTÀàËÆ
ÈÕÆÚº¯Êý£º
1. day(str), ·µ»ØstrÖеÄÈÕÆÚÖµ
2. month(str), year(str)
3. DATEADD(<datepart>, <number>, <data>) // data¼ÓÉÏdatepartµÄaddÖ®ºóµÄÐÂÈÕÆÚ
4. DATEDIFF(<datepart>, <date1>, <date2>)
5. DATENAME(<datepart>, <date>) // ·µ»ØdatepartÖ¸¶¨²¿·Ö
6. DATEPART(<datepart>, <date>) //·µ»ØÕûÊý£¬DAT
Ïà¹ØÎĵµ£º
Student(S#,Sname,Sage,Ssex) ѧÉú±í
Course(C#,Cname,T#) ¿Î³Ì±í
SC(S#,C#,score) ³É¼¨±í
Teacher(T#,Tname) ½Ìʦ±í
ÎÊÌ⣺
1¡¢²éѯ“001”¿Î³Ì±È“002”¿Î³Ì³É¼¨¸ßµÄËùÓÐѧÉúµÄѧºÅ£»
select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
& ......
selectÓï¾äÇ°¼Ó£º
declare @d datetime
set @d=getdate()
²¢ÔÚselectÓï¾äºó¼Ó£º
select [Óï¾äÖ´Ðл¨·Ñʱ¼ä(ºÁÃë)]=datediff(ms,@d,getdate())
ת×Ô£º¶¯Ì¬ÍøÖÆ×÷Ö¸ÄÏ www.knowsky.com
ÕâÊǼòÒ׵IJ鿴ִÐÐʱ¼äµÄ·½·¨¡£
===========================================£¨Ò»ÏÂÄÚÈÝת×Ô£º£Ã£Ó£Ä£Î£©
MSSQL ServerÖÐͨ¹ý²é ......
--ͨ¹ýsqlÆóÒµ¹ÜÀíÆ÷Ð޸ĺÍɾ³ýa±íÖÐÊý¾Ýʱ»á³öÏÖ´íÎó
--sqlÆóÒµ¹ÜÀíBug£¬Í¨¹ý³ÌÐò»òÖ´ÐÐsqlÓï¾ä¸üÐÂa±íÊý¾ÝûÓÐÎÊÌâ
--Ìí¼Ó
Insert a (FName, FCode, FOther) Values('11','2222','33')
--ÐÞ¸Ä
Update a Set FName='22_Edit' Where FCode='22'
--ɾ³ý
Delete a Where FCode='22'
--²é¿´a/b±íÊý¾Ý
Select * from a ......
¼Ü¹¹£¨Schema£©¡£Î¢ÈíµÄ¹Ù·½ËµÃ÷£¨MSDN£©£º
"Êý¾Ý¿â¼Ü¹¹ÊÇÒ»¸ö¶ÀÁ¢ÓÚÊý¾Ý¿âÓû§µÄ·ÇÖظ´ÃüÃû¿Õ¼ä£¬Äú¿ÉÒÔ½«¼Ü¹¹ÊÓΪ¶ÔÏóµÄÈÝÆ÷"£¬Ïêϸ²Î¿¼
http://technet.microsoft.com/zh-cn/library/ms190387.aspx.ÎÒÃÇÖªµÀ£¬ÔÚJAVAÖУ¬ÃüÃû¿Õ
¼äÃûÆäʵ¾ÍÊÇÎļþ¼ÐÃû¡£Òò´ËÎÒÃǷdz£Ã÷È·Ò»µã£ºÒ»¸ö¶ÔÏóÖ»ÄÜÊôÓÚÒ»¸ö¼Ü¹¹£¬¾ÍÏ ......
ÊÓͼ
SET¡¡NOCOUNT ON;
SET Northwind;
GO
IF OBJECT_ID('dbo.ViewName') IS NOT NULL
DROP VIEW dbo.ViewName;
GO
CREATE VIEW dbo.Viewname
AS
SELECT * from customer AS C
WHERE EXISTS
(SELECT * from dbo.Orders AS O
WHERE O.CustomerI ......