sql字符串截取oracle,SQL Sever和Oracle截取字符串分析
不同的數據庫下截取字符串的方法函數是不同的,在sql server下用的是substring(expression, start, length),Oracle下用的是substr(expression, start, length),參數都是一致的,要截取的字符串,起始位置,長度。其中的差異部門就在第二個參數起始位置。下面拿"Hello"做例子
1:SQL Server 下截取字符串
返回SQL Server 中的字符、二進制、文本或圖像表達式的一部分。
substring('Hello',-2,3)?????--?He
substring('Hello',0,3)??????--?He
substring('Hello',1,3)??????--?Hel
substring('Hello',1,5)??????--?Hello
substring('Hello',1,6)??????--?Hello
substring('Hello',2,6)??????--?ello?長度大于要截取的字符串,返回起始位置的整個值表達式
substring('Hello',6,1)??????--??????如果起始位置大于要截取的最大長度返回空
2:Oracle 下截取字符串
oracle與sqlserver不同的地方就在于起始位置為負數的時候,和起始位置為0時。substr('Hello',-2,3)???????--lo??從右向左的第二個開始
substr('Hello',-4,3)???????--ell
substr('Hello',0,3)????????--Hel
substr('Hello',1,3)????????--Hel
substr('Hello',1,5)????????--Hello
substr('Hello',1,6)????????--Hello
substr('Hello',2,6)????????--ello
substr('Hello',6,1)????????--
打賞
總結
以上是生活随笔為你收集整理的sql字符串截取oracle,SQL Sever和Oracle截取字符串分析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PTA - 简单计算器
- 下一篇: 理论+实战,一文详解最常使用的10个聚类