Codd
Codd
Codd
2) What is a mutating table error and how can you get around it?
This happens with triggers. It occurs because the trigger is trying to update a row it is
currently using. The usual fix involves either use of views or temporary tables so the
database is selecting from one while updating the other.
%ROWTYPE allows you to associate a variable with an entire table row. The %TYPE
associates a variable with a single column type.
4) What packages (if any) has Oracle provided for use by developers?
Oracle provides the DBMS_ series of packages. There are many which developers should
be aware of such as DBMS_SQL, DBMS_PIPE, DBMS_TRANSACTION,
DBMS_LOCK, DBMS_ALERT, DBMS_OUTPUT, DBMS_JOB, DBMS_UTILITY,
DBMS_DDL, UTL_FILE.
5). What are SQLCODE and SQLERRM and why are they important for PL/SQL
developers?
SQLCODE returns the value of the error number for the last error encountered. The
SQLERRM returns the actual error message for the last error encountered. They can be
used in exception handling to report, or, store in an error log table, the error that occurred
in the code. These are especially useful for the WHEN OTHERS exception.
There are 12 types of triggers in PL/SQL that consist of combinations of the BEFORE,
AFTER, ROW, TABLE, INSERT, UPDATE, DELETE and ALL key words:
BEFORE ALL ROW INSERT
AFTER ALL ROW INSERT
BEFORE INSERT
AFTER INSERT
By use of the & symbol. For passing in variables the numbers 1-8 can be used (&1,
&2,...,&8) to pass the values after the command into the SQLPLUS session. To be
prompted for a specific variable, place the ampersanded variable in the code itself:
A Cartesian product is the result of an unrestricted join of two or more tables. The result
set of a three table Cartesian product will have x * y * z number of rows where x, y, z
correspond to the number of rows in each table involved in the join.
-------------------------------------------
1. To see current user name
Sql> show user;
2. Change SQL prompt name
SQL> set sqlprompt “Manimara > “
Manimara >
Manimara >
3. Switch to DOS prompt
SQL> host
4. How do I eliminate the duplicate rows ?
SQL> delete from table_name where rowid not in (select max(rowid) from table group
by duplicate_values_field_name);
or
SQL> delete from table_name ta where rowid >(select min(rowid) from table_name tb
where ta.dv=tb.dv and .....);
Example.
Table Emp
Empno Ename
101 Scott
102 Jiyo
103 Millor
104 Jiyo
105 Smith
delete from emp a where rowid < ( select max(rowid) from emp b where a.ename =
b.ename );
The output like,
Empno Ename
101 Scott
103 Millor
104 Jiyo
105 Smith
5. How do I display row number with records?
To achive this use rownum pseudocolumn with query, like SQL> SQL> select rownum,
ename from emp;
Output:
1 Scott
2 Millor
3 Jiyo
4 Smith
6. Display the records between two range
select rownum, empno, ename from emp where rowid in
(select rowid from emp where rownum <=&upto
minus
select rowid from emp where rownum<&Start);
Enter value for upto: 10
Enter value for Start: 7
ROWNUM EMPNO ENAME
--------- --------- ----------
1 7782 CLARK
2 7788 SCOTT
3 7839 KING
4 7844 TURNER
7. I know the nvl function only allows the same data type(ie. number or char or date
Nvl(comm, 0)), if commission is null then the text “Not Applicable” want to display,
instead of blank space. How do I write the query?
SQL> select nvl(to_char(comm.),'NA') from emp;
Output :
NVL(TO_CHAR(COMM),'NA')
-----------------------
NA
300
500
NA
1400
NA
NA
8. Oracle cursor : Implicit & Explicit cursors
Oracle uses work areas called private SQL areas to create SQL statements.
PL/SQL construct to identify each and every work are used, is called as Cursor.
For SQL queries returning a single row, PL/SQL declares all implicit cursors.
For queries that returning more than one row, the cursor needs to be explicitly declared.
9. Explicit Cursor attributes
There are four cursor attributes used in Oracle
cursor_name%Found, cursor_name%NOTFOUND, cursor_name%ROWCOUNT,
cursor_name%ISOPEN
10. Implicit Cursor attributes
Same as explicit cursor but prefixed by the word SQL
SQL%Found, SQL%NOTFOUND, SQL%ROWCOUNT, SQL%ISOPEN
Tips : 1. Here SQL%ISOPEN is false, because oracle automatically closed the implicit
cursor after executing SQL statements.
: 2. All are Boolean attributes.
11. Find out nth highest salary from emp table
SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT
(DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
Enter value for n: 2
SAL
---------
3700
12. To view installed Oracle version information
SQL> select banner from v$version;
13. Display the number value in Words
SQL> select sal, (to_char(to_date(sal,'j'), 'jsp'))
from emp;
the output like,
SAL (TO_CHAR(TO_DATE(SAL,'J'),'JSP'))
--------- -----------------------------------------------------
800 eight hundred
1600 one thousand six hundred
1250 one thousand two hundred fifty
If you want to add some text like,
Rs. Three Thousand only.
SQL> select sal "Salary ",
(' Rs. '|| (to_char(to_date(sal,'j'), 'Jsp'))|| ' only.'))
"Sal in Words" from emp
/
Salary Sal in Words
------- ------------------------------------------------------
800 Rs. Eight Hundred only.
1600 Rs. One Thousand Six Hundred only.
1250 Rs. One Thousand Two Hundred Fifty only.
14. Display Odd/ Even number of records
Odd number of records:
select * from emp where (rowid,1) in (select rowid, mod(rownum,2) from emp);
1
3
5
Even number of records:
select * from emp where (rowid,0) in (select rowid, mod(rownum,2) from emp)
2
4
6
15. Which date function returns number value?
months_between
16. Any three PL/SQL Exceptions?
Too_many_rows, No_Data_Found, Value_Error, Zero_Error, Others
17. What are PL/SQL Cursor Exceptions?
Cursor_Already_Open, Invalid_Cursor
18. Other way to replace query result null value with a text
SQL> Set NULL ‘N/A’
to reset SQL> Set NULL ‘’
19. What are the more common pseudo-columns?
SYSDATE, USER , UID, CURVAL, NEXTVAL, ROWID, ROWNUM
20. What is the output of SIGN function?
1 for positive value,
0 for Zero,
-1 for Negative value.
21. What is the maximum number of triggers, can apply to a single table?
12 triggers.
6. How will you copy the structure of a table without copying the data?
select * from table_naem where 1 > 3
7. How to find out the database name from SQL*PLUS command prompt?
-
PRAGMA AUTONOMOUS_TRANSACTION;
Here is an example of defining a stored procedure as autonomous:
CREATE PROCEDURE process_ord_line_shipment
(p_order_no number, p_line_no number) AS
PRAGMA AUTONOMOUS_TRANSACTION;
l_char_1 varchar2(100);
BEGIN
...
END;
There are two restrictions on the use of this PRAGMA: it cannot be used to mark ALL members of
a package as autonomous. Simple workaround: mark each member (proc/function) as
autonomous individually. Also, a nested PL/SQL block cannot be marked as autonomous. Again,
the workaround is not too bad: just make it a local procedure (or a separate stored procedure).
The called routine should have its own commit (or rollback). This is true even for a trigger (which
otherwise cannot have a commit or rollback statement). An attempt to exit without committing or
rolling back the changes results in an exception condition (and the pending changes are rolled
back as a result).
Advantages of Autonomous Transactions
Autonomous transactions are likely to be quickly embraced by PL/SQL developers. They would
find their use in many situations where some DML's needs to be saved regardless of whether or
main transaction commits or rolls back. Here are a few examples:
Transaction logging: A transaction needs to be logged for audit purposes even if it fails and
does not update any other data. An example of this is currently available under the
sample PL/SQL code section of the Technet website (technet.oracle.com).
Debugging (logging messages in an error-message table). The procedure to insert a
message into a debug table should be set up as an autonomous transaction so the
messages are saved even if the main transaction fails or rolls back.
Incrementing retry counters. It is very similar to the transaction-logging situation.
Apart from these technical needs, there is a significant advantage of using autonomous
transactions from the point of view of programming style and structure. Since autonomous
transactions can be committed or rolled back independent of the main transaction, it will facilitate
development of more modular programs.
Here is an example of debugging application (mentioned above) that demonstrates this very well:
Procedure debug_write(p_err_msg in varchar2,
p_proc in varchar2, …)
is
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
Begin
Insert into debug messages (err_msg, proc_name, …)
Values(p_err_msg, p_proc, …);
Commit;
Exception
…
end;
END;
Once set up this way, it is a modular piece of code that can be called from any
procedure/function/trigger without compromising the integrity of the calling transaction.
This is a great benefit and will surely make PL/SQL programming more fun.
STEP DESCRIPTION
END PK_RETURN_RS;
/
BEGIN
FOR I IN C1
LOOP
O_ENO(CNT):=I.ENO;
O_ENAME(CNT):=I.ENAME;
O_SAL(CNT):=I.SAL;
CNT:=CNT+1;
END LOOP;
END GET_EMP_DETAILS;
END PK_RETURN_RS;
/
DECLARE
V_ENO PK_RETURN_RS.tbl_ENO;
V_ENAME PK_RETURN_RS.tbl_ENAME;
V_SAL PK_RETURN_RS.tbl_SAL;
V_DNO DEPT.DNO%TYPE := &DEPTNO;
BEGIN
Example of PK_RETURN_RS.GET_EMP_DETAILS(V_DNO,
calling Package V_ENO, V_ENAME,V_SAL);
using PL/SQL FOR K IN 1 .. V_ENO.COUNT
LOOP
DBMS_OUTPUT.PUT_LINE(V_ENO(K));
DBMS_OUTPUT.PUT_LINE(V_ENAME(K));
DBMS_OUTPUT.PUT_LINE(V_SAL(K));
END LOOP;
END;
/
SET rstest=CNNTEST.EXECUTE(STRSQL)
rstest.Open
Print "ENO :- " & rstest(0)
Print "ENAME :- " & rstest(1)
print "SAL :- " & rstest(2)
End Sub
STEP DESCRIPTION
DECLARE
Example of REC1 PK_RETURN_RS.TBL_EMP;
calling Package V_DNO NUMBER := &DNO;
BEGIN
using PL/SQL PK_RETURN_RS.GET_EMP_DETAILS(V_DNO,REC1);
FOR K IN 1 .. REC1.COUNT
LOOP
DBMS_OUTPUT.PUT_LINE(REC1(K).V_ENO);
DBMS_OUTPUT.PUT_LINE(REC1(K).V_ENAME);
DBMS_OUTPUT.PUT_LINE(REC1(K).V_SAL);
END LOOP;
END;
/
Create the following package that returns a recordset for the input Sql. CREATE
OR REPLACE PACKAGE GL_PK_RETURN_CURSOR AS TYPE REF_CUR
IS REF CURSOR; PROCEDURE GL_PR_RETURN_CURSOR( IN_SQL
VARCHAR2, OUT_REF_CUR OUT REF_CUR); END
GL_PK_RETURN_CURSOR ; /
In this package, a Ref Cursor type is defined and the package procedure returns
this type defined in the package as an OUT parameter. The Ref Cursor type that
is returned can be used in any Pl/Sql block or in the Sql Prompt and the records
stored in it can be retrieved, in much the same way as records are fetched from
any other cursor variable.
Pre-Requisite:
Create the following table. create table EMP ( EMPNO NUMBER(4) not null, ENAME
VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL
NUMBER(7,2), COMM NUMBER(7,2), DEPTNO NUMBER(2) );
From the Sql Prompt, follow the 4 steps below to retrieve employee records through the
package.
1. SET SERVEROUTPUT ON
2. VAR X REFCURSOR
3. EXEC GL_PK_RETURN_CURSOR.GL_PR_RETURN_CURSOR('SELECT * FROM
EMP',:X);
4. PRINT X
The following sample Pl/Sql Block can be used to retrieve the employee records through
the package.
DECLARE
V_SQLSTR VARCHAR2(4000);
V_EMP_CUR GL_PK_RETURN_CURSOR.REF_CUR;
V_EMP_ROW EMP%ROWTYPE;
BEGIN
V_SQLSTR:='SELECT * FROM EMP';
GL_PK_RETURN_CURSOR.GL_PR_RETURN_CURSOR(V_SQLSTR,V_EMP_CUR)
;
LOOP
FETCH V_EMP_CUR INTO V_EMP_ROW;
EXIT WHEN V_EMP_CUR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('Emp No : ' || V_EMP_ROW.EMPNO || ' | Emp Name : ' ||
V_EMP_ROW.ENAME || ' | Emp Sal : ' || V_EMP_ROW.SAL);
END LOOP;
END;
/
-- unordered
select ilv1.col_val
from
(
select
decode(ilv_dual.rnum, 1, src_table.col1
, 2, src_table.col2
, 3, src_table.col3
, 4, src_table.col4
, 5, src_table.col5
) col_val
from
src_table,
(select level rnum
from dual
connect by level <= 5
) ilv_dual
) ilv1
where ilv1.col_val is not null
-- ordered
select ilv1.col_val
from
(
select
src_table.rowid rid,
decode(ilv_dual.rnum, 1, src_table.col1
, 2, src_table.col2
, 3, src_table.col3
, 4, src_table.col4
, 5, src_table.col5
) col_val
from
src_table,
(select level rnum
from dual
connect by level <= 5
) ilv_dual
) ilv1
where ilv1.col_val is not null
order by ilv1.rid
/
What is the difference between all_ and user_ tabl...
An ALL_ view displays all the information accessible to the current user, including
information from the current user's schema as well as information from objects in other
schemas, if the current user has access to those objects by way of grants of privileges or
roles.
While A USER_ view displays all the information from the schema of the current user. No
special privileges are required to query these views.
Based on what conditions can we decide whether to use a table or a view or a
materialized view ?
Security reasons we can use view2. If there is a more transaction in a base table we better
chose materialised view for performance 3. Depend upon the situation where we need to
refresh the data in specific time interval.
Tables we used for entity information physically in our DB.
View is a virtual representation of table data, for security and hiding the table column
infor. we used normally view. we uses for Report & MIS purposes for showing the data
from more than two table.
Materalized view is used for remote data access and suitable for transaction related data
storage in distributed environment. It stores the data phyisically comparision to normal
view. It can refreshes the remote data auto. and forcefully/manually.
--if the refresh mode is Force
dbms_mview.refresh('Ashok_mview')
What are ref cursors ?
They are similar to a normal curson but they can have different select stmts at run time.
What is the difference between a reference cursor and normal cursor ?
REF cursors are different than your typical, standard cursors. With standard cursors, you
know the cursor's query ahead of time. With REF cursors, you do not have to know the
query ahead of time. With REF Cursors, you can build the cursor on the fly
Normal Cursor is a Static Cursor.
Refernce Cursor is used to create dynamic cursor.
There are two types of Ref Cursors:
1. Weak cursor and 2.Strong cursor
Type ref_name is Ref cursor [return type]
[return type] means %Rowtype
if Return type is mentioned then it is Strong cursor else weak cursor
The Reference cursor does not support For update clause.
Describe in brief some of the featurs of oracle9i....
LogMiner is a powerful audit tool for Oracle databases, allowing administrators to easily
locate changes in the database, enabling sophisticated data analyses, and providing undo
capabilities to rollback logical data corruptions or user errors.
Can e truncate some of the rows from the table instead of truncating the full table.
No , it is not possible. Truncate is a DDL Command and we can not where clause in
Truncate.
can i write plsql block inside expection
Yes you can write PL/SQL block inside exception section. Suppose you want to insert the
exception detail into your error log table, that time you can write insert into statement in
exception part. To handle the exception which may be raised in your exception part, you
can write the PL/SQL code in exception part.
What is PL/SQL table?
SNO MARK
------- ------------------
1 59
2 40
3 ‘A’
4 60
Write a single query to I) Sorted Marks II)First mark III) replace the mark ‘A’ with
0(zero)?
%searchwordhere%
searchwordhere%
%searchwordhere
The searchwordhere% is the fastest because it can use an index if one is specified on that
column. The other two %searchwordhere%, and %searchwordhere would never use the
index even if one is specified and thus result in slow table scans.
In which situation whether peak time or off peak time you will execute the
ANALYZE TABLE command. Why
You have to run the analyze command during off peak time only because it actually
performs full table scan.
How to do the scheduled task/jobs in Unix platform
Salay
------
10
20
30
40
TRUNCATE DELETE
select name,salary from employee where rowid=( select Max(rowid) from employee
where rownum<=10);
one can create a table2 from the existing table1 by selecting distinct values and dropping
the table1.
1. Suppose if you are using JAVA applications to modify the database columns, then you
have to open streaming connections to write data for these columns where the streaming
connections can be ASCII as well as Binary connections. See the java docs for that.
2. From SQL plus it not possible to write as max value that can be written is 4000 chars.
3. From PL/SQL you have to use the dbms_lob.writeappend packages for inserting data.
The User Defined TYPE can contain these datatypes CLOB,BLOB,NCLOB be part of
user defined records or datatype by record i mean
type rec_blob is record( l_str clob);
Merge Join :
Oracle performs a join between two sets of row data using the merge
join algorithm. The inputs are two separate sets of row data. Output is
the results of the join. Oracle reads rows from both inputs in an
alternating fashion and merges together matching rows in order to
generate output. The two inputs are sorted on join column.
Hash Join :
Oracle performs a join between two sets of row data using hash join
algorithm. Input and Output same as Merge Join. Oracle reads all rows
from the second input and builds a hash structure (like has table in
java), before reading each row from the first input one at a time. For
each row from the first input, the hash structure is probed and matching
rows generate output.
Difference between Optimizer=ALL_ROWS and Optimizer=CHOOSE
Choose - Choose either Rule based or Cost based depend on the
availability of statistics. If statistics is available on the table it uses
CBO and if not it uses RBO.
Declare
type rc is ref cursor;
l_cursor rc;
begin
if ( to_char(sysdate,'dd') = 30 ) then
open l_cursor for 'select * from emp';
elsif ( to_char(sysdate,'dd') = 29 ) then
open l_cursor for select * from dept;
else
open l_cursor for select * from dual;
end if;
open c;
end;
/
Given that block of code -- you see perhaps the most "salient"
difference -- no
matter how many times you run that block -- cursor C will always be
select *
from dual. The ref cursor can be anything.
Another difference is that static sql (not using a ref cursor) is much
more
efficient then using ref cursors and that use of ref cursors should be
limited
to
- returning result sets to clients
- when there is NO other efficient/effective means of achieving the goal
that is, you want to use static SQL (with implicit cursors really) first
and use
a ref cursor only when you absolutely have to
Then sit back and say "anything else you wanted to know about them"
Aliases:
An alias in oracle is another name used for a column or a table inside SELECT query.
They are accessible only inside the query where they are created. Once the query
execution is over alias will perish. An alias can be a single word or can be more than one
word. If alias used is more than one word it must be enclosed in double quotes
example:
current_date or "current date"
Student_name or "Student name"
Aliases are used in places when ever there is multiple usage of longer table names.
example :
STUDENT_MASTER_RECORD can be aliased as SMR
ACCOUNT_MASTER_TABLE as AMT .
SUBQUERY :
A query within another quey. A select statement whose output is substituted in the
condition of another select statement .(A query is a statement written for returning
specific data). The subquery is executed only once. A subquery is enclosed in parenthesis
Conside the following queries.
1) SELECT DEPTNO FROM EMP WHERE ENAME = 'SMITH';
2) SELECT ENAME FROM EMP WHERE DEPTNO= 20
These two queries can be combined as follows.
SQL> SELECT ENAME FROM EMP
WHERE DEPTNO = (SELECT DEPTNO FROM EMP
WHERE ENAME = 'SMITH');
The SELECT statement inside parenthesis is called subquery and the one which
uses the values returned by it as main query.
CORRELATED QUERY:
In a correlated subquery the table used in outer query refers to the table used in the inner
query. The correlated subquery is executed repeatedly once
for each row of the main query table.
Query to diplay name of highest salary taker.
SQL> SELECT EMPNO, ENAME FROM EMP A
WHERE 1 > ( SELECT COUNT(*) FROM EMP B
WHERE A.SAL < B.SAL)
EMPNO ENAME
-------- ----------
7839 KING
SET OPERATORS
They combine results from two or more queries into one result.Data type
of all selected colums must be of same type.
UNION: It returns
rows of first query plus rows of second query but avoids duplicates.
(UNION ALL will give duplicates also).
To display designations in department 10 and 20
SQL> SELECT JOB FROM EMP WHERE DEPTNO=10
UNION
SELECT JOB FROM EMP WHERE DEPTNO=20;
JOB
---------
ANALYST
CLERK
MANAGER
PRESIDENT
To display designations in department 10,20 and 30
SQL> SELECT JOB FROM EMP WHERE DEPTNO=10
UNION
SELECT JOB FROM EMP WHERE DEPTNO=20
UNION
SELECT JOB FROM EMP WHERE DEPTNO=30;
JOB
---------
ANALYST
CLERK
MANAGER
PRESIDENT
SALESMAN
Similar output can be produced by writing
SQL> SELECT DISTINCT JOB FROM EMP;
JOB
---------
ANALYST
CLERK
MANAGER
PRESIDENT
SALESMAN
INTERSECT: It returns rows that are common to all queries.
Indexes
This chapter describes how to use indexes in a data warehousing environment and
discusses the following types of index:
Bitmap Indexes
B-tree Indexes
Local Indexes Versus Global Indexes
See Also:
Bitmap indexes are widely used in data warehousing environments. The environments
typically have large amounts of data and ad hoc queries, but a low level of concurrent
DML transactions. For such applications, bitmap indexing provides:
Fully indexing a large table with a traditional B-tree index can be prohibitively expensive
in terms of space because the indexes can be several times larger than the data in the
table. Bitmap indexes are typically only a fraction of the size of the indexed data in the
table.
Note:
Bitmap indexes are available only if you have purchased the Oracle9i
Enterprise Edition. See Oracle9i Database New Features for more
information about the features available in Oracle9i and the Oracle9i
Enterprise Edition.
An index provides pointers to the rows in a table that contain a given key value. A regular
index stores a list of rowids for each key corresponding to the rows with that key value.
In a bitmap index, a bitmap for each key value replaces a list of rowids.
Each bit in the bitmap corresponds to a possible rowid, and if the bit is set, it means that
the row with the corresponding rowid contains the key value. A mapping function
converts the bit position to an actual rowid, so that the bitmap index provides the same
functionality as a regular index. If the number of different key values is small, bitmap
indexes save space.
Bitmap indexes are most effective for queries that contain multiple conditions in the
WHERE clause. Rows that satisfy some, but not all, conditions are filtered out before the
table itself is accessed. This improves response time, often dramatically.
Benefits for Data Warehousing Applications
Bitmap indexes are primarily intended for data warehousing applications where users
query the data rather than update it. They are not suitable for OLTP applications with
large numbers of concurrent transactions modifying the data.
Parallel query and parallel DML work with bitmap indexes as they do with traditional
indexes. Bitmap indexing also supports parallel create indexes and concatenated indexes.
See Also:
Cardinality
The advantages of using bitmap indexes are greatest for columns in which the ratio of the
number of distinct values to the number of rows in the table is under 1%. We refer to this
ratio as the degree of cardinality. A gender column, which has only two distinct values
(male and female), is ideal for a bitmap index. However, data warehouse administrators
also build bitmap indexes on columns with higher cardinalities.
For example, on a table with one million rows, a column with 10,000 distinct values is a
candidate for a bitmap index. A bitmap index on this column can outperform a B-tree
index, particularly when this column is often queried in conjunction with other indexed
columns. In fact, in a typical data warehouse environments, a bitmap index can be
considered for any non-unique column.
B-tree indexes are most effective for high-cardinality data: that is, for data with many
possible values, such as customer_name or phone_number. In a data warehouse, B-tree
indexes should be used only for unique columns or other columns with very high
cardinalities (that is, columns that are almost unique). The majority of indexes in a data
warehouse should be bitmap indexes.
In ad hoc queries and similar situations, bitmap indexes can dramatically improve query
performance. AND and OR conditions in the WHERE clause of a query can be resolved
quickly by performing the corresponding Boolean operations directly on the bitmaps
before converting the resulting bitmap to rowids. If the resulting number of rows is small,
the query can be answered quickly without resorting to a full table scan.
Table 6-1 illustrates the bitmap index for the cust_gender column in this example. It
consists of two separate bitmaps, one for gender.
cust_id 70 0 1
cust_id 80 0 1
cust_id 90 1 0
cust_id 100 0 1
cust_id 110 0 1
cust_id 120 1 0
cust_id 130 1 0
cust_id 140 1 0
Each entry (or bit) in the bitmap corresponds to a single row of the customers table. The
value of each bit depends upon the values of the corresponding row in the table. For
instance, the bitmap cust_gender='F' contains a one as its first bit because the region is
east in the first row of the customers table. The bitmap cust_gender='F' has a zero
for its third bit because the gender of the third row is not F.
Bitmap indexes can efficiently process this query by merely counting the number of ones
in the bitmap illustrated in Figure 6-1. The result set will be found by using bitmap or
merge operations without the necessity of a conversion to rowids. To identify additional
specific customer attributes that satisfy the criteria, use the resulting bitmap to access the
table after a bitmap to rowid conversion.
Unlike most other types of indexes, bitmap indexes include rows that have NULL values.
Indexing of nulls can be useful for some types of SQL statements, such as queries with
the aggregate function COUNT.
Any bitmap index can be used for this query because all table rows are indexed, including
those that have NULL data. If nulls were not indexed, the optimizer would be able to use
indexes only on columns with NOT NULL constraints.
You can create bitmap indexes on partitioned tables but they must be local to the
partitioned table--they cannot be global indexes. (Global bitmap indexes are supported
only on nonpartitioned tables). Bitmap indexes on partitioned tables must be local
indexes.
See Also:
"Index Partitioning"
Bitmap Join Indexes
In addition to a bitmap index on a single table, you can create a bitmap join index, which
is a bitmap index for the join of two or more tables. A bitmap join index is a space
efficient way of reducing the volume of data that must be joined by performing
restrictions in advance. For each value in a column of a table, a bitmap join index stores
the rowids of corresponding rows in one or more other tables. In a data warehousing
environment, the join condition is an equi-inner join between the primary key column or
columns of the dimension tables and the foreign key column or columns in the fact table.
Bitmap join indexes are much more efficient in storage than materialized join views, an
alternative for materializing joins in advance. This is because the materialized join views
do not compress the rowids of the fact tables.
Using the example in "Bitmap Index", create a bitmap join index with the following
sales table:
The following query shows how to use this bitmap join index and illustrates its bitmap
pattern:
TIME_ID C AMOUNT
--------- - ----------
01-JAN-98 M 2291
01-JAN-98 F 114
01-JAN-98 M 553
01-JAN-98 M 0
01-JAN-98 M 195
01-JAN-98 M 280
01-JAN-98 M 32
...
sales record 1 1 0
sales record 2 0 1
sales record 3 1 0
sales record 4 1 0
sales record 5 1 0
sales record 6 1 0
sales record 7 1 0
You can create other bitmap join indexes using more than one column or more than one
table, as shown in these examples.
You can create a bitmap join index on more than one column, as in the following
example, which uses customers(gender, marital_status):
You can create a bitmap join index on more than one table, as in the following, which
uses customers(gender) and products(category):
You can create a bitmap join index on more than one table, in which the indexed column
is joined to the indexed table by using another table. For example, we can build an index
on countries.country_name, even though the countries table is not joined directly to
the sales table. Instead, the countries table is joined to the customers table, which is
joined to the sales table. This type of schema is commonly called a snowflake schema.
Join results must be stored, therefore, bitmap join indexes have the following restrictions:
Parallel DML is currently only supported on the fact table. Parallel DML on one
of the participating dimension tables will mark the index as unusable.
Only one table can be updated concurrently by different transactions when using
the bitmap join index.
No table can appear twice in the join.
You cannot create a bitmap join index on an index-organized table or a temporary
table.
The columns in the index must all be columns of the dimension tables.
The dimension table join columns must be either primary key columns or have
unique constraints.
If a dimension table has composite primary key, each column in the primary key
must be part of the join.
See Also:
A B-tree index is organized like an upside-down tree. The bottom level of the index holds
the actual data values and pointers to the corresponding rows, much as the index in a
book has a page number associated with each index entry.
See Also:
In general, use B-tree indexes when you know that your typical query refers to the
indexed column and retrieves a few rows. In these queries, it is faster to find the rows by
looking at the index. However, using the book index analogy, if you plan to look at every
single topic in a book, you might not want to look in the index for the topic and then look
up the page. It might be faster to read through every chapter in the book. Similarly, if you
are retrieving most of the rows in a table, it might not make sense to look up the index to
find the table rows. Instead, you might want to read or scan the table.
B-tree indexes are most commonly used in a data warehouse to index unique or near-
unique keys. In many cases, it may not be necessary to index these columns in a data
warehouse, because unique constraints can be maintained without an index, and because
typical data warehouse queries may not work better with such indexes. Bitmap indexes
should be more common than B-tree indexes in most data warehouse environments.
B-tree indexes on partitioned tables can be global or local. With Oracle8i and earlier
releases, Oracle recommended that global indexes not be used in data warehouse
environments because a partition DDL statement (for example, ALTER TABLE ... DROP
PARTITION) would invalidate the entire index, and rebuilding the index is expensive. In
Oracle9i, global indexes can be maintained without Oracle marking them as unusable
after DDL. This enhancement makes global indexes more effective for data warehouse
environments.
However, local indexes will be more common than global indexes. Global indexes should
be used when there is a specific requirement which cannot be met by local indexes (for
example, a unique index on a non-partitioning key, or a performance requirement).
1) A table AA contains two columns c1 and c2. column c1 contains 3 records and column
c2 contains
3 records.
write a update query so that c1 must contain c2 values and c2 must c1 values .
[SWAPPING]
3) A table has 4 index. If a query , select * from table uses the index. When it is used.
6) what is the query performance if a table contains more than 100 columns.
My Answer : Yes .
My Answer: No
8) How will u measure the performance of the query.What are the tools available??