日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oracle both from,Oracle trim函数的使用

發(fā)布時(shí)間:2023/12/8 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle both from,Oracle trim函数的使用 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

TRIM,LTRIMandRTRIMareSQLfunctions used to filter unwanted characters from strings. By default they remove spaces, but a set of characters can be specified for removal as well.

TRIM,?LTRIM?、RTRIM是用于過濾一些不想要的字符的sql函數(shù),默認(rèn)去除空格,也可以去除指定的字符串。

TRIM enables you to trim leading or trailing characters (or both) from a character string. If trim_character or trim_source is a character literal, then you must enclose it in single quotes.

If you specify LEADING, then Oracle Database removes any leading characters equal to trim_character.

If you specify TRAILING, then Oracle removes any trailing characters equal to trim_character.

If you specify BOTH or none of the three, then Oracle removes leading and trailing characters equal to trim_character.

If you do not specify trim_character, then the default value is a blank space.

If you specify only trim_source, then Oracle removes leading and trailing blank spaces.

The function returns a value with datatype VARCHAR2. The maximum length of the value is the length of trim_source.

If either trim_source or trim_character is null, then the TRIM function returns null.

Both trim_character and trim_source can be any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The string returned is of VARCHAR2 datatype if trim_source is a character datatype and a LOB if trim_source is a LOB datatype. The return string is in the same character set as trim_source.

下面舉例說明:

1、trim(str)等價(jià)于trim(both from '字符串')

select trim('? 去除前后空格? ') from dual;

等價(jià)于

SQL> select trim(both from'? 去除前后空格? ') from dual;

TRIM(BOTHFROM'去除前后空格')

----------------------------

去除前后空格

2、trim(leading from str)

SQL> select trim(leading from '? 用leading只去除前面空格,后面的空格不會去除? ')||'看看前面那句話后面的空格沒去掉吧' from dual;

TRIM(LEADINGFROM'用LEADING只去

-----------------------------------------------------------------------------

用leading只去除前面空格,后面的空格不會去除? 看看前面那句話后面的空格沒去掉吧

3、trim(trailing from '?字符串')

SQL> select 'Start'||trim(trailing from '? 用trailing只去除末尾的空格,字符串前面的空格不會去除? ')||'End' from dual;

'START'||TRIM(TRAILINGFROM'用T

--------------------------------------------------------------

Start? 用trailing只去除末尾的空格,字符串前面的空格不會去除End

4、刪除字符串末尾的字符d

SQL> select 'Start='||trim(trailing 'd' from 'Hello World')||'=End' from dual;

'START='||TRIM(TRAILING'D'FROM

------------------------------

Start=Hello Worl=End

LTRIM

LTRIM()(char [,set]):該函數(shù)用于去掉字符串char左端所包含的set中的任何字符。Oracle從左端第一個(gè)字符開始掃描,逐一去掉在set中出現(xiàn)的字符,當(dāng)遇到不是set中的字符時(shí)終止,然后返回剩余結(jié)果。

先看幾個(gè)實(shí)例:

SQL> select ltrim('109224323','109') from dual;

LTRIM('109224323','109')

------------------------

224323

這個(gè)的功能應(yīng)該都知道的噢~~? 再來看一個(gè):

SQL> select ltrim('10900094323','109') from dual;

LTRIM('10900094323','109')

---------------------------

4323

是不是有點(diǎn)迷糊了?按道理說應(yīng)該是00094323的結(jié)果嘛~~? 再來看兩個(gè)對比的:

SQL> select ltrim('10900111000991110224323','109') from dual;

LTRIM('10900111000991110224323

------------------------------

224323

SQL> select ltrim('109200111000991110224323','109') from dual;

LTRIM('10920011100099111022432

------------------------------

200111000991110224323

是不是有這樣的疑問:為什么第二個(gè)查詢語句多了一個(gè)2就沒被截了呢?

再來看一個(gè):

SQL> select ltrim('902100111000991110224323','109') from dual;

LTRIM('90210011100099111022432

------------------------------

2100111000991110224323

我想大家都都會想:按道理說是截109的值,為什么90也被截了?

總結(jié):ltrim(x,y) 函數(shù)是按照y中的字符一個(gè)一個(gè)截掉x中的字符,并且是從左邊開始執(zhí)行的,只要遇到y(tǒng)中有的字符, x中的字符都會被截掉, 直到在x的字符中遇到y(tǒng)中沒有的字符為止函數(shù)命令才結(jié)束 .

函數(shù)將109當(dāng)成了三個(gè)字符以1,0,9在字符串開始直道出現(xiàn)不為1,0,9這三個(gè)字符中的任意一個(gè)開始截取;

可以看出,ltrim函數(shù)是從匹配函數(shù)開始之后出現(xiàn)在子串中任何字符都被屏蔽掉了;

ltrim('902100111000991110224323','109')從左邊開始截取,直到出現(xiàn)不符合1,0,9結(jié)束,即到2停止截取,不管2后面是否存在1,0,9照樣輸出,rtrim()同理

RTRIM 同LTRIM。。。

總結(jié)

以上是生活随笔為你收集整理的oracle both from,Oracle trim函数的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。