隨筆-314  評(píng)論-209  文章-0  trackbacks-0

          Sybase 函數(shù)

           

          Sybase字符串函數(shù)

          長(zhǎng)度和語(yǔ)法分析
          datalength(char_expr)
          在char_expr中返回字符的長(zhǎng)度值,忽略尾空
          substring(expression,start,length)
          返回部分字符串
          right(char_expr,int_expr)
          返回char_expr右邊的int_expr字符
          基本字符串運(yùn)算
          upper(char_expr)
          把char_expr轉(zhuǎn)換成大寫(xiě)形式
          lower(char_expr)
          把char_expr轉(zhuǎn)換成小寫(xiě)形式
          space(int_expr)
          生成有int_expr個(gè)空格的字符串
          replicate(char_expr,int_expr)
          重復(fù)char_expr,int_expr次
          stuff(expr1,start,length,expr2)
          用expr2代替epxr1中start起始長(zhǎng)為length的字符串
          reverse(char_expr)
          反寫(xiě)char_expr中的文本
          ltrim(char_expr)
          刪除頭空
          rtrim(char_expr)
          刪除尾空
          格式轉(zhuǎn)換
          ascii(char_expr)
          返回char_expr中第一個(gè)字符的ASCII值
          char(int_expr)
          把ASCII碼轉(zhuǎn)換為字符
          str(float_expr[,length[,decimal]])
          進(jìn)行數(shù)值型到字符型轉(zhuǎn)換
          soundex(char_expr)
          返回char_expr的soundex值
          difference(char_expr1,char_expr2)
          返回表達(dá)式soundex值之差
          串內(nèi)搜索
          charindex(char_expr,expression)
          返回指定char_expr的開(kāi)始位置,否則為0
          patindex("%pattern%",expression)
          返回指定樣式的開(kāi)始位置,否則為0
            
          datalength
          用于確定可變字符串的長(zhǎng)度
          soundex
          用于確定字符串是否發(fā)音相似
          difference
          返回0-4之間的值,0表示最不相似,4表示最相似
          通配符
          %
          匹配任何數(shù)量的字符或無(wú)字符
          _
          匹配任何單個(gè)字符(空間占位符)
          []
          規(guī)定有效范圍,或某個(gè)"OR"條件
              [ABG]   A,B,G
              [A-C]   A,B,C
              [A-CE-G] A,B,C,E,F,G
              [^ABG]
          除了A,B,G
              [^A-C]  
          除了A,B,C
            
          escape
          子句
          用某個(gè)轉(zhuǎn)義字符可在搜索字符串時(shí)將通配符作為文字來(lái)包含。
          ANSI-89 SQL
          標(biāo)準(zhǔn)定義了escape子句指定某個(gè)轉(zhuǎn)義字符
          缺省情況下,[]來(lái)轉(zhuǎn)義某個(gè)通配符,例:
          select * from test_tab
              where description like "%20[%]%"
          語(yǔ)法:
          like char_expression escape escape_character

          select * from test_tab
              where description like "%20#%%" escape "#"
          +
          可用于串接字符
          select au_laname+","+au_fname from authors
            
          數(shù)學(xué)函數(shù)
          abs(numeric_expr)
          返回指定值的絕對(duì)值
          ceiling(numeric_expr)
          返回大于或等于指定值的最小整數(shù)
          exp(float_expr)
          給出指定值的指數(shù)值
          floor(numeric_expr)
          返回小于或等于指定值的最大整數(shù)
          pi()
          返回常數(shù)3.1415926
          power(numeric_expr,power)
          返回numeric_expr的值給power的冪
          rand([int_expr])
          返回0-1之間的隨機(jī)浮點(diǎn)數(shù),可指定基值
          round(numeric_expr,int_expr)
          把數(shù)值表達(dá)式圓整到int_expr指定的精度
          sign(int_expr)
          返回正+1,零0或負(fù)-1
          sqrt(float_expr)
          返回指定值的平方根
          SQL SERVER
          支持所有標(biāo)準(zhǔn)的三角函數(shù)和其他有用的函數(shù)
            
          日期函數(shù)
          getdate()
          返回當(dāng)前的系統(tǒng)日期和時(shí)間
          datename(datepart,date_expr)
          以字符串形式返回date_expr指定部分的值,轉(zhuǎn)換成合適的名字
          datepart(datepart,date_expr)
          作為整數(shù)返回date_expr值的指定部分
          datediff(datepart,date_expr1,date_expr2)
          返回date_expr2-date_expr1,通過(guò)指定的datepart度量
          dateadd(datepart,number,date_expr)
          返回日期,通過(guò)在date_expr上增加指定number的日期部件而產(chǎn)生的
            
          datepart
          日期部件   縮寫(xiě)   值范圍
          yy   1753-9999
          季度 qq   1-4
          mm   1-12
          每年中的天   dy   1-366
          dd   1-31
          星期 wk   1-54
          星期天 dw   1-7(1=sunday)
          小時(shí) hh   0-23
          分鐘 mi   0-59
          ss   0-59
          毫秒 ms   0-999
          例:
          select invoice_no,
              datediff(dd,date_shipped,getdate())
              from invoices
              where balance_due>0
            
          轉(zhuǎn)換函數(shù)convert
          此函數(shù)把值從一種類(lèi)型改變成另一種類(lèi)型
          convert(datetype [(length)],expression)
          select "Advance="+convert(char(12),advance)
              from titles

          日期轉(zhuǎn)換
          convert(datetype[(length)],expression,format)
          format
          指定將日期轉(zhuǎn)換為什么格式,有以下值:
          沒(méi)有世紀(jì)   有世紀(jì) 轉(zhuǎn)換字符串中日期格式
              0 or 100   mon dd yyy hh:miAM(or PM)
          1 101 mm/dd/yy
          2 102 yy.mm.dd
          3 103 dd/mm/yy
          4 104 dd.mm.yy
          5 105 dd-mm-yy
          6 106 dd mon yy
          7 107 mon dd,yy
          8 108 hh:mm:ss
              9 or 109   mon dd,yyyy hh:mi:ss:mmmAM(or PM)
          10 110 mm-dd-yy
          11 111 yy/mm/dd
          12 112 yymmdd
            
          系統(tǒng)函數(shù)
          函數(shù)       定義
          訪問(wèn)和安全性信息
          host_id()      
          客戶進(jìn)程的當(dāng)前主機(jī)進(jìn)程ID號(hào)
          host_name()       
          客戶進(jìn)程的當(dāng)前主計(jì)算機(jī)名
          suser_id(["login_name"])  
          用戶的SQL Server ID號(hào)
          suser_name([server_user_id])  
          用戶的SQL Server登錄名
          user_id(["name_in_db"])
          用戶在數(shù)據(jù)庫(kù)中的ID號(hào)
          user_name([user_id])
          用戶在數(shù)據(jù)庫(kù)中的名字
          user         
          用戶在數(shù)據(jù)庫(kù)中的名字
          show_role()       
          用戶的當(dāng)前活動(dòng)角色

          數(shù)據(jù)庫(kù)和對(duì)象信息
          db_id(["db_name"]) 數(shù)據(jù)庫(kù)ID號(hào)
          db_name([db_id])   
          數(shù)據(jù)庫(kù)名
          object_id("objname")
          數(shù)據(jù)庫(kù)對(duì)象ID號(hào)
          object_name(obj_id])
          數(shù)據(jù)庫(kù)對(duì)象號(hào)
          col_name(obj_id,col_id)
          對(duì)象的欄名
          col_length("objname","colname")  
          欄的長(zhǎng)度
          index_col("objname",index_id,key#)  
          已索引的欄名
          valid_name(char_expr)
          若char_expr不是有效標(biāo)識(shí)符,則返回0

          數(shù)據(jù)函數(shù)
          datalength(expression) 按字節(jié)返回expression的長(zhǎng)度
          tsequal(timestamp1,timestamp2)  
          比較時(shí)戳值,若時(shí)戳值不匹配,則返回出錯(cuò)消息
            
          isnull()
          isnull
          函數(shù)用指定的值代替查詢欄或合計(jì)中的空值
          例:
          select avg(isnull(total_order,$0))
              from invoices

           

          posted on 2012-08-21 10:49 xzc 閱讀(5177) 評(píng)論(1)  編輯  收藏 所屬分類(lèi): SybaseIQ

          評(píng)論:
          # re: Sybase 函數(shù) 2012-11-08 19:49 | jj

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 铜山县| 祁阳县| 遂川县| 卢氏县| 县级市| 偃师市| 区。| 新巴尔虎右旗| 刚察县| 六安市| 湖南省| 新田县| 德兴市| 修水县| 新巴尔虎左旗| 兴化市| 朝阳区| 聂拉木县| 百色市| 万年县| 淳安县| 元朗区| 宜州市| 高尔夫| 夏津县| 肃宁县| 新邵县| 刚察县| 侯马市| 眉山市| 玉屏| 明光市| 珠海市| 黄龙县| 芜湖市| 建德市| 合肥市| 徐州市| 白山市| 安庆市| 镶黄旗|