Tuesday, June 2, 2015

SQL Learning

The lexical ordering is:

SELECT [ DISTINCT ]
FROM
WHERE
GROUP BY
HAVING
UNION
ORDER BY

For simplicity, not all SQL clauses are listed. This lexical ordering differs fundamentally from the logical order, i.e. from the order of execution:

FROM
WHERE
GROUP BY
HAVING
SELECT
DISTINCT
UNION
ORDER BY

Now you know why the following occurs:

SELECT A.x + A.y AS z
FROM A
WHERE z = 10 -- z is not available here!

Much more at http://tech.pro/tutorial/1555/10-easy-steps-to-a-complete-understanding-of-sql

An excellent explanation of how B-tree indexes work at http://www.orafaq.com/node/1403

SQL Plus window settings

A lot of the commands related to the login.sql for the sqlplus are mentioned in the link http://stackoverflow.com/questions/1439203/favorite-sqlplus-tips-and-tricks

Basic SQL


1. By default, Oracle sorts using a binary sort order.
ex:
Russell
SMITH
Sarchand
Sciarra

alter session set NLS_SORT='BINARY_CI'
The above statement would be able to enforce case insensitivity when sorting

2. alter session set NLS_COMP='LINGUISTIC';
This statement would enable Oracle's linguistic comparison capability which enforce case insensitivity in the where clause

3. Use ROLLUP and CUBE functions to aggregate data at multiple levels