sql語句用法大全

2022-06-11 21:24:07 字數 1703 閱讀 2115

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

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

解析:

格式1:

1、string 需要擷取的字串 

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

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

格式2:

1、string 需要擷取的字串

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

格式1:

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

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

4、select substr('helloworld',0,100) value from dual; //返回結果:helloworld,100雖然超出預處理的字串最長度,但不會影響返回結果,系統按預處理字串最大數量返回。5、select substr('helloworld',5,3) value from dual; //返回結果:owo6select substr('hello world',5,3) value from dual; //返回結果:o w (中間的空格也算乙個字串,結果是:o空格w)7、select substr('helloworld',-1,3) value from dual; //返回結果:d (從後面倒數第一位開始往後取1個字元,而不是3個。原因:下面紅色 第三個註解)8、select substr('helloworld',-2,3) value from dual; //返回結果:ld (從後面倒數第二位開始往後取2個字元,而不是3個。原因:下面紅色 第三個註解)9、select substr('helloworld',-3,3) value from dual; //返回結果:rld (從後面倒數第三位開始往後取3個字元)10select substr('helloworld',-4,3) value from dual; //返回結果:orl (從後面倒數第四位開始往後取3個字元)

作用:判斷某個值是否為空值,若不為空值則輸出,若為空值,返回指定值。

詳細解釋如下:

1、nvl()函式的格式如下:nvl(expr1,expr2);

2、含義是:如果oracle第乙個引數為空那麼顯示第二個引數的值,如果第乙個引數的值不為空,則顯示第乙個引數本來的值。

3、例:select name,nvl(name,-1) from user;執行後,結果返回兩列數值,若name為空,則返回-1,若name不為空值,則返回其自身。

《SQL語句大全》

語 句 功 能 資料操作 select 從資料庫表中檢索資料行和列 insert 向資料庫表新增新資料行 delete 從資料庫表中刪除資料行 update 更新資料庫表中的資料 資料定義 create table 建立乙個資料庫表 drop table 從資料庫中刪除表 alter table 修...

SQL語句大全

建表 create table tab1 id counter,name string,age integer,date datetime 技巧 自增字段用 counter 宣告.欄位名為關鍵字的字段用方括號括起來,數字作為欄位名也可行.建立索引 下面的語句在tab1的date列上建立可重複索引 c...

習SQL語句之SQL語句大全

語 句 功 能 資料操作 select 從資料庫表中檢索資料行和列 insert 向資料庫表新增新資料行 delete 從資料庫表中刪除資料行 update 更新資料庫表中的資料 資料定義 create table 建立乙個資料庫表 drop table 從資料庫中刪除表 alter table 修...