版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、DB2常用函數(shù)實(shí)例版使用說(shuō)明:函數(shù)定義形式 result : schema-name.funcation_name(para-list) 其中參數(shù)列表形式,<>表示必選參數(shù),表示可選參數(shù),|表示任選其一 下面的所有實(shí)例均在DB2 V95版本測(cè)試通過(guò),如果是新版本會(huì)加注。any-builtin-type:Any data type that is not a distinct typestructured-type:Any user-defined structured type defined to the databasecharacter-type:An
2、y of the character string types: CHAR, VARCHAR, LONG VARCHAR, CLOB.datetime-type:Any of the datetime types: DATE, TIME, TIMESTAMPgraphic-type:Any of the double byte character string types: GRAPHIC, VARGRAPHIC, LONGVARGRAPHIC, DBCLOB.string-type:Any type from character type, graphic-type or BLOBnumer
3、ic-type:Any of the numeric types: SMALLINT, INTEGER, BIGINT, DECIMAL, REAL, DOUBLE.函數(shù)定義的Schema有sysfun和sysibm 1 字符串函數(shù)ascii 返回字符串首字符的ASCII碼值 integer : sysfun.ascii(<char>|<varchar(4000)>|<clob(1M)>) values sysfun.ascii('A'),sysfun.ascii('ABC'),sysfun.
4、ascii('中國(guó)人'); 結(jié)果:65 65 206hex 返回字符的十六進(jìn)制值 varchar : hex(<any-type>) values hex('中'),hex('A'),x'41',x'E590B4' 結(jié)果:E590B4 41 A 中 chr 返回ASCII值對(duì)應(yīng)的字符 char : sysfun.chr(<integer>) values sysfun.chr(89); 結(jié)果:Yconcat 字符串連接
5、160; string-type : sysibm.concat(<string-type>,<string-type>) values sysibm.concat('hello','world');結(jié)果:helloworldlower,lcase 轉(zhuǎn)小寫(xiě),upper,ucase 轉(zhuǎn)大寫(xiě) varchar(4000)|clob(1M) : sysfun.lcase(<varchar(4000>|<clob(1M)>) char|varchar : sysibm.lowe
6、r(<char>|<varchar>) values sysibm.lower('Your Name'),sysibm.upper('Your Name'); 結(jié)果:your name YOUR NAME values sysibm.lcase('Your Name'),sysfun.ucase('Your Name'); 結(jié)果:your name YOUR NAMEltrim 去左空格,rtrim 去右空格,trim 去左右空格 char|varchar|graphic
7、 sysibm.ltrim(<char>|<varchar>|<graphic>) varchar(4000)|clob(1M) sysfun.ltrim(<varchar(4000)>|<clob(1M)>) rtrim定義同ltrim,只不過(guò)trim函數(shù)定義不清楚 values ''|sysibm.ltrim(' h w ')|'',''|sysfun.rtrim(' h w ')|'','&
8、#39;|trim(' h w ')|'' 結(jié)果:h w h w h wtrim 去除表達(dá)式前后指定的字符,默認(rèn)是空格 character-type : sysibm.trim(B|BOTH|L|LEADING|T|TRAILING <strip-express> FROM <string-express>) 將表達(dá)式前或后(默認(rèn)是BOTH)指定的字符(strip-express)移除 values trim('0' from '00012300') 結(jié)果:123strip 去除表達(dá)
9、式前后指定的字符,默認(rèn)是空格 character-type : sysibm.strip(<string-express>,B|BOTH|L|LEADING|T|TRAILING,<strip-express>) values strip('*88000*',b,'*') 結(jié)果:88000posstr 查找字符串位置(從1開(kāi)始計(jì)數(shù)),沒(méi)有找到返回0 string-type : sysibm.posstr(<string-type:source-string>,<string-type:
10、search-string>) 前者為source-string,后為search-string values sysibm.posstr('the one is not that one','one'); 結(jié)果:5position 查找字符串位置,與posstr功能類(lèi)似,由于考慮到不同國(guó)家的字符集,增強(qiáng)編碼模式 string-type : sysibm.position(<string-type:source-string>,<string-type:search-string>,CODEUNITS16|C
11、ODEUNITS32|OCTETS) values position('a','abca',OCTETS) 結(jié)果:1locate 搜索子字符串出現(xiàn)的位置,找不到返回0 integer : sysfun.locate(<varchar(4000):exp1>,<varchar(4000):exp2>,integer) 其中varchar(4000)還可以換成clob(1M)或blob(1M) values sysfun.locate('y','yesterday'
12、;),sysfun.locate('y','yesterday',2); 結(jié)果: 1 9 repeat 重復(fù)字符串 varchar(4000)|clob(1M)|blob(1M) : sysfun.repeat(<varchar(4000)>|<clob(1M)>|<blob(1M)>,<integer>) values sysfun.repeat('ab',5); 結(jié)果:abababababspace 產(chǎn)生空格 varchar(
13、4000) : sysfun.space(<integer>) values ''|sysfun.space(5)|'' ; 結(jié)果: replace 替換字符串 varchar(4000)|clob(1M)|blob(1M) : sysfun.replace(<varchar(4000):exp1>,<varchar(4000):exp2>,<varchar(4000):exp3>) 在exp1中查找所有exp2使用exp3來(lái)替換
14、values sysfun.replace('abac','a','d'); 結(jié)果:dbdc left 返回左邊字符串 right 返回右邊字符串 varchar(4000)|clob(1M)|blob(1M) : sysfun.left(<varchar(4000)>|<clob(1M)>,<integer>) right函數(shù)同樣定義 values left('adf.adf',5),right('adf
15、.adf',5) ; 結(jié)果:adf.a f.adf values right(digits(3),5),left(rtrim(char(3)|'00000',5); 結(jié)果: 00003 30000 這也是左補(bǔ)零右補(bǔ)零的方法substr 截取字符中 string-type : sysibm.substr(<string-type:string>,<integer:start>,integer:length) 要求start從1string的長(zhǎng)度,如果指定length的話(huà),要求必
16、須能取到length位字符,不然會(huì)報(bào)錯(cuò)。 values sysibm.substr('abcdasd',1,2),sysibm.substr('abcdasd',3); 結(jié)果: ab cdasdsubstring 字符串截取函數(shù),與substr用法類(lèi)似,不同的是substr是按字節(jié)截取,substring可以指定string unit string-type : sysibm.substring(<string-type:string>,<integer:start>,<integer:lengt
17、h>,CODEUNITS16|CODEUNITS32|OCTETS) 其中CODEUNITS16按16-bit UTF-16的code unit,CODEUNITS32按32-bit UTF-32 code units,OCTETS則按字節(jié) values substring('中國(guó)人是我',1,4,CODEUNITS16),substring('中國(guó)人是我',1,6,OCTETS) 結(jié)果:'中國(guó)人是' '中國(guó)'octet_length 返回字符串的字節(jié)數(shù) integer : sysibm.
18、octet_length(<any-builtin-type>) values octet_length('abc中'); 結(jié)果:6length 返回字符串的長(zhǎng)度(字節(jié)) integer : sysibm.length(<any-builtin-type>,CODEUNITS16|CODEUNITS32|OCTETS)character_length 功能同length函數(shù),使用時(shí)必須輸入字符碼 values length('abc中'),character_length('abc中',
19、CODEUNITS32); 結(jié)果:6 42 數(shù)學(xué)函數(shù)digits 返回固定長(zhǎng)度(不夠前導(dǎo)補(bǔ)零)僅數(shù)字的字符串,不包括符號(hào)和點(diǎn),結(jié)果長(zhǎng)度small integer5位,large integer10位,big integer19位,decimal類(lèi)型p精度位 string : sysibm.digits(<numeric-type>) values digits(smallint(2.3),digits(2.3),digits(bigint(2.3),digits(dec(2.3,8,2); 結(jié)果是:'00002','23',&
20、#39;0000000000000000002','00000230' abs、absval 取絕對(duì)值 values abs(-23); 結(jié)果:23 ceiling、floor 向上取整和向下取整 values ceiling(13.56),floor(13.56); 結(jié)果:14 13mod 取模,取余數(shù) values mod(10,3); 結(jié)果:1rand 返回隨機(jī)數(shù) values rand;round 國(guó)舍五入 values r
21、ound(23.853,0),round(23.853,1),decimal(round(23.853,1),3,1) ,round(23.853,-1); 結(jié)果:24.000 23.900 23.9 20.000sign 如果參數(shù)大于0返回1,如果參數(shù)小于0返回-1,如果參數(shù)為0返回0power 返回參數(shù)1的參數(shù)2次冪sqrt 返回該參數(shù)的平方根degrees 求角度radians 將度轉(zhuǎn)換為弧度3 日期函數(shù)0)了解一下unix timestamp與DB2中的timestamp區(qū)別Unix時(shí)間戳(Unix Timestamp):從格人威治時(shí)間1970年01月01日00時(shí)00分00秒(1970
22、年1月1日 00:00:00 GMT)到現(xiàn)在的總秒數(shù)即從1970年1月1日(UTC/GMT的午夜)開(kāi)始所經(jīng)過(guò)的秒數(shù),不考慮閏秒。一個(gè)小時(shí)為3600秒,一個(gè)基準(zhǔn)日(紀(jì)元日,epoch day)為86400秒。以32位整型進(jìn)行保存,可能會(huì)在2038年1月19日產(chǎn)生一些問(wèn)題。GMT:Greenwich Mean Time 格人威治時(shí)間UTC:Universal Time Coordinated UTC時(shí)間,現(xiàn)在已經(jīng)漸漸變成GMT的同義詞轉(zhuǎn)換當(dāng)前時(shí)間為GMT時(shí)間:current timestamp - current timezone數(shù)據(jù)庫(kù)中的timestamp與unix timestamp是不同的,
23、即數(shù)據(jù)庫(kù)中的timestamp并不是時(shí)間戳,它是一個(gè)日期時(shí)間類(lèi)型記錄的是日期和時(shí)間信息。1)DB2中關(guān)于日期與時(shí)間的表示有timestamp日期和時(shí)間(其中時(shí)間部分精確到ff6,即1000000ms),date日期,time時(shí)間(精確到秒)oracle中的timestamp類(lèi)型精確到ff9毫秒2)寄存器中的日期與時(shí)間current timestamp 當(dāng)前時(shí)間戳current date 當(dāng)前日期current time 當(dāng)前時(shí)間3)日期時(shí)間對(duì)象直接相減,返回timestamp duration(數(shù)據(jù)類(lèi)型為dec(20,6),即yyyymmddhhmiss.ff6)、date duration(
24、數(shù)據(jù)類(lèi)型為dec(8,0),即yyyymmdd)和time duration(數(shù)據(jù)類(lèi)型為dec(6,0),即hhmiss)timestamp-timestamp 返回兩個(gè)時(shí)間戳對(duì)象相差的年月日時(shí)分秒毫秒date-date 返回兩個(gè)日期相差年月日time-time 返回兩個(gè)時(shí)間相差的時(shí)分秒values date('2011-02-13')-date('2010-01-12'); 返回1 01 01,也就是1年1個(gè)月1日values date('2998-02-13')-date('1220-08-26'); 返回1777 05 18
25、,也就是1777年5個(gè)月18日4)DB2中日期與時(shí)間對(duì)象能直接與帶單位的數(shù)值(忽略小數(shù)部分)相加減年years、月months、日days、小時(shí)hours、分鐘minutes、秒seconds、毫秒microsecondsvalues current time + 3 hours - 30 minutes + 58 seconds ; 結(jié)果:02:20:30values current date + 2 years - 2 months + 20 days; 結(jié)果:2013-12-03values current timestamp + 2 years - 2 mont
26、hs + 20 days + 3 hours - 30 minutes + 58 seconds; 結(jié)果:2013-12-04 02:20:305)日期時(shí)間字符串轉(zhuǎn)日期時(shí)間對(duì)象timestamp、date、time、year、month、day、hour、minute、second、microsecond這些函數(shù)的參數(shù)為timestmap、date、time、timestamp duration、date duration、time duration以及有效的時(shí)間日期字符串,結(jié)果依次返回參數(shù)的timestamp、日期、時(shí)間、年、月、日、小時(shí)、分鐘、秒和毫秒部分SELECT timestamp(
27、'2012-11-23 18:35:30.580000') col1, date('2012-11-23') col2, time('18:35:30') col3, current timestamp col17, current date col18,
28、0; current time col19, year(current timestamp) col4, year(current date) col5, month(current timestamp) col6, month(current dat
29、e) col7, day(current timestamp) col8, day(current date) col9, hour(current timestamp) col10, hour(current time) col11, m
30、inute(current timestamp) col12, minute(current time) col13, second(current timestamp) col14, second(current time) col15, microsecond(current timestamp) col1
31、6 FROM sysibm.sysdummy1;6)其它日期時(shí)間函數(shù)days 返回自0001年1月1日以來(lái)的天數(shù),可以用來(lái)計(jì)算兩個(gè)日期相隔的天數(shù) bigint : sysibm.days(timestamp|date|date-string) values days(current date)-days(date('2012-11-02'); 結(jié)果:21timestamp_format 根據(jù)格式化字符串和日期字符串返回timestamp timestamp : sysibm.timestamp_format(<exp1:st
32、ring>,<exp2:string>) ,其中exp1表示日期字符串,exp2表示格式化字符串 其中支持的日期時(shí)間格式化字符串有:yyyy 4位年、mm 2位月 、dd 2位月、hh12 12小時(shí)制小時(shí)、hh24 24小時(shí)制小時(shí)、mi 2位分鐘、ss 2位秒、ff 16位毫秒 格式化分隔符有dash (-)、period (.)、slash (/)、comma (,)、apostrophe (')、semi-colon (;)、colon (:)、blank ( ) SELECT timestamp_format('201
33、2/11/23 235935.540540','yyyy/mm/dd hh24miss.ff6') col1, timestamp_format('20121123','yyyymmdd') col2, timestamp_format('23,59','hh24,mi') col3 FROM sysibm.sysdummy1;to_timestamp和
34、to_date 字符串轉(zhuǎn)timestamp和date類(lèi)型,是timestamp_format的同義詞,用法類(lèi)似 timestampdiff 計(jì)算返回表達(dá)式中指定部分的值 integer:sysfun.timestampdiff(<exp1:integer>,<exp2:char(22)>) 參數(shù)exp1是指定值1(毫秒)|2(秒)|4(分鐘)|8(小時(shí))|16(天)|32(周)|64(月)|128(季)|256(年),參數(shù)exp2表示timestamp duration的char(22)字符串 values timestampdiff(
35、16,char(current timestamp - (current timestamp - 23 days); 注意:1、此函數(shù)在計(jì)算時(shí)按1月=30天計(jì)算,因此計(jì)算天不準(zhǔn)確,建議使用days()計(jì)算相差的天數(shù),例如下面計(jì)算2011-03-13與2010-01-26相差天數(shù),結(jié)果為413和411,明顯示411是正確的,而413是將2010年2月的28天當(dāng)30天多算了2天 values timestampdiff(16,char(timestamp('2011-03
36、-13 03:16:34.562003')-timestamp('2010-01-26 00:00:00'); values days(timestamp('2011-03-13 03:16:34.562003') - days(timestamp('2010-01-26 00:00:00'); 2、因?yàn)榉祷刂禐閕nteger類(lèi)型,所以函數(shù)在計(jì)算時(shí)有
37、精度誤差,它是只舍不入的,例如下面結(jié)果4,實(shí)際上應(yīng)該是4分鐘59秒 values timestampdiff(4,char(current timestamp - (current timestamp - 5 minutes + 1 seconds);quarter 返回日期所在季度,返回14 values quarter(current date) ; midnight
38、_seconds 返回自午夜過(guò)去的秒數(shù),即從00:00:00到指定時(shí)間間隔秒數(shù) SELECT current timestamp col1, midnight_seconds(current timestamp) col2, midnight_seconds(current time) col3 FROM sysibm.sysdummy1;monthname 返回月分名稱(chēng) values monthname(curre
39、nt date); dayofyear 返回日期在當(dāng)年中的第幾天,返回1366dayofweek 返回日期在周中的位置 integer : sysfun.dayofweek(timestamp|date|date-string) 返回17,分別表示星期天、星期一.星期六 values dayofweek(current date);dayname 返回日期是星期幾 string : sysfun.dayname(timestamp|date|date-s
40、tring) 返回本地星期的表示,如星期一week 返回日期是當(dāng)年的第幾周,返回154last_day 返回日期當(dāng)月的最后一天日期,在v9.7中使用s4 類(lèi)型轉(zhuǎn)換函數(shù)在DB2中內(nèi)置數(shù)據(jù)類(lèi)型都有自己相應(yīng)的數(shù)據(jù)類(lèi)型轉(zhuǎn)換函數(shù),如smallint、integer、bigint、decimal、real、double、float、char、varchar、clob、graphic、blob等因?yàn)槠涫褂煤?jiǎn)單,不作詳述decimal <-> char 假設(shè)字段定義為decimal(20,5),現(xiàn)在存儲(chǔ)8.9,直接轉(zhuǎn)結(jié)果是字符串為'000000000000008.90000 &
41、#39;,注意后面有一個(gè)空格 values char(cast(8.9 as decimal(20,5); 最佳寫(xiě)法:values strip(trim(char(cast(8.9 as decimal(20,5),both,'0'); 結(jié)果是字符串'8.9' 字符串'8.9'轉(zhuǎn)成decimal(10,5)寫(xiě)法 values decimal('8.94',10,2);或者values cast('8.934' as decimal(10,5);
42、cast 數(shù)據(jù)類(lèi)型轉(zhuǎn)換 data-type : cast(<exp> as <data-type>) values cast('123' as integer);decimal或者dec decimal : sysibm.dec(<numeric-type>,integer,integer) 返回?cái)?shù)值的小數(shù)顯示形式 參數(shù)說(shuō)明:numeric-type 數(shù)值類(lèi)型,integer1 精度(precision),integer2 該度(scale),就是顯示的小數(shù)位數(shù)
43、; 如果precision設(shè)置過(guò)小,會(huì)報(bào)SQLSTATE=22003錯(cuò)誤,數(shù)值轉(zhuǎn)換時(shí)越界,即要求整數(shù)部分位數(shù) < precision - scale, 例如decimal(223.345,6,2)中6定義一共6位數(shù)字,2定義兩位小數(shù),如果需要轉(zhuǎn)換的字符串非小數(shù)部分位數(shù)超6-2就會(huì)報(bào)錯(cuò) 。 decimal : sysibm.dec(<varchar>,integer,integer,varchar) 將字符串轉(zhuǎn)成小數(shù)形式的數(shù)值,需要指定decimal-character(最后一個(gè)參數(shù)) valu
44、es sysibm.dec(233.2323,4,1); 結(jié)果:233.2 values sysibm.dec(233,4,1); 結(jié)果:233.00 values sysibm.dec('23.2323',5,1,'.'); 結(jié)果:23.20 values sysibm.decimal(223.345,6,2); 結(jié)果:22
45、3.34char 轉(zhuǎn)字符串 char : sysibm.char(<decimal-type>,varchar) 返回?cái)?shù)值的字符串格式,如果指定varchar字符串的話(huà),那么decimal中的點(diǎn)按指定字符串顯示 char : sysibm.char(<character-type>,integer) 返回字符串,如果指定integer的話(huà)就按長(zhǎng)度返回 char : char(<date-type>,keywords) 返回日期的字符串,按keywords格式化 D
46、B2日期的缺省格式由數(shù)據(jù)庫(kù)的地區(qū)代碼決定,該代碼在數(shù)據(jù)庫(kù)創(chuàng)建的時(shí)候被指定。可以在創(chuàng)建數(shù)據(jù)庫(kù)時(shí)使用 territory=USA 來(lái)定義地區(qū)代碼,可選值有: DEF 使用與地區(qū)代碼相匹配的日期和時(shí)間格式 EUR 使用歐洲日期和時(shí)間的 IBM 標(biāo)準(zhǔn)格式,格式:dd.mm.yyyy ISO 使用國(guó)際標(biāo)準(zhǔn)組織(ISO)制訂的日期和時(shí)間格式,格式:yyyy-mm-dd
47、JIS 使用日本工業(yè)標(biāo)準(zhǔn)的日期和時(shí)間格式,格式為:yyyy-mm-dd LOC 使用與數(shù)據(jù)庫(kù)地區(qū)代碼相匹配的本地日期和時(shí)間格式,本地日期格式,在char(date-type,keywords)中使用LOCATE USA 使用美國(guó)日期和時(shí)間的 IBM 標(biāo)準(zhǔn)格式,格式:mm/dd/yyyy values sysibm.char(223.345,',') ; 結(jié)果:223,345 values
48、sysibm.char('223.345',4) ; 結(jié)果:223. values char(current date,ISO); 結(jié)果:2012-05-09 values sysibm.char(current date); 結(jié)果:2012-05-09 values sysibm.char(current timestamp);結(jié)果:2012-05-09-23.2
49、2.03.906000 values sysibm.char(34); 結(jié)果:34to_char 將timestamp類(lèi)型參數(shù)轉(zhuǎn)成指定格式字符串 定義: varchar : sysibm.to_char(<timestamp>,<varchar>) 實(shí)例: values sysibm.to_char(current timestamp,'yyyy-mm-dd h
50、h:mi:ss'); 結(jié)果:2012-05-10 01:24:435 其它函數(shù)coalesce 取第一個(gè)非空值,可以用來(lái)將NULL轉(zhuǎn)成指定值 any-type : sysibm.coalesce(par1,par2,.) 要求參數(shù)類(lèi)型一致,可以接受任何build-in data type values coalesce(cast(null as integer),2,3);value 取第一個(gè)非空值,用法類(lèi)似于coalesce nullif 參數(shù)相等時(shí)返回NULL,否則返回第一個(gè)參數(shù) any-type : sysibm.nullif(<
51、;any-type>,<any-type>) nullif(e1,e2) 相當(dāng)于 case when e1=e2 then null else e1 end values sysibm.nullif('a','a'),sysibm.nullif(cast(null as char(1),'a');數(shù)值截?cái)嗪瘮?shù) trunc或truncate decimal-type : sysfun.trunc(<decimal-type:exp1>,
52、<integer:exp2>) 其中exp2為正數(shù)時(shí)截?cái)嘈?shù)位(保留小數(shù)位),為負(fù)數(shù)時(shí)向左截?cái)嗾麛?shù)位(變0) values sysfun.truncate(345.2344,2),truncate(345.2344,56),truncate(345.2344,0),truncate(345.2344,-1); 結(jié)果:345.23 345.2344 345 340translate 字符串轉(zhuǎn)換 varchar : sysibm.translate(<varchar:source-st
53、ring>,<varchar:to-string>,<varchar:from-string>,varchar:pad-string) 按自左到右順序,按位找from-string中的字符在source-string出現(xiàn)時(shí)使用同位置(與from-string中字符相同位置)的字符替換, 如果在from-string中的位置在to-string中沒(méi)有,則使用pad-string字符串(默認(rèn)是空格)替換 values sysibm.tra
54、nslate('Hello World','db2','World','%'); 結(jié)果:He%b db2% 解釋:from-string為World,to-string為db2,替換字符串為%,就是在Hello World中替換W->d,o->b,r->2,l->%,d->% vlaues ''|sysibm.trans
55、late('Hello World','db2','World')|' ; 結(jié)果:He b db2 listagg 聚集函數(shù)DB2 v9.7.4 中新增的函數(shù),用于拼SELECT id,LISTAGG(name,',') WITHIN GROUP(ORDER BY name) names FROM (VALUES(1,'張三'),(1,'李明'),(1,'楊青'),(2,'柯言'),(2,'何楓') AS t
56、(id,name)GROUP BY id;結(jié)果:id name- -1 張三,李明,楊青2 何楓,柯言SELECT stno,LISTAGG(subname|' '|score,',') WITHIN GROUP(ORDER BY 1) info FROM (VALUES ('NO01','語(yǔ)文',90) , ('NO01','數(shù)學(xué)',99) , ('NO01','英語(yǔ)',98) , &
57、#160; &
58、#160; ('NO02','語(yǔ)文',96),('NO02','數(shù)學(xué)',95) AS t(stno,subname,score)GROUP BY stno;結(jié)果:STNO INFO- -NO01 語(yǔ)文
59、 90,數(shù)學(xué) 99,英語(yǔ) 98NO02 語(yǔ)文 96,數(shù)學(xué) 95xmlagg 函數(shù)SELECT stno,REPLACE(REPLACE(XML2CLOB(XMLAGG(XMLELEMENT(NAME stno,subname|' '|score|' , '),'<STNO>'),'</STNO>') info FROM (VALUES ('NO01','語(yǔ)文',90) , ('NO01
60、','數(shù)學(xué)',99) , ('NO01','英語(yǔ)',98) , &
61、#160; ('NO02','語(yǔ)文',96),('NO02','數(shù)學(xué)',95) AS t(stno,subname,score)GROUP BY stno;結(jié)果:STNO
62、60; INFO- -NO01 語(yǔ)文 90 , 數(shù)學(xué) 99 , 英語(yǔ) 98 ,NO02 語(yǔ)文 96 , 數(shù)學(xué) 95 ,type_id、type_name和type_schema 返回?cái)?shù)據(jù)類(lèi)型的id、name和schema,要求參數(shù)是structured data typestrip 功能增加的trim標(biāo)量函數(shù),它可以用來(lái)去除表達(dá)式的前綴和后綴
63、160; 特殊應(yīng)用:-獲取當(dāng)前月份values month(current timestamp) ;-獲取當(dāng)前日期是當(dāng)前月的第幾天values day(current timestamp) ;-獲取當(dāng)前月表天數(shù)-獲取上月最后一天values current timestamp - day(current timestamp) days ;-獲取上月第一天values current timestamp -1 months - day(current timestamp) days + 1
64、days ;-獲取本月第一天values current timestamp - day(current timestamp) days + 1 days ;values current timestamp - day(current timestamp) days - hour(current timestamp) hours - minute(current timestamp) minutes - second(current timestamp) seconds - microsecond(current timestamp) microsecond + 1 days ;-獲取本月最后
65、一天values current timestamp + 1 months - day(current timestamp) days ;values current timestamp - day(current timestamp) days + 1 days + 1 months - 1 days ;values current timestamp + 1 months - day(current timestamp) days - hour(current timestamp) hours - minute(current timestamp) minutes - second(cur
66、rent timestamp) seconds - microsecond(current timestamp) microsecond ;values current date + 1 months - day(current date + 1 months) days ;-獲取下月第一天values current timestamp + 1 months - day(current timestamp) days - hour(current timestamp) hours - minute(current timestamp) minutes - second(current timestamp) seconds - microsecond(current timestamp) microsecond + 1 days;計(jì)算兩個(gè)時(shí)間之間的差(秒)CREATE FUNCTION second_diff(t1 timestamp, t2 timestamp)RETURNS intRETURN (days(t1) - days(t2) * 86400 + (midnight_seconds(t1) - midnight_seconds(t2);調(diào)用: VALUES second_diff(timestamp('2012-05-10 12:50:23
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026中國(guó)人民對(duì)外友好協(xié)會(huì)所屬事業(yè)單位招聘工作人員5人參考考試題庫(kù)及答案解析
- 雨污水改造工程技術(shù)方案
- 綠色建筑與分布式光伏結(jié)合方案
- 商務(wù)車(chē)零部件生產(chǎn)制造項(xiàng)目技術(shù)方案
- 初中英語(yǔ)寫(xiě)作中邏輯銜接詞與篇章結(jié)構(gòu)關(guān)系實(shí)驗(yàn)研究課題報(bào)告教學(xué)研究課題報(bào)告
- 基于核心素養(yǎng)的小學(xué)低段學(xué)生行為習(xí)慣養(yǎng)成路徑探究教學(xué)研究課題報(bào)告
- 流感知識(shí)普及:預(yù)防措施與護(hù)理要點(diǎn)
- 小學(xué)英語(yǔ)戲劇教學(xué)法在閱讀理解能力培養(yǎng)中的應(yīng)用研究教學(xué)研究課題報(bào)告
- 2025廣西廣電網(wǎng)絡(luò)科技發(fā)展有限公司平樂(lè)分公司招聘2人模擬筆試試題及答案解析
- 護(hù)理內(nèi)分泌系統(tǒng)護(hù)理課件
- 心衰患者的康復(fù)護(hù)理
- 2026年內(nèi)科護(hù)理工作計(jì)劃范文4篇
- 2025超重和肥胖管理指南課件
- 武警拓展訓(xùn)練方案
- 五年級(jí)下冊(cè)《勞動(dòng)技術(shù)》15、番茄炒雞蛋課件
- 2024統(tǒng)編版七年級(jí)語(yǔ)文上冊(cè)第四單元測(cè)試卷(原卷版+答案版)
- 2025年合肥興泰金融控股(集團(tuán))有限公司招聘23人筆試參考題庫(kù)附答案
- 肺癌科普宣傳知識(shí)課件
- 2025新疆和田和康縣、和安縣面向社會(huì)招聘事業(yè)單位工作人員108人筆試考試參考試題及答案解析
- (2025年)河源市委社會(huì)工作部遴選公務(wù)員考試試題附答案
- 婦產(chǎn)科考試試題及答案
評(píng)論
0/150
提交評(píng)論