oracle中in與exist的用法與比較
最近在工作中用到oracle的in函式,但是該函式的引數個數存在上限(1000)的限制,而且涉及查詢的兩個表還在兩個不同的資料庫中,就無法使用exists函式來替代in的使用了。但還是總結一下in與exists的用法差異。
1.in適用於內表比外表資料量小的場景:select * from testA a where a.client_id in (select * from testB)。
原因:in方法下,oracle會執行兩個for迴圈遍歷,外迴圈次數為testA的資料,內迴圈次數為testB的資料。如果testB的資料量超過testA,很明顯執行效率會降低,只有testB的資料量小於testA時,才適合選擇in方法;
2.exists適用於內表資料多於外表的場景:select * from testA a where exists (select * from testB b where a.client_id=b.client_id)。
原因:exists方法下,oracle會執行外表和內表的遍歷查詢,外迴圈次數為testA的資料,內迴圈次數也是testA的資料量大小。所以當內表資料量小於外表時,採用in,內表資料量大於外表時,採用exists,內表等於外表時,兩者效能相當。
相關推薦
oracle中in與exist的用法與比較
最近在工作中用到oracle的in函式,但是該函式的引數個數存在上限(1000)的限制,而且涉及查詢的兩個表還在兩個不同的資料庫中,就無法使用exists函式來替代in的使用了。但還是總結一下in與exists的用法差異。 1.in適用於內表比外表資料量小的場景:select * from te
ORACLE 中in與exists語句的區別(一)
select * from A where id in(select id from B) 以上查詢使用了in語句,in()只執行一次,它查出B表中的所有id欄位並快取起來.之後,檢查A表的id是否與B表中的id相等,如果相等則將A表的記錄加入結果集中,直到遍歷完A表的所有
Oracle的substr函式簡單用法 與java中substring區別
substr(字串,擷取開始位置,擷取長度) //返回擷取的字 substr('Hello World',0,1) //返回結果為 'H' *從字串第一個字元開始擷取長度為1的字串 substr('Hello World',1,1) //返回結果為 'H' *0和1都是
js中slice、splice用法與區別
delet 內容 title pan ont 指定 至少 一個 拷貝 1.slice(start,end)(參數可選) slice() 方法返回一個從開始到結束(不包括結束)選擇的數組的一部分淺拷貝到一個新數組對象。原始數組不會被修改。 var a = [‘a‘, ‘b‘
Oracle中 in、exists、not in,not exists的比較
src inf .... blog pos str bug class exists 最基本的區別: in 對主表使用索引 exists 對子表使用索引 not in 不使用索引 not exists 對主子表都使用索引 寫法: exist的where條件是: "..
C語言中關鍵詞static的用法與作用域
細心 錯誤 不同 color 運行程序 可能 gpo 需要 之間 一、面向過程設計中的static 轉載:http://blog.csdn.net/celerylxq/article/details/6160499 1、靜態全局變量 在全局變量前,加上關鍵字stati
java調用Oracle中的存儲過程與存儲函數
div edr oid rac gist acl ble ava exception 1 //調用存儲過程 2 public static void testPro(){ 3 String driver = "oracle.jdbc.Orac
Oracle Decode函式的簡單用法與個人理解
Oracle Decode函式的簡單用法 個人的簡單理解 舉例說明 個人的簡單理解 本人在嘗試用了之後發現,decode的用法其實與Excel中IF的用法類似 decode(條件,值1,返回值1,值2,返回值2,…值n,返回
Oracle中自動生成的guid與.Net中的guid的互動
最近在做一個T1的.NET專案,資料庫oracle的時候,遇到一個問題。.NET裡面的某個資料庫表類的某個欄位是guid型別。但是用oracle生成的guid。跟.NET的guid 無法識別。導致報錯。資料顯示不了。經過查資料,網上好像很少是專門去說明這個問題的部落格,後來
Oracle 中MERGE語句的用法(轉載)
同時 sdn ble reat nth merge type href detail 原文章出處(http://blog.csdn.net/lichkui/article/details/4306299) MERGE語句是Oracle9i新增的語法,用來合並UPDATE和I
oracle中 merge into 的用法
大數據 char 條件 http -1 alt mat 一個表 dml語句 很多時候我們需要通過篩選條件同時對表進行 更新,插入,刪除 等操作。這樣如果我們單一的去操作表會顯得很麻煩,下面會說到這個merge into 的用法會極大的優化我們操作表的時間和代碼量。 舉例,
Oracle 中 decode 函數用法
個數 依次 elsif 根據 sql nbsp htm 開發 ret 含義解釋: decode(條件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 該函數的含義如下:IF 條件=值1 THEN RETURN(翻譯值1)ELSIF 條件=值2 THEN
sql中in和exist語句的區別?(補充了left join和right join)
有用 表數 from 部分匹配 exist 循環 targe 從表 exists in和exists(摘錄自百度)in 是把外表和內表作hash 連接,而exists是對外表作loop循環,每次loop循環再對內表進行查詢。如果兩個表中一個較小,一個是大表,則子查詢表大的用
Oracle中add_months()函式的用法
查詢當前時間1個月以前的時間: select add_months(sysdate,-1) from dual; 查詢當前時間1個月以後的時間: select add_months(sysdate,1) from dual; 如對公司員工表:查詢2年前進入公司的員工的姓
oracle中的substr() instr() 用法
原文章:https://www.cnblogs.com/miaoying/p/5784947.html點選開啟連結 --substr(字串,擷取開始位置,擷取長度)=返回擷取的字 select substr('miaoying',0,1) from dual;--返回結果為:m select
oracle中add_months和trunc用法
oracle中add_months和trunc用法 2012-06-13 13:45 646人閱讀 評論(0) 收藏 舉報 oracle date sql 工作
oracle 中start with 的用法
oracle 提供了start wit h c onnect by 語法結構可以實現遞迴查詢。 1. 一個簡單舉例: SQL> select * from test; BILL_MONTH &
ORACLE中部分函式的用法
select decode(sign(salary - 8000),1,salary*1.15,-1,salary*1.2,salary from employee DECODE的語法:DECODE(value,if1,then1,if2,then2,if3,then3,…,else)
oracle中臨時表的用法詳解
1、前言 目前所有使用Oracle作為資料庫支撐平臺的應用,大部分資料量比較龐大的系統,即表的資料量一般情況下都是在百萬級以上的資料量。 當然在Oracle中建立分割槽是一種不錯的選擇,但是當你發現你的應用有多張表關聯的時候,並且這些表大部分都是比較龐大,而你關聯的時候發現其中的某一張或者某
ORACLE 中merge....into的用法簡單瞭解一下
MERGE INTO [target-table] A USING [source-table sql] B ON([conditional expression] and […]…) WHEN MATCHED THEN [UPDATE sql] WHEN NO