全部博文(136)
分类: Oracle
2008-05-14 14:25:33
SQL> SELECT w.event, SQL_TEXT EVENT SQL_TEXT |
SELECT SUM(A) FROM (SELECT COUNT(1) A FROM KC03 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1' UNION ALL SELECT COUNT(1) A FROM JC01 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1' UNION ALL SELECT COUNT(1) A FROM LC09 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1' UNION ALL SELECT COUNT(1) A FROM MC03 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1' UNION ALL SELECT COUNT(1) A FROM IC01 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1') |
SQL> explain plan for 2 SELECT SUM(A) FROM ( SELECT COUNT(1) A FROM KC03 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1' UNION ALL SELECT COUNT(1) A FROM JC01 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1' UNION ALL SELECT COUNT(1) A FROM LC09 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1' UNION ALL SELECT COUNT(1) A FROM MC03 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1' UNION ALL SELECT COUNT(1) A FROM IC01 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1') 3 ; 已解释。 SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------ ------------------------------------------------------------------------ | Id | Operation | Name |Rows|Bytes|Cost| ------------------------------------------------------------------------ | 0 |SELECT STATEMENT | | 1 | 13 | 26 | | 1 | SORT AGGREGATE | | 1 | 13 | | | 2 | VIEW | | 5 | 65 | 26 | | 3 | UNION-ALL | | | | | | 4 | SORT AGGREGATE | | 1 | 23 | | | 5 | INDEX RANGE SCAN | IND_KC03 | 1 | 23 | 3 | | 6 | SORT AGGREGATE | | 1 | 23 | | | 7 | INDEX RANGE SCAN | PK_JC01 | 1 | 23 | 3 | | 8 | SORT AGGREGATE | | 1 | 23 | | | 9 | TABLE ACCESS BY INDEX ROWID| LC09 | 1 | 23 | 16 | | 10 | INDEX RANGE SCAN | INX_LC09 |13 | | 3 | | 11 | SORT AGGREGATE | | 1 | 20 | | | 12 | INDEX SKIP SCAN | PK_MC03 | 1 | 20 | 0 | | 13 | SORT AGGREGATE | | 1 | 23 | | | 14 | INDEX RANGE SCAN | PK_IC01 | 1 | 23 | 4 | ------------------------------------------------------------------------ Note PLAN_TABLE_OUTPUT ---------------------------------- - 'PLAN_TABLE' is old version 已选择24行。 SQL> |
SELECT SUM(A) INTO n_count FROM ... IF n_count > 0 then ... END IF;
|
SELECT 1 FROM DUAL WHERE EXISTS (SELECT 1 FROM IC01 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1') OR EXISTS (SELECT 1 FROM KC03 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1') OR EXISTS (SELECT 1 FROM LC09 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1') OR EXISTS (SELECT 1 FROM JC01 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1') OR EXISTS (SELECT 1 FROM MC03 WHERE AAC001 = :B2 AND AAE003 = :B1 AND AAE143 = '1') |
n_index_aac001_exists number(10); type type_aac001_exists is table of ac01.aac001%type index by pls_integer; t_aac001_exists type_aac001_exists; |
n_index_aac001_exists := n_index_aac001_exists + 1; t_aac001_exists(n_index_aac001_exists) := rec_ic01.aac001; END FOR rec_KC03 IN( SELECT aac001 FROM KC03 WHERE aab001 = prm_aab001 AND aae003 = prm_aae002 and aae143 = '1' ) LOOP n_index_aac001_exists := n_index_aac001_exists + 1; t_aac001_exists(n_index_aac001_exists) := rec_KC03.aac001; END FOR rec_JC01 IN( SELECT aac001 FROM JC01 WHERE aab001 = prm_aab001 AND aae003 = prm_aae002 and aae143 = '1' ) LOOP n_index_aac001_exists := n_index_aac001_exists + 1; t_aac001_exists(n_index_aac001_exists) := rec_JC01.aac001; END FOR rec_LC09 IN( SELECT aac001 FROM LC09 WHERE aab001 = prm_aab001 AND aae003 = prm_aae002 and aae143 = '1' ) LOOP n_index_aac001_exists := n_index_aac001_exists + 1; t_aac001_exists(n_index_aac001_exists) := rec_LC09.aac001; END FOR rec_MC03 IN( SELECT aac001 FROM MC03 WHERE aab001 = prm_aab001 AND aae003 = prm_aae002 and aae143 = '1' ) LOOP n_index_aac001_exists := n_index_aac001_exists + 1; t_aac001_exists(n_index_aac001_exists) := rec_MC03.aac001; END |
IF t_aac001_exists.EXISTS(1) THEN FOR n_pointer IN t_aac001_exists.FIRST..t_aac001_exists.LAST IF v_aac001 = t_aac001_exists(n_pointer) THEN n_co := 1; EXIT; END IF; END ELSE n_co := 0; END IF; |