You are on page 1of 2

1. What is a CO-RELATED SUBQUERY ?

SELECT field1 from table1 X WHERE field2>(select avg(field2) from table1 Y


where field1=X.field1);

The subquery in a correlated subquery is revaluated for every row of the table or view named in the outer
query.)

2. What are various constraints used in SQL


NULL
NOT NULL
CHECK
DEFAULT
3. What are different Oracle database objects
TABLES
VIEWS
INDEXES
SYNONYMS
SEQUENCES
TABLESPACES etc
4. What is difference between Rename and Alias
5. 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.
6. Can a primary key contain more than one columns
Yes
7. Which datatype is used for storing graphics and images
LONG RAW data type is used for storing BLOB's (binary large objects).
8. What is difference between SUBSTR and INSTR
SUBSTR returns a specified portion of a string eg SUBSTR('BCDEF',4) output BCDE INSTR provides character position in
which a pattern is found in a string.

eg INSTR('ABC-DC-F','-',2) output 7 (2nd occurence of '-')


9. There is a string '120000 12 0 .125' ,how you will find the position of the decimal place
INSTR('120000 12 0 .125',1,'.') output 13
10. When you use WHERE clause and when you use HAVING clause
HAVING clause is used when you want to specify a condition for a group function and it is written after GROUP BY clause
The WHERE clause is used when you want to specify a condition for columns, single row functions except group functions
and it is written before GROUP BY clause if it is used.
11. What is a cursor.
Oracle uses work area to execute SQL statements and store processing information PL/SQL construct called a cursor lets
you name a work area and access its stored information A cursor is a mechanism used to fetch more than one row in a
Pl/SQl block.
12. What are cursor attributes
%ROWCOUNT
%NOTFOUND
%FOUND
%ISOPEN
13. Can cursor variables be stored in PL/SQL tables.If yes how.If not why.
No, a cursor variable points a row which cannot be stored in a two-dimensional PL/SQL table.
14. Can you use a commit statement within a database trigger.
No
15. 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.
16. Describe the use of %ROWTYPE and %TYPE in PL/SQL

Expected answer: %ROWTYPE allows you to associate a variable with an entire table row.
The %TYPE associates a variable with a single column type.
17. What is a Cartesian product
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.

18. To see current user name


Sql> show user;
19. 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
20. 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
21. 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

You might also like