oracle使用筆記

2021-09-18 05:48:26 字數 1109 閱讀 5400

一.判斷某個欄位是另外的值的時候,返回另外的值

decode函式

decode(value,if1,then1,if2,then2,if2,then2,..,else)

表示如果value等於if1時,decode函式的結果返回then1,...,如果不等於任何乙個if值,則返回else。

參考文章:

二. oracle開窗函式,mysql 語法;實現sql對一組資料排序之後取最大或者最小的數

在開發專案的時候遇到乙個邏輯,需要使用oracle開窗函式,通過對欄位1分組,找出欄位1對應的字段2下面的所有資料 然後進  行排序,取出最大或者最小的資料:

oracle: 

select p1,p2 from (

select p1,p2 row_number() over(partition by p1 order by p2 asc)  rn  from table

)  where rn = 1

mysql:

select p1,substring_index(group_concat(p2 order by p2 asc),',',1) as p2 from(

table  group by p1

) 注釋: (這個語法的意思是:取出p2欄位下對應的所有值,然後用逗號分隔,公升序排序,取出用逗號分隔的第乙個資料)

三.由於主鍵是利用序列自動增長的,所以在insert 之後 查詢出當前 id進行了

上**:

xml 配置: 

insert into shop_three_type_info (name,is_show,sort,parent_id,is_delete,create_time)     

values (#,#, 

#,#,#,

#)select shop_three_type_info_seq.currval as id from dual  

後台:執行插入操作之後

threetypeinfo.getid() 就ok了。

查詢系統資料、運維:

資料庫設計三大正規化

Oracle 使用筆記

原理 for each row r a in table a outer table for each rowr bintable b inner table ifr ajoin withr bthen return r a r b 適用範圍 a.outer table很小 or b.inner t...

oracle使用筆記

1 scott解鎖 alter user scott identified by tiger alter user scott account unlock 2 導表 d oracle table.sql 3 檢視表結構 desc table 4 連線資料 hello world 5 去重 dist...

Oracle使用筆記

1.nvl 函式 lnv val,rep val if val 字段值 null 返回 rep val 例 user表 id name age 1 atimo 18 2 null 20 select nvl name,sys name from user where id 2 結果 sys name...