Saturday, September 4, 2010

DBMS_OUTPUT in Oracle

Oracle built in with a set of built-in packaged procedures that provide a wealth of functionality for DBA's and developers.

DBMS_OUTPUT

You can use this standard packaged procedure to write messaged to the buffer area and later retrieve those messages.
One of the remarkable usage of this packaged procedure is it capability to display the buffer to your screen if you are using SQLDBA or SQLPLUS.

DBMS_OUTPUT.PUT_LINE(message varchar2);

This procedure is used to Write a message to the session's buffer. You can invoke DBMS_OUTPUT.PUT_LINE(message). either within a PL/SQL block or directly from SQL prompt.

DBMS_OUTPUT.GET_LINE( Message out Varchar2 , Status out integer)
Once this procedure is executed it will return the buffer line into the (Message) variable and will return the Status into the (Status) variable. If a line of information is found in the buffer, the procedure will return a zero in the Status variable, otherwise status is <> 0

What is ROWID in Oracle?

The ROWID is a unique database-wide physical address for every row on every table. Once assigned (when the row is first inserted into the database), it never changes until the row is deleted or the table is dropped.

The ROWID consists of the following three components, the combination of which uniquely identifies the physical storage location of the row.

* Oracle database file number, which contains the block with the rows
* Oracle block address, which contains the row
* The row within the block (because each block can hold many rows)

The ROWID is used internally in indexes as a quick means of retrieving rows with a particular key value. Application developers also use it in SQL statements as a quick way to access a row once they know the ROWID

Saturday, July 31, 2010

Partitioning in Oracle

Partitioning enables tables and indexes or index-organized tables to be subdivided into smaller manageable pieces and these each small piece is called a partition. From an Application Development perspective, there is no difference between a partitioned and a non-partitioned table. The application need not be modified to access a partitioned table if that application was initially written on a non partitioned tables.

Oracle introduced partitioning like Range Partitioning, Hash Partitioning, Composite Partitioning, List Partitioning,etc. Each method of partitioning has its own advantages and disadvantages and the decision which one to use will depend on the data and type of application. Also one can MODIFY, RENAME, MOVE, ADD, DROP, TRUNCATE, SPLIT partitions.

Advantages of using Partition’s in Table

1. Smaller and more manageable pieces of data (Partitions)
2. Reduced recovery time
3. Failure impact is less
4. Import / Export can be done at the Partition Level.
5. Faster access of data
6. Partitions work independent of the other partitions.
7. Very easy to use

What is SQL*Loader and why it is used for?

SQL*Loader is a bulk loader utility used for moving data from external files into the Oracle database. Its syntax is similar to that of the DB2 Load utility, but comes with more options. SQL*Loader supports various load formats, selective loading, and multi-table loads.

One can load data into an Oracle database by using the sqlldr utility. Invoke the utility without arguments to get a list of available parameters.

Faster SQL performance with dbms_stats

While executing a SQL Query, the execution plan determines the best way to retrieve the data most efficiently. For Oracle, there are many way to retrieve the data from a SQL Query, like which index need to be use, order of joins to be performed and which internal join methods to be use like, hash joins, star joins, and sort merge join, etc. These execution plans are computed by the Oracle’s Cost-Based Optimizer, widely known as CBO.

The choice of executions plans made by the Oracle SQL Optimizer is only as good as the Oracle statistics. Always choose the best execution plan for a SQL query, Oracle depends on information about the tables and indexes in the query.

Using dbms_stats package, Oracle provides a simple way for the Oracle developer to collect statistics for the CBO. The dbms_stats utility does a far better job in estimating statistics, especially for large partitioned tables, and the better stats results in faster SQL execution plans.

The old-fashioned method is Analyzing a table and using methods of dbms_utility to generating CBO statistics are obsolete and somewhat dangerous to SQL performance because they don't always capture high-quality information about tables and indexes. The CBO determines using the the object statistics to choose the best execution plan for all SQL Queries.

The dbms_stats utility does a far better job in estimating statistics, especially for large partitioned tables, and the better stats result in faster SQL execution plans.

Tuesday, December 15, 2009

What is the difference between table & View?

View is a virtual table made of one or tables of the database using complex/simple join logic. The view has some useful purposes. Some are as under:

1. Simplification of database:

A schema may have hundreds of tables. Applications can be simplified if they can access predefined views which embed complex join logic.

2. Easy Maintenance:

Views can contain complex column expressions that are transparent in the views. Changes to these expressions need only be made in the view.

3. Change management:

Views can reduce maintenance to the application as they can hide schema changes that affect the view's query.

4. Security purpose:

Views can embed selection logic and present a subset of a table's content. You can create additional schema that contains just views of the main schema, limiting what may be accessed. Different user groups enter through one of these other schema, each group having a different view of the overall database.

Monday, December 14, 2009

How to free up database space in Tablespace in Oracle?

Oracle uses the high-water mark after deleted rows in database, you can free up this space at the table level with following methods.

1 . using export/import of table -

For a complete restructuring of table and space freeing up export/import of a table allows us to restructure our files and release the lost space.

2. using dbms_redefinition -

This procedure will reorganize a table while it remains online for updates.

3. using alter table tmp shrink -

If you are using Oracle 10g and later, you could use
alter table tmp shrink space compact.

4. using coalesing table -


It removes space above the high-water mark, It puts together the uncontiguous fragmented extents.

The honeycomb fragmentation and Swiss Cheese fragmentation are mainly occured in oracle. When the free extents are side by side, its in honeycomb fragmentation, and when the extents are separated by live segments, its in Swiss Cheese fragmentation.

alter table tmp coalesce;

5. using deallocate unused space -

Oracle uses it to explicitly deallocate unused space at the end of a segment and makes that space available for other segments within the tablespace.

alter table tmp deallocate unused space;

Oracle deallocates unused space beginning from the end of the objects and moving downwards toward the beginning of the object, continuing down until it reaches the high water mark (HWM). For indexes, deallocate unused space coalesces all leaf blocks within same branch of b-tree, and quickly frees up index leaf blocks for use.