Explain Query Is Not Working in Oracle Db
I Use the Following Query in Mysql and It Works Fine: Explain Select Count(Userid) from Tableone Where Userid='Abc' I Tried the Same in Oracle but I Get the...
I use the following query in MySQL and it works fine:
explain SELECT COUNT(userid) FROM tableone where userid='abc'
I tried the same in Oracle but I get the following error:
SQL Error [905] [42000]: ORA-00905: missing keyword
ORA-00905: missing keyword
When I execute explain query in mysql it result type,possible_keys,key,key_len,ref etc.... how can i get that result from oracle
1 Answer
explain SELECT COUNT(userid) FROM tableone where userid='abc'
That is syntactically incorrect in Oracle. the correct syntax is:
EXPLAIN PLAN FOR sql_statement;
See How to create and display explain plan in Oracle.
For example,
SQL> EXPLAIN PLAN FOR SELECT * FROM EMP;
Explained.
SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------
Plan hash value: 3956160932
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 518 | 4 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMP | 14 | 518 | 4 (0)| 00:00:01 |
--------------------------------------------------------------------------
8 rows selected.
Alternatively, you could achieve the same in SQL*Plus:
SQL> set autot on explain
SQL> SELECT empno FROM emp;
EMPNO
----------
7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934
14 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 56 | 4 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMP | 14 | 56 | 4 (0)| 00:00:01 |
--------------------------------------------------------------------------