儘量用簡單的SQL替代PL/SQL邏輯
可以將很多複雜的結果集先用WITH的別名定義起來,方便後續呼叫。
點選(此處)摺疊或開啟
-
drop table t;
-
drop table t1;
-
drop table t2;
-
drop table t3;
-
CREATE TABLE t AS SELECT object_id, object_name FROM dba_objects;
-
CREATE TABLE t1 AS SELECT object_id, object_name FROM dba_objects WHERE 1 = 2;
-
CREATE TABLE t2 AS SELECT object_id FROM t1;
-
CREATE TABLE t3 AS SELECT object_name FROM t1;
-
-
EXECUTE runstats_pkg.rs_start;
-
INSERT ALL
-
WHEN object_id > 5 THEN INTO t1 VALUES(object_id, object_name)
-
WHEN object_id <> 2 THEN INTO t2 VALUES(object_id)
-
ELSE INTO t3 VALUES(object_name)
-
SELECT object_id, object_name FROM t;
-
-
EXECUTE runstats_pkg.rs_middle;
-
-
--用自己的邏輯實現插入
-
BEGIN
-
INSERT INTO t1 SELECT object_id, object_name FROM t WHERE object_id > 5;
-
INSERT INTO t2 SELECT object_id FROM t WHERE object_id <> 2;
-
INSERT INTO t3 SELECT object_name FROM t WHERE object_id <= 5 AND object_id = 2;
-
COMMIT;
-
END;
-
/
-
-
EXECUTE runstats_pkg.rs_stop(1000);
-
-
Run1 ran in 2265hsec
-
Run2 ran in 2270hsec
- run 1 ran in 99.78% of the time
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17013648/viewspace-1072074/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 儘量使用簡單的sqlSQL
- 用pl/sql替代JavaSQLJava
- pl/sql中的forall簡單測試SQL
- 高效的SQL(清晰的邏輯重構業務SQL)SQL
- Oracle PL/SQL塊簡介OracleSQL
- 用PL/SQL建立包SQL
- PL/SQL初學者必讀:幾十個實用的PL/SQL (轉)SQL
- PL/SQL中繫結變數使用的簡單測試SQL變數
- SQL限制條件應儘量避免使用SYSDATESQL
- 【SQL 優化】異常的邏輯讀SQL優化
- PLSQL Language Reference-PL/SQL語言基礎-表示式-邏輯操作符SQL
- PL/SQL Case when應用SQL
- PL/SQLSQL
- SQL&PL/SQL (轉)SQL
- 單條SQL語句實現複雜邏輯幾例~~SQL
- sql生成可讀性邏輯圖SQL
- sql優化之邏輯優化SQL優化
- SQL限制條件應儘量避免使用SYSDATE(二)SQL
- [TEAP早期試讀]在資料庫中使用PL/SQL實現業務邏輯的優勢資料庫SQL
- 【SQL/PLUS】Oracle PL/SQL程式設計用set serveroutput onSQLOracle程式設計Server
- T-SQL、Jet SQL、PL-SQL 的含義SQL
- 邏輯有點難理解的Sql執行結果,以及用處SQL
- PL/SQL 宣告SQL
- PL/SQL cursorSQL
- PL/SQL打包SQL
- PL/SQL DEVSQLdev
- Oracle PL/SQLOracleSQL
- PLSQL Language Reference-PL/SQL概覽-PL/SQL的優點SQL
- Oracle PL/SQL編寫PL/SQL程式碼的注意事項OracleSQL
- MySQL之SQL邏輯查詢順序MySql
- 單條SQL語句實現複雜邏輯的幾個例子(1)SQL
- 單條SQL語句實現複雜邏輯的幾個例子(2)SQL
- 單條SQL語句實現複雜邏輯的幾個例子(3)SQL
- 單條SQL語句實現複雜邏輯的幾個例子(4)SQL
- 單條SQL語句實現複雜邏輯的幾個例子(5)SQL
- PLSQL Language Reference-PL/SQL語言基礎-詞彙單元-字面量SQL
- sql語句中較為重要的查詢邏輯SQL
- PL/SQL解數獨在簡單優化基礎上的改進SQL優化