常用的SQL函式

2021-10-10 09:44:59 字數 1500 閱讀 1788

update temp_20200420_48

set aac147 = substr(bz,

instr(bz, '|', 1, 4) + 1,

instr(bz, '|', 1, 5) - instr(bz, '|', 1, 4) - 1),

aac003 = substr(bz,

instr(bz, '|', 1, 1) + 1,

instr(bz, '|', 1, 2) - instr(bz, '|', 1, 1) - 1);

select bz, instr(bz, '|', 1, 1), instr(bz, '|', 1, 2)

from temp_20200420_48;

格式一:instr( string1, string2 )    // instr(源字串, 目標字串)

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

1、string 需要擷取的字串

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

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

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

1、string 需要擷取的字串

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

create sequence seq_aaz621

increment by 1

start with 1

maxvalue 9999999999999999

minvalue 1

cache 50

order;

解析:

increment    by    x    //x為增長間隔     

start with x //x為初始值

maxvalue x //x為最大值

minvalue x //x為最小值

cycle //迴圈使用,到達最大值或者最小值時,從新建立物件

cache x //制定存入快取(也就是記憶體)序列值的個數

序列是一資料庫物件,利用它可生成唯一的整數。一般使用序列自動地生成主碼值。乙個序列的值是由特別的oracle程式自動生成。

如果不設定cycle迴圈的話,每乙個序列號是唯一的。 當乙個序列號生成時,序列是遞增

當使用到序列的事務發生回滾。會造成序列號不連續。

cache的作用:當大量語句發生請求,申請序列時,為了避免序列在運用層實現序列而引起的效能瓶頸。oracle序列允許將序列提前生成 cache x個先存入記憶體,

在發生大量申請序列語句時,可直接到執行最快的記憶體中去得到序列。但cache個數也不能設定太大,因為在資料庫重啟時,會清空記憶體資訊,預存在記憶體中的序列會丟失,

當資料庫再次啟動後,序列從上次記憶體中最大的序列號+1 開始存入cache x個

常用的Sql 函式

常用的sql函式 1 replace函式,替換字元。語法replace original string,search string,replace string 第乙個引數你的字串,第二個引數你想替換的部分,第三個引數你要替換成什麼 select replace helloword h a 輸出 a...

SQL常用函式

新建表 create table 表名 自動編號字段 int identity 1,1 primary key 欄位1 nvarchar 50 default 預設值 null 欄位2 ntext null 欄位3 datetime,欄位4 money null 欄位5 int default 0,...

sql常用函式

格式 cast expression as data type 該函式主要用於字段型別轉換 select cast id as int from table 格式 mod nexp1,nexp2 如查詢欄位id對5取余為1的資料 select from table where mod id,5 1 ...