oracle 達夢擷取字串

2021-10-05 12:24:05 字數 1648 閱讀 1696

格式1: substr(string string, int a, int b);  

格式2:substr(string string, int a) ;

解釋:格式1

1、string 需要擷取的字串 

2、a 擷取字串的開始位置(注:當a等於0或1時,都是從第一位開始擷取)

3、b 要擷取的字串的長度

格式21、string 需要擷取的字串

2、a 可以理解為從第a個字元開始擷取後面所有的字串。

1、substr('helloworld',0,3); //返回結果:hel,擷取從「h」開始3個字元

2、substr('helloworld',1,3); //返回結果:hel,擷取從「h」開始3個字元

3、substr('helloworld',2,3); //返回結果:ell,擷取從「e」開始3個字元

4、substr('helloworld',0,100); //返回結果:helloworld,100雖然超出預處理的字串最長度,但不會影響返回結果,系統按預處理字串最大數量返回。

5、substr('helloworld',5,3); //返回結果:owo

6、substr('hello world',5,3); //返回結果:o w (中間的空格也算乙個字串,結果是:o空格w)

7、substr('helloworld',-1,3); //返回結果:d (從後面倒數第一位開始往後取1個字元,而不是3個。原因:下面紅色 第三個註解)

8、substr('helloworld',-2,3); //返回結果:ld (從後面倒數第二位開始往後取2個字元,而不是3個。原因:下面紅色 第三個註解)

9、substr('helloworld',-3,3); //返回結果:rld (從後面倒數第三位開始往後取3個字元)

10、substr('helloworld',-4,3); //返回結果:orl (從後面倒數第四位開始往後取3個字元)(注:當a等於0或1時,都是從第一位開始擷取(如:1和2))

(注:假如helloworld之間有空格,那麼空格也將算在裡面(如:5和6))

(注:雖然7、8、9、10擷取的都是3個字元,結果卻不是3 個字元; 只要 |a| ≤ b,取a的個數(如:7、8、9);當 |a| ≥ b時,才取b的個數,由a決定擷取位置(如:9和10))

11、substr('helloworld',0);  //返回結果:helloworld,擷取所有字元

12、substr('helloworld',1);  //返回結果:helloworld,擷取所有字元

13、substr('helloworld',2);  //返回結果:elloworld,擷取從「e」開始之後所有字元

14、substr('helloworld',3);  //返回結果:lloworld,擷取從「l」開始之後所有字元

15、substr('helloworld',-1);  //返回結果:d,從最後乙個「d」開始 往回擷取1個字元

16、substr('helloworld',-2);  //返回結果:ld,從最後乙個「d」開始 往回擷取2個字元

17、substr('helloworld',-3);  //返回結果:rld,從最後乙個「d」開始 往回擷取3個字元

(注:當只有兩個引數時;不管是負幾,都是從最後乙個開始 往回擷取(如:15、16、17))

Oracle擷取字串

今天遇到的問題是 我需要乙個201802281530時間格式的字串 即年月日時分 但是讀取的oracle資料庫裡只有2018 02 28 15 30 00這種格式的char型別。由於程式大都是直接呼叫其他方法,不方便在程式內操作,只能在oracle讀取時解決問題。解決後的最終sql 為 substr...

oracle擷取字串

格式1 substr string string,int a,int b 格式2 substr string string,int a 解釋 格式1 1 string 需要擷取的字串 2 a 擷取字串的開始位置 注 當a等於0或1時,都是從第一位開始擷取 3 b 要擷取的字串的長度 格式21 str...

oracle中擷取字串

substring 返回字元 binary text 或 image 表示式的一部分。有關可與該函式一起使用的有效 microsoft sql server 資料型別的更多資訊,請參見資料型別。語法 substring expression start length 引數 expression 是字...