第11章:使用數據處理函數。函數
P69 文本處理函數,upper()函數把文本變成大寫字體。字體
select vend_name,upper(vend_name) as vend_name_upcase from vendors order by vend_name; #upper()把vend_name列的文本變成了大寫,而且從新命名爲vend_name_upcase #blog
其餘的經常使用的函數:string
length()返回串的長度class
lower() 將文本變成小寫字體。date
其餘的,left()返回串左邊的字符,locate()找到串的一個子串。 LTrim()去掉串左邊的空格,Right()返回串右邊的字符。substring()返回子串的字符。試了一下,不知道怎麼用,或是不知道用不用有什麼區別。select
select cust_name,cust_contact from customers where cust_contact ='Y.Lie'; #查找列cust_contact裏面名Y.Lie,可是沒有沒有這個顧客名,因此返回的值是空的#搜索
select cust_name,cust_contact from customers where soundex(cust_contact)=soundex('Y.Lie); #soundex()函數搜索發音相似的,相似模糊搜索,注意條件的裏邊都要用soundex()函數。#im
P71 日期和時間處理函數。注意:爲了排除多義性混亂的各類可能性,日期的首選首選格式:yyyy-mm-dd。命名
select cust_id,order_num from orders where order_date='2005-09-01'; #檢索訂單日期是2005-09-01 #
select cust_id,order_num from orders where date(order_date)='2005-09-01'; #假若訂單日期的格式是yyyy-mm-dd xx:xx:xx ,那where order_date='2005-09-01'就會檢索失敗,爲了保險起見,用date()函數,提取日期的部分信息,相應地,若是想要時間的時間時部分(便是xx:xx:xx部分),用time()函數,如:where time(order_date)=13:08:22 #
P73 檢索一段時間內的信息。
select cust_id,order_num from orders where date(order_date) between '2005-09-01' and '2005-09-30'; #檢索的時間範圍是20050901到20050930#
select cust_id,order_num from orders where year(order_date)=2005 and month(order_date)=9 ; #檢索的年份是2005,月份是9月,要同時知足這兩個條件。#注意:上面檢索的是時間格式,因此要用引號,下面檢索的年份和月份已經至關於一個數值,不須要引號(本身的理解)#
其餘的數值處理函數有:
abs() 絕對值;
cos()一個角度的餘弦
exp()一個值的指數值
mod()返回除操做的餘數 #不懂它的操做#
pi()返回圓周率
rand()返回一個隨機值
sin()返回一個角度的正弦
sqrt()返回一個數的平方根
tan()返回正切值