SQL Document
SQL Document
=====
An index is a database structure that provides quick lookup of data in a column or
columns of a table.
B-Tree Index is the default Oracle index created whenever we use the CREATE INDEX
command
Function-Based Index.
Bitmap Index is an index type used in scenarios with repetitive values
The VARCHAR datatype is an ANSI standard data type, which is why it is included in
Oracle. The maximum length of a CHAR value is 4000 bytes.
DROP: DDL COMMAND, TOTAL TABLE WILL DROP AND DATA ALSO WILL DELETE.
NVL2: If expr1 is null, then NVL2 returns expr3. If expr1 is not null, then NVL2
returns expr2
The session-specific rows in a GTT can be preserved for the entire session, tables
are created using ON COMMIT PRESERVE ROWS clause.
A table can have more than one unique key unlike primary key. Unique key
constraints can allow NULL values. Unique constraints are also referenced by the
foreign key of another table.
SUB QUERY AND CO RELATED SUB QUERY When a query is included inside another query,
the Outer query is known as Main Query, and Inner query is known as Subquery.
In Correlated Query,
=================
Outer query executes first and for every Outer query row Inner query is executed.
Hence, Inner query uses values from Outer query.
JOINS Oracle JOINS are used to retrieve data from multiple tables. An Oracle JOIN
is performed whenever two or more tables are joined in a SQL statement.
REF CURSOR:
It’s a dynamic cursor to change sql statement dynamically at run time.
example: will change columns, where clause, order by clause and tables also.
we need to declare a variable and build sql query and assign to variable
and execute that variable using ref cursor data type.
Materialized views
=================
are the snap shots. Materialized views are also a logical virtual table, but in
this case the result of the query is stored in the table. The performance of the
materialized views is better than normal views. This is because the data is stored
on the TABLE SPACE
PERFORMANCE TUNING
=================
IN SQL DEVELOPER , will get explain plan.
i will check table scan and cost of query
and will check whether it’s an index scan or full table scan
and check cardinality
second method
=============
i will generate trace file by checking check box calleD "trace"
and run the program
will get trace file and using command tk prof will convert to readable format
and will come to know which sql query is taking lot of time
and will tune that query
Certain index is more selective for certain queries. Based on this information, WE
might be able to choose a more efficient execution plan than the optimizer. In such
a case, use hints to force the optimizer to use the optimal execution plan.
example:
Global hints:rule, first_rows, first_rows_n all_rows, driving_site
Table join hints: use_nl, use_hash
Index hints: Specifies an index name
Table access hints: parallel, full, cardinality
Table join hints: ordered
SET OPERATORS UNION is used to combine the results of two or more SELECT
statements. However, it will eliminate duplicate rows from its result set. In case
of union, number of columns and datatype must be same in both the tables, on which
UNION operation is being applied.
UNION ALL: This operation is similar to Union. But it also shows the duplicate
rows.
Intersect operation is used to combine two SELECT statements, but it only returns
the records which are common from both SELECT statements.
The Minus operation combines results of two SELECT statements and return only those
in the final result, which belongs to the first set of the result.
Implicit and explicit cursors Implicit cursors are automatically created when
select statements are executed.
They are capable of fetching a single row at a time.
Closes automatically after execution.