JustAnswer.com

Monday, June 11, 2007

Oracle 7

What is Pseudo Colomn ?
USER, UID, SYSDATE, ROWNUM, ROWID, NULL, AND LEVEL

How to Display output in PL/SQL ?

we first
set serveroutput on
at SQL Prompt. and then in sql programming we specify as
dbms_output.put_line(`hdjhd' || `sakdha');
No Displays are allowed in PL/SQL programming with select statement

Write about Commands and Keywords ?
Alter : ALTER TABLE EMP ADD .......... , MODIFY .......... ;
for a in 1..10 loop ........... end loop;
loop exit when a<1 .................. end loop;
while ..... loop.................end loop;
Data Types : number, integer, varchar2, char, date, Boolean;
goto procedure name;..............<>..............
exit, rollback, commit, savepoint.
References: This keyword is used to refer two similar fields of different tables.

What are different built in functions ?
CONCATENATE, INITCAP, LENGTH, LOWER, UPPER, LPAD, RPAD, LTRIM
(removes the character specified left side of word), RTRIM, SUBSTR (displays values from
specified location onwards), TRANSLATE (for single character), REPLACE (for more than one
character ),CHR ( prints character of given ASCII value), ASCII (value of given character ).
ABS, CEIL, FLOOR, SQRT, POWER, SIGN, TRUNC, ROUND, EXP, MOD, LOG, LN,
GREATEST, LEAST, SYSDATE, ADD_MONTHS, MONTHS_BETWEEN.

what are emp.sal%type and emp%rowtype ?
First one is to assign a variable of type sal only.
Second is to assign a complete row of type emp table.

What are constraints ?
Constraint Clause : This will constrain a single column or a group of columns in a table.
and are used for maintaining integrity of the database.
Different Constraints are : candidate keys, primary keys, foreign keys, check conditions.
Can specify as a part of column definition, or at the end of the table (if more than one column).
Check Constraint : for validations to fields.
Naming Constraint (table constraints): Can name the constraint else system will name it
by default.

Different types of joins ?
Equi join : where emp.deptno = dept.deptno;
Non Equi join : where e.sal >= g.losal;
Outer join :***********e.deptno(+)=d.deptno;

Different types of Keys ?
Foreign Key : This is a referential integrity constraint and specifies the values of primary
key in other table. and is mentioned as :

DEPTNO number(2) REFERENCES DEPT(DEPTNO);
The clause ON DELETE CASCADE added to REFERENCES clause tells Oracle to delete the
dependent rows when we delete the row in the parent table.
Unique Key : If declared, then does not accept duplicate and also NULL values. And can
have many Unique key fields.
Primary Key : Similar to Unique key but, also maintains an index on primary key and also
used to connect two tables.

Write about cursors ?
Implicit (SQL is implicit by default ) and Explicit cursors.
EXIT WHEN C1%NOTFOUND, IF C1%FOUND THEN, IF C1%ISOPEN THEN,
FOR LOOP in CURSOR will :
1) open the cursor.
2) fetches the records from cursor one by one.
3) keeps the track of number of records in the cursor.


Super Dynamism in Cursors is obtained by passing the values as parameters( ie pass by value)

ie., for x in c1(a,b)
Multiple Cursors : These are nothing but nested cursors...........
In Implicit Cursors there is no need of declaration of cursors, by default system will create
a cursor whenever a query is written...and the conditions are like if SQL%NOTFOUND
if SQL%ROWCOUNT > 2 will keep a count of the number of records updated.
SQL is a keyword and cannot be used to name as a cursor name explicitly.

Difference between group functions and single row functions ?
Group Function
Single Row Function
A group function operates
A single row function
on many rows returns one and
result for one row.
returns single result.
Not allowed in Pl/sql procedural Allowed in Pl/Sql Procedural statements
eg SUM(),AVG,MIN,MAX etc
eg UPPER,LOWER,CHR...

Difference between DECODE and TRANSLATE ?
DECODE is value by value
TRANSLATE is character by
character replacement.
replacement.
Ex SELECT DECODE('ABC','A',1,'B',2,'ABC',3) eg SELECT
from dual; o/p 3
TRANSLATE('ABCGH',
'ABCDEFGHIJ', 1234567899)
FROM DUAL; o/p 12378
(DECODE command is used to bring IF,THEN,ELSE logic to SQL.It tests for the IF values(s) and
then aplies THEN value(s) when true, the ELSE value(s) if not.)

Difference between TRUNCATE and DELETE ?
TRUNCATE deletes much faster than DELETE
Truncate
Delete
It is a DDL statement
It is a DML statement
It is a one way trip,cannot
One can Rollback
ROLLBACK
Doesn't have selective features (where clause)
Has
Doesn't fire database triggers
Does
It requires disabling of referential
Does not require
constraints.