Oracle FAQ's Part-11

551. What is a view ?
A view is stored procedure based on one or more tables, it's a virtual table.

552. What is difference between UNIQUE and PRIMARY KEY constraints?
A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys. The columns that compose PK are automatically define NOT NULL, whereas a column that compose a UNIQUE is not automatically defined to be mandatory must also specify the column is NOT NULL.

553. What is use of a cursor variable? How it is defined?
A cursor variable is associated with different statements at run time, which can hold different values at run time.

Static cursors can only be associated with one run time query. A cursor variable is reference type (like a pointer in C).
Declaring a cursor variable:TYPE type_name IS REF CURSOR RETURN return_type type_name is the
name of the reference type,return_type is a record type indicating cursor variable.


554. How do you find the numbert of rows in a Table ?
A bad answer is count them (SELECT COUNT(*) FROM table_name)
A good answer is :-'By generating SQL to ANALYZE TABLE table_name COUNT STATISTICS by
querying Oracle System Catalogues (e.g. USER_TABLES or ALL_TABLES).
The best answer is to refer to the utility which Oracle released which makes it unnecessary to do ANALYZE TABLE for each Table individually.

555. What is the maximum buffer size that can be specified using the DBMS_OUTPUT.ENABLE function?
1,000,00

556. What are cursor attributes?
-%ROWCOUNT
-%NOTFOUND
-%FOUND
-%ISOPEN

557. There is a % sign in one field of a column. What will be the query to find it?
'' Should be used before '%'.

558. What is ON DELETE CASCADE ?
When ON DELETE CASCADE is specified ORACLE maintains referential integrity by automatically removing dependent foreign key values if a referenced primary or unique key value is removed.

559. What is the fastest way of accessing a row in a table ?
Using ROWID.CONSTRAINTS

560. What is difference between TRUNCATE & DELETE ?
TRUNCATE commits after deleting entire table i.e., can not be rolled back. Database triggers do not fire on TRUNCATEDELETE allows the filtered deletion. Deleted records can be rolled back or
committed.Database triggers fire on DELETE.

561. What is a transaction ?
Transaction is logical unit between two commits and commit and rollback.

562. What are the advantages of VIEW ?
To protect some of the columns of a table from other users.To hide complexity of a query.To hide complexity of calculations.

563. How will you a activate/deactivate integrity constraints ?
The integrity constraints can be enabled or disabled by ALTER TABLE ENABLE constraint/DISABLE constraint.

564. Where the integrity constraints are stored in Data Dictionary ?
The integrity constraints are stored in USER_CONSTRAINTS.

565. What is the Subquery ?
Sub query is a query whose return values are used in filtering conditions of the main query.

566. How to access the current value and next value from a sequence ? Is it possible to access the current value in a session before accessing next value ?
Sequence name CURRVAL, Sequence name NEXTVAL.It is not possible. Only if you access next value in the session, current value can be accessed.

567. What are the usage of SAVEPOINTS ?value in a session before accessing next value ?
SAVEPOINTS are used to subdivide a transaction into smaller parts.
It enables rolling back part of a transaction. Maximum of five save points are allowed.


568. What is ROWID ?in a session before accessing next value ?
ROWID is a pseudo column attached to each row of a table. It is 18
character long, blockno, rownumber are the components of ROWID.

569. Explain Connect by Prior ?in a session before accessing next value ?
Retrieves rows in hierarchical order.e.g. select empno, ename from emp where.

570. How many LONG columns are allowed in a table ? Is it possible to use LONG columns in WHERE clause or ORDER BY ?
Only one LONG columns is allowed. It is not possible to use LONG column in WHERE or ORDER BY clause.

571. What is Referential Integrity ?
Maintaining data integrity through a set of rules that restrict the values of one or more columns of the tables based on the values of primary key or unique key of the referenced table.

572. What is a join ? Explain the different types of joins ?
Join is a query which retrieves related columns or rows from multiple tables.

Self Join - Joining the table with itself.

Equi Join -Joining two tables by equating two common columns.

Non-Equi Join - Joining two tables by equating two common columns.

Outer Join - Joining two tables in such a way that query can also retrieve rows
that do not have corresponding join value in the other table.

573. If an unique key constraint on DATE column is created, will it validate the rows that are inserted with SYSDATE ?
It won't, Because SYSDATE format contains time attached with it.

574. Explain UNION,MINUS,UNION ALL, INTERSECT ?
INTERSECT returns all distinct rows selected by both queries.MINUS - returns all distinct rows selected by the first query but not by the second.UNION - returns all distinct rows selected by either
queryUNION ALL - returns all rows selected by either query, including all duplicates.

575. What is an Integrity Constraint ?
Integrity constraint is a rule that restricts values to a column in a table.

576. Difference between SUBSTR and INSTR ?

INSTR (String1,String2(n,(m)),INSTR returns the position of the mth occurrence of the string 2 instring1. The search begins from nth position of string1.SUBSTR (String1 n,m)SUBSTR returns a character string of size m in string1, starting from nth position of string1.

577. If a View on a single base table is manipulated will the changes be reflected on the base table ?
If changes are made to the tables which are base tables of a view will the changes be reference on the view.

578. What are the pre requisites ?

I. to modify data type of a column ? ii. to add a column with NOT NULL constraint ? To Modify the datatype of a column the column must be empty. to add a column with NOT NULL constrain, the table must be empty.
579. What is a database link ?
Database Link is a named path through which a remote database can be accessed.

580. What are the types of SQL Statement ?
Data Definition Language : CREATE,ALTER,DROP,TRUNCATE,REVOKE,NO AUDIT & COMMIT.
Data Manipulation Language: INSERT,UPDATE,DELETE,LOCK
TABLE,EXPLAIN PLAN & SELECT.Transactional Control:COMMIT & ROLLBACKSession Control: ALTERSESSION & SET
ROLESystem Control :ALTER SYSTEM.

581. What is CYCLE/NO CYCLE in a Sequence ?
CYCLE specifies that the sequence continues to generate values after reaching either maximum or minimum value. After pan ascending sequence reaches its maximum value, it generates its minimum value. After a descending sequence reaches its minimum, it generates its maximum.NO CYCLE specifies that the sequence cannot generate more values after reaching its maximum or minimum value.
582. What is correlated sub-query ?
Correlated sub query is a sub query which has reference to the main query.

583. What are the data types allowed in a table ?

CHAR,VARCHAR2,NUMBER,DATE,RAW,LONG and LONG RAW.

584. What is difference between CHAR and VARCHAR2 ? What is the maximum SIZE allowed for each type ?

CHAR pads blank spaces to the maximum length. VARCHAR2 does not pad blank spaces. For CHAR it is 255 and 2000 for VARCHAR2.

585. Can a view be updated/inserted/deleted? If Yes under what conditions ?
A View can be updated/deleted/inserted if it has only one base table if the view is based on columns from one or more tables then insert, update and delete is not possible.

586. What are the different types of Coordinations of the Master with the Detail block?

POPULATE_GROUP(function)
POPULATE_GROUP_WITH_QUERY(function)
SET_GROUP_CHAR_CELL(procedure)
SET_GROUPCELL(procedure)
SET_GROUP_NUMBER_CELL(procedure)

587. Use the ADD_GROUP_COLUMN function to add a column to a record
group that was created at design time? I) TRUE II)FALSE
II) FALSE

588. Use the ADD_GROUP_ROW procedure to add a row to a static record
group? I) TRUE II)FALSE

I) FALSE

589. maxvalue.sql Select the Nth Highest value from a table?
select level, max('col_name') from my_table where level = '&n'
connect by prior ('col_name') > 'col_name')
group by level;
Example:
Given a table called emp with the following columns:
-- id number
-- name varchar2(20)
-- sal number
--
-- For the second highest salary:
-- select level, max(sal) from emp
-- where level=2
-- connect by prior sal > sal
-- group by level

590. 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);
For Eg:-
Enter value for n: 2
SAL
---------
3700

591. Suppose a customer table is having different columns like customer no, payments.What will be the query to select top three max payments?
SELECT customer_no, payments from customer C1 WHERE 3<=(SELECT COUNT(*) from customer C2 WHERE C1.payment <= C2.payment)

592. How you will avoid your query from using indexes?

SELECT * FROM emp Where emp_no+' '=12345;
i.e you have to concatenate the column name with space within codes
in the where condition.
SELECT /*+ FULL(a) */ ename, emp_no from emp where emp_no=1234;
i.e using HINTS

Recent Tutorials