1.what Is A Cursor For Loop ?
1.what Is A Cursor For Loop ?
1.what Is A Cursor For Loop ?
Cursor for loop implicitly declares %ROWTYPE as loop index, opens a cursor, fetches rows of
values from active set into fields in the record and closes.
END LOOP;
Procedure:-
Execute as a PL/SQL
statement, No RETURN clause in
the header, Can return none, one,
or many values,Can contain a RETURN
statement
Function:-Invoke as part of an
expression,Must contain a RETURN
clause in the header,Must return a single value,Must contain at least one RETURN statement
Implicit Cursor are declared and used by the oracle internally. whereas the explicit cursors
are declared and used by the user. More over implicitly cursors are no need
to declare oracle creates and process and closes automatically. The explicit cursor should be
declared and closed by the user.
ROWID - Every record in a database is uniquely identified by system generated value called
Rowid’s. It Is a 18 character hexma decimal value. These Rowid's are physically existence.
ROWNUM - It is an integer number also unique for sorting Normally TOP N Analysis
Other Psudo Column are
NEXTVAL, CURRVAL Of sequence are some exampls
6. What is Raise_application_error ?
7. Name the tables where characteristics of Package, procedure and functions are stored ?
Characteristics of DB objects are stored in data dictionary. Which can be accessed by Data
dict. views like (user/all/DBA_objects/source).
Ref Cursor is cursor variable. It is a pointer to a result set. It is useful in scenarios when
result set is created in one program and the processing of the same in some other, might be
written indifferent language, e.g. firing the select is done in PL/SQL and the processing will
be done in Java.
declare
type r_cursor is REF CURSOR;
c_emp r_cursor;
en emp.ename%type;
begin
open c_emp for select ename from emp;
loop
fetch c_emp into en;
exit when c_emp%notfound;
dbms_output.put_line(en);
end loop;
close c_emp;
end;
9. How many types of database triggers can be specified on a table ? What are they?
Baically there only 1 type of trigger which can be fired on the table. .i.e., DML TRIGGER.
1. Before insert on ROW LEVEL TRIGGER 2. 1. AFTER insert on ROW LEVEL TRIGGER
11. Before Delete on ROW LEVEL TRIGGER. 12 After Delete on ROW LEVEL TRIGGER
14.What will be the output for the below Query Select 'High'
from dual where null = null;
The Answer will always be null, since you never can equate a NULL to another NULL. if the
query was "Select 'High' from dual where null IS null;" The answer would have been "High"
SELECT * FROM A
MINUS
SELECT * FROM B
while minus shows only those rows which are not duplicated of table first in query.
SELECT * FROM A
UNION
SELECT * FROM B
How to calculate the second highest salary of he
16.
employee ?
TRUNCATE: in the case of truncate when u r using truncate what ever data in the table it will
be deleted. after that if u r giving rollback also the data will not be retrived. but the
structure of the table is available.
DROP: in the case of DROP if u r using drop the rollback command is not working and
structure and data in the table also deleted. nothing willbe available about that table.
DELETE: delete * from emp;
TRUNCATE: truncate table emp;
drop table emp;
Foreign Key: This is a constraint which is just opposite to Primary key. It can be not null &
can accept duplicate value as well.
Foreign key points to same table's primary key or another table's primary key to make a
relationship.
26. I have two table one Emp and other is dpt. Emp table has a field
,dept id,name ,sal and dpt table has a field dept id,dept name. Now I
want to find out the emplyee list whose sal is between 2000-3000
from dept x.
Select Name
From Emp e inner join Dpt d
on d.dptid=e.dptid Where sal>=2000 And sal<=3000
And dptname='x'
33. Briefly explain the difference between first, second, third and
fourth normal forms?
Second Normal Form : Non-Key attribute should be fully functionally dependent on key
Attribute.
Third normal Form : There is no transitivity dependency between attribute. Suppose 'y' is
dependent on 'x' i.e. x->y and 'z' is dependent on 'y' i.e. y->z this is transitivity dependency
So we can split table on to two tables os that result will be x->z.
Forth Normal Form : A determinant is any attribute (simple or composite) on which some
other attribute is fully functionally dependent.
RAC stands for REAL APPLICATION CLUSTER; it is and advance future from oracle 10g
Oracle RAC allows multiple computers to run the Oracle RDBMS software simultaneously
while accessing a single database, thus providing a clustered database.
Areas include:
Fault tolerance
Load balancing
Scalability
1) Not Null: This doesn't accept null values.. in other words when u declare a
column as not null then its mandatory to enter a value for that column without
leaving it blank
The above example will create a table emp with field empno with not null constraint
2) Unique: This uniquely identifies every row in the table... it restricts the entry of
duplicate values in the table
In the example when u try to enter a empno which is already existing it will not
accept
3) Primary Key: it is also known as not null key... this uniquely identifies each row
in the table. observe this example
Here we created a table emp with a field empno as not null and unique. Instead of
using both not null and unique constraints simply declare the field as "PRIMARY
KEY" wch satisfies both constraint conditions
• procedure
• function
• package
• trigger
• index
• cluster
• sequence
• view
• table
NAME
--------------------
Girija Sankar
11) When do you use WHERE clause and when do 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.
SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM
EMP B WHERE a.sal<=b.sal);
For Eg:-
SAL
---------
3700
One more diff is that function must return a value while procedure may or may not return a
value.
yes fuction can take out variable but the good programing practice is to not use the out
parameter since function must return only one value to the calling envoirnment.
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.
1)User defined datatypes are applicable only for oracle 9i but not oracle 8i.
2)datatype for character large object is LONG for oracle 8i but it is LOBS for oracle9i.
Scalar Types
BINARY_INTEGER
DEC
DECIMAL
DOUBLE PRECISION
FLOAT
INT
INTEGER
NATURAL
NATURALN
NUMBER
NUMERIC
PLS_INTEGER
POSITIVE
POSITIVEN
REAL
SIGNTYPE
SMALLINT
CHAR
CHARACTER
LONG
LONG RAW
NCHAR
NVARCHAR2
RAW
ROWID
STRING
UROWID
VARCHAR
VARCHAR2
DATE
INTERVAL DAY TO SECOND
INTERVAL YEAR TO MONTH
TIMESTAMP
TIMESTAMP WITH LOCAL TIME ZONE
TIMESTAMP WITH TIME ZONE
BOOLEAN
Composite Types
RECORD
TABLE
VARRAY
LOB Types
BFILE
BLOB
CLOB
NCLOB
Reference Types
REF CURSOR
REF object_type
View does not occupy memory but Oracle keeps view code in its dictionary (you can check in
user views for example)
If you delete the base table the view becomes INVALID.
In order to make it valid again you have to ether build the deleted table again or create
another view with the same name and structure as deleted table or create synonym with the
same name as deleted table which will point to the table with the same structure.
1) HAVING clause can only be used to filter out the aggegate functions whereas WHERE clause
cannot filter out the aggegate functions.
2) HAVING clause can be used with GROUP BY function where as WHERE clause cannot be used
with group by function.
Deadlock is a process it occurs when two users are trying to modify the same data at the same
time then problem occurs with this process then oracle automatically locks one user so that
other user can process the data.
27) Dispaly employee records who gets more salary than the average salary in
their department?
Cartesian Products: If two tables in a join query have no join condition Oracle
returns their Cartesian product. Oracle combines each row of one table with
each row of the other. A Cartesian product always generates many rows and is
rarely useful.• A Cartesian product is formed when:– A join condition is
omitted– A join condition is invalid– All rows in the first table are joined to all
rows in the second table
255 bytes was the size limits of earlier version of oracle..ie prior to 10 g ..in 10g 32767
byte is the limit..
Though we can use out parameter in function(function not getting called from select
statement or DML) it is not good programming practice to write OUT and IN OUT in function.
In case we wanted to return values using OUT parameters always use procedures.
In case we wanted to return more than one value from function use of ref cursor is preferred
solution not OUT parameters.
Exception is nothing but Error. In PL/SQL block we handle these errors in Exception block.
There are two types of exceptions: 1> System define exception and 2> User define exception.
System define exception predefine exceptions like 'ZERO_DEVIDE' NO_DATA_FOUND etc.User
define exceptions is defined by the user and raise in the excution block and then call into the
exception block.