orcale關鍵字的用法(個人總結)

2021-09-26 04:18:17 字數 2585 閱讀 4736

exists用於檢查子查詢是否至少會返回一行資料,該子查詢實際上並不返回任何資料,而是返回值true或false

exists 指定乙個子查詢,檢測 行 的存在。

not exists 的作用與 exists 正好相反。如果子查詢沒有返回行,則滿足了 not exists 中的 where 子句。

例:select * from 表名 where exists(select null)  等同於: select * from 表名

(1)用於將已知欄位換做另一種表達形式

select   case ***  when '1' then '男' when '2' then '女' else '其他' end  from student或   select   case   when   ***='1' then '男'   when ***='2' then '女'  else  '其他'  end  from student

(2)完成不同條件分組

select sum(population),

case country when '中國' then '亞洲'

when '印度' then '亞洲'

when '日本' then '亞洲'

when '美國' then '北美洲'

when '加拿大' then '北美洲'

when '墨西哥' then '北美洲'

else '其他' end from table_a group by

case country when '中國' then '亞洲'

when '印度' then '亞洲'

when '日本' then '亞洲'

when '美國' then '北美洲'

when '加拿大' then '北美洲'

when '墨西哥' then '北美洲'

else '其他' end;

(3)根據所定條件去更改資料

update person  set salary = salary * 1.2 where salary >= 5000;(員工5000以上的漲百分之二十工資)

distinct跟在select後面,代表去除重複的,這個重複是整體重複的。 select 子句後面指定要查詢的列 from 後面跟要查詢的表 

在oracle資料庫內有一種特殊的表dual。dual表是oracle中的乙個實際存在的表,任何使用者均可讀取,常用在沒有目標表的select中。dual表由oracle連同資料字典一同建立,所有的使用者都可以用名稱dual訪問該錶。這個表裡只有一列dummy,該列定義為varchar2(1)型別,有一行值x。從dual表選擇資料常被用來通過select語句計算常數表示式,由於dual只有一行資料,所以常數只返回一次。

查詢當前系統時間

select sysdate from dual

語法:round(number,digits)

引數:number,要四捨五入的數,digits是要小數點後保留的位數

如果 digits 大於 0,則四捨五入到指定的小數字。 

如果 digits 等於 0,則四捨五入到最接近的整數。 

如果 digits 小於 0,則在小數點左側進行四捨五入。

如果round函式只有引數number,等同於digits 等於 0。

返回值:

四捨五入後的值

舉例:round(3.1415926,2)=3.14;

round(3.1415926,3)=3.142;

select round(193,-2)from dual; 200

select round(193,-1)from dual;190

select round(193,-3)from dual;0

返回值:

如果第乙個引數 非空, 那麼直接返回第乙個引數, 忽略第二個引數。

如果第乙個引數 是 空( is null), 那麼返回第二個引數。

使用with as 提高效能巢狀

簡單來說定義一張臨時表來填充需求資料,在去查詢一定條件的資料

with

a as

select countryregioncode from person.countryregion where name like '李%'

select * from person.stateprovince where countryregioncode in (select * from a)

要新增字元靠近列名的那一邊需要加||,並且要新增的字串需要用單引號 

select 『找到的id為:』||id||』 找到的名字為』||last_name as name from s_emp; 

select upper('daxie') from dual  ;輸出結果daxie

select  initcap(hello) from dual ;輸出結果  hello

select concat ('supper','man') from dual ;輸出結果supperman

select substr('hellworld',n,m) from dual 

從n字元開始擷取後m位字元

select length('helloworld') from dual:輸出結果10

golang中的select關鍵字用法總結

1.官方解釋 乙個select語句用來選擇哪個case中的傳送或接收操作可以被立即執行。它類似於switch語句,但是它的case涉及到channel有關的i o操作。即select就是用來監聽和channel有關的io操作,當 io 操作發生時,觸發相應的動作。2.要點 如果有乙個或多個io操作可...

Java 關鍵字 synchronized 總結

android 學習計畫 第一周 同一程序的多個執行緒共享同一片儲存空間,因此當多個執行緒同時訪問同乙個資料時,會造成訪問衝突。public synchronized void start public static synchronized void start 普通函式 public void ...

關鍵字的用法 C 中const關鍵字用法總結

ark2000 看完了c primer的基礎篇,對const還是有點陌生,在這裡小小地總結一下吧。在變數的定義前加上const修飾符即可完成const物件的建立。const int val 5 const變數的值不能改變。val 5 error assignment of read only var...