Professional Documents
Culture Documents
SQL Coding Standard
SQL Coding Standard
Selected rows:
Avoid using SELECT * FROM table. Define the column names instead.
Duplicate rows:
Avoid using DISTINCT if you can tolerate having duplicate rows returned by a query.
Outer join:
Review the use, especially outer joins should not be required between a child and master table.
Don't mix LEFT and RIGHT OUTER JOIN in the same query.
Use SELECT... BULK COLLECT INTO ... FROM ... only when you are sure that the result set
will be of a reasonable size, otherwise, use an explicit cursor and fetch with the LIMIT clause.
Search limiting:
Use rownum to limit search after finding "n" rows
Views:
Don’t use views unless you require all the tables of the view in the query. Use base tables
instead, if you just need to access a few columns/tables only.
Upper:
Don’t use upper on columns which are indexed. If these are indexed, then upper will not enable
index to be used.
Wild card:
Use this only in cases where required, don’t use LIKE without a wild card character. Don’t use it
to compare full value supplied.
Procedural logic:
Long running sqls and code must be developed as pl/sql codes don’t write a single query which
runs for long time.
Conditional retrieval:
Don’t use nested selects, instead embed such logic in pl/sql, so that if...then...else conditions
can be used and access can be optimized.
Datatype:
Respect the data type stored in the table, don’t do too many conversions in the query (for
example char to number, date to char etc..).