Sunteți pe pagina 1din 19

Questions Page

1. Difference between trigger and procedure?


2. Difference between procedure and package
3. What triggers are triggered when performed delete, truncate, drop
4. Scalar data types, composite datatypes, reference, Large objects
5. Disadvantages of views.
6. Disadvantages of no copy hint
7. Advantages and disadvantages of parallel hint.
1. Why parallel ?
2. We can gather statistics of table ..if giving auto cascade it gathers stats of
index as well.

exec dbms_stats.gather_table_stats('SCOTT', 'EMP', cascade =>


DBMS_STATS.AUTO_CASCADE);

3. Index skip scan


4. disadvantages od bitmap indexing
5. Different types of scans
6. What are the types of joins that are seen in explain plan?
7. Advantages and disadvantages of hash joins, sort merge joins, nested
loop joins.
8. Difference between above joins.
9. Pseudo code for above joins, algorithm
10. Autonomous transaction
11. Types of triggers, when truncate happens, which trigger does trigger?
12.

Explain the difference between trigger and stored procedure.


- A stored procedure can accept parameters while a trigger cannot.
- A trigger can’t return any value while stored procedures can.
- A trigger is executed automatically on some event while a stored procedure needs to be explicitly called.
- Triggers are used for insertions, update and deletions on tables while stored procedures are often using
independently in the database.
- A trigger cannot be written in a stored procedure. However, the reverse is not possible.
Within a namespace, no two objects can have the same name.

The following schema objects share one namespace:

Tables
Views
Sequences
Private synonyms
Stand-alone procedures
Stand-alone stored functions
Packages
Materialized views
User-defined types
User-defined operators
Each of the following schema objects has its own namespace:

Indexes
Constraints
Clusters
Database triggers
Private database links
Dimensions
Because tables and views are in the same namespace, a table and a view in the same
schema cannot have the same name. However, tables and indexes are in different
namespaces. Therefore, a table and an index in the same schema can have the same name.

Each schema in the database has its own namespaces for the objects it contains. This
means, for example, that two tables in different schemas are in different namespaces and can
have the same name.

Each of the following nonschema objects also has its own namespace:

User roles
Public synonyms
Public database links
Tablespaces
Profiles
Parameter files (PFILEs) and server parameter files (SPFILEs)
Editions
Because the objects in these namespaces are not contained in schemas, these namespaces
span the entire database.

How do you log errors on merge statement?


*****************Join Optimizations

This section describes common join optimizations:

************** Bloom Filters


************** Partition-Wise Joins

Burton Bloom, is a low-memory data structure that tests membership in a set.

Purpose of Bloom Filters


A Bloom filter tests one set of values to determine whether they are members another set, for
example, set (10,20,30,40) and set (10,30,60,70). The filter determines that 60 and 70 are
guaranteed not to be members of the first set, and that 10 and 30 are probably members.

Oracle Database uses Bloom filters to various specific goals, including the following:

Reduce the amount of data transferred to slave processes in a parallel query, especially when
the database discards most rows because they do not fulfill a join condition

Eliminate unneeded partitions when building a partition access list in a join, known as partition
pruning

Test whether data exists in the server result cache, thereby avoiding a disk read

Filter members in Exadata cells, especially when joining a large fact table and small
dimension tables in a star schema

-----------------------------------------------------------------------------------------------------------
****Partition-Wise Joins
A partition-wise join is a join optimization that divides a large join of two tables, one of which
must be partitioned on the join key, into several smaller joins. Partition-wise joins are either of
the following:

Full partition-wise join

Both tables must be equipartitioned on their join keys, or use reference partitioning (that is, be
related by referential constraints). The database divides a large join into smaller joins
between two partitions from the two joined tables.

Partial partition-wise joins

Only one table is partitioned on the join key. The other table may or may not be partitioned.

Partitioning an Existing Table using DBMS_REDEFINITION

Logical Database Limits

Order of Execution of sql query

FROM
ON
JOIN
WHERE
GROUP BY
WITH CUBE or WITH ROLLUP
HAVING
SELECT
DISTINCT
ORDER BY
TOP
Skip rows with duplicate primary key or unique values

use hint /*+ IGNORE_ROW_ON_DUPKEY_INDEX (t (id)) */

BEGIN
FOR i in 1 ..7
loop
insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX (t (id)) */ into t(id) values (i);
end loop;
commit;
end;
/

Excecution time of a procedure

QL> declare
2 t1 pls_integer;
3 begin
4 t1 := dbms_utility.get_time;
5 p;
6 dbms_output.put_line((dbms_utility.get_time - t1)/100 || ' seconds');
7 end;
8 /
5 seconds

PL/SQL procedure successfully completed.


----------------------------------------------------------------------------------------------------------
-

Pipelined Table Functions

Pipelining negates the need to build huge collections by piping rows out of the
function as they are created, saving memory and allowing subsequent
processing to start before all the rows are generated.
SELECT employee_id, last_name
BULK COLLECT INTO enums, names
FROM employees
ORDER BY employee_id;

how rownum works example

http://www.oracle.com/technetwork/issue-archive/2006/06-sep/o56asktom-
086197.html

How ROWNUM Works


ROWNUM is a pseudocolumn (not a real column) that is available in a query.
ROWNUM will be assigned the numbers 1, 2, 3, 4, ... N , where N is the number
of rows in the set ROWNUM is used with. A ROWNUM value is not assigned
permanently to a row (this is a common misconception). A row in a table does
not have a number; you cannot ask for row 5 from a table—there is no such
thing.

Also confusing to many people is when a ROWNUM value is actually assigned.


A ROWNUM value is assigned to a row after it passes the predicate phase of
the query but before the query does any sorting or aggregation. Also, a
ROWNUM value is incremented only after it is assigned, which is why the
following query will never return a row:

select *
from t
where ROWNUM > 1;

select ..., ROWNUM


from t
where <where clause>
group by <columns>
having <having clause>
order by <columns>;

Think of it as being processed in this order:

1. The FROM/WHERE clause goes first.


2. ROWNUM is assigned and incremented to each output row from the
FROM/WHERE clause.
3. SELECT is applied.
4. GROUP BY is applied.
5. HAVING is applied.
6. ORDER BY is applied.

That is why a query in the following form is almost certainly an error:

select *
from emp
where ROWNUM <= 5
order by sal desc;

select *
2 from
3 (select a.*, rownum rnum
4 from
5 (select id, data
6 from t
7 order by id, rowid) a
8 where rownum <= 151
9 )
10 where rnum >= 148;

ID DATA RNUM
------- ---------- -----------
0 45 148
0 99 149
0 41 150
0 45 151
Now the query is very deterministic. ROWID is unique within a table, so if you
use ORDER BY ID and then within ID you use ORDER BY ROWID, the rows
will have a definite, deterministic order and the pagination query will
deterministically return the rows as expected.

Pagination with ROWNUM


My all-time-favorite use of ROWNUM is pagination. In this case, I use
ROWNUM to get rows N through M of a result set. The general form is as
follows:

select *
from ( select /*+ FIRST_ROWS(n) */
a.*, ROWNUM rnum
from ( your_query_goes_here,
with order by ) a
where ROWNUM <=
:MAX_ROW_TO_FETCH )
where rnum >= :MIN_ROW_TO_FETCH;

where

FIRST_ROWS(N) tells the optimizer, "Hey, I'm interested in getting the first
rows, and I'll get N of them as fast as possible."

:MAX_ROW_TO_FETCH is set to the last row of the result set to fetch—if you
wanted rows 50 to 60 of the result set, you would set this to 60.

:MIN_ROW_TO_FETCH is set to the first row of the result set to fetch, so to get
rows 50 to 60, you would set this to 50.

q1. Why parallel ?


3. We can gather statistics of table ..if giving auto cascade it gathers stats of
index as well.

exec dbms_stats.gather_table_stats('SCOTT', 'EMP', cascade =>


DBMS_STATS.AUTO_CASCADE);
13. Index skip scan
14. disadvantages od bitmap indexing

DML Error Logging in Oracle 10g Database Release 2

-- Create the error logging table.


BEGIN
DBMS_ERRLOG.create_error_log (dml_table_name => 'dest');
END;
/

It creates a table named ERR$_DEST

INSERT /*+ APPEND */ INTO dest


SELECT *
FROM source
LOG ERRORS INTO err$_dest ('INSERT APPEND') REJECT LIMIT
UNLIMITED;

INSERT INTO dest


SELECT *
FROM source
LOG ERRORS INTO err$_dest ('INSERT NO-APPEND') REJECT LIMIT
UNLIMITED;

Logical Type of Indexes

S-ar putea să vă placă și