Sie sind auf Seite 1von 128

CONSTRAINTS PRIMARY CONSTRAINTS SECONDARY CONSTRAINTS CONSTRAINTS BASED ON : PRIMARY,UNIQUE,CHECK,REFERENCES) : NOT NULL,DEFAULT) 2 LEVELS COLUMN LEVEL and TABLE

LEVEL

Eg. For SECONDARY CONSTRAINTS ~~~~~~~~~~~~~~~~~~~~~~~ 1 NOT NULL CONSTRAINT CREATE TABLE EMP!" ENO NUMBER"#) ENAME VARCHAR2"1$))% 2 DEFAULT CONSTRAINT CREATE TABLE EMP!"ENO NUMBER"#) NOT NULL, ENAME VARCHAR2"1$),DO& DATE DEFAULT SYSDATE)% # PRIMARY CONSTRAINT"COLUMN LEVEL) UNIQUE CREATE TABLE EMP!" ENO NUMBER"#) UNIQUE,ENAME VARCHAR2"1$))% PRIMARY KEY CREATE TABLE EMP!" ENO NUMBER"#) KEY,ENAME VARCHAR2"1$))% ' CHECK CONSTRAINT CREATE TABLE BANK" ACNO NUMBER"2) CONSTRAINT PKBANK PRIMARY KEY,ACTYPE VARCHAR2"2) CONSTRAINT CKBANK CHECK "ACTYPE IN "(SB(,(CA(,(RD()),ACNAME VARCHAR2"1$),AMOUNT NUMBER"'))% ) REFERENCES CREATE TABLE EMP!" ENO NUMBER"#) CONSTRAINT PKE! PRIMARY KEY,&OB VARCHAR2"1$),ENAME VARCHAR2"1$),M*R NUMBER"') REFERENCES EMP!"ENO))% + REFERENCES"REFERIN* TO DIFFERENT TABLE) CREATE TABLE DEPT!"DEPTNO NUMBER"2) CONSTRAINT PKDNO PRIMARY KEY, DNAME VARCHAR2"1$), LOC VARCHAR2"1$))% CREATE TABLE EMP!" EMPNO NUMBER"'),ENAME VARCHAR2"1$), SAL NUMBER",,2),DEPTNO NUMBER"2) CONSTRAINT FKDNO REFERENCES DEPT!"DEPTNO))% CONSTRAINT PKEMP! PRIMARY NOT NULL CONSTRAINT UNIEMP NOT NULL,

TABLE LEVEL CONSTRAINTS UNIQUE TABLE LEVEL

CREATE TABLE BANK" ACNO NUMBER"#),ACTYPE VARCHAR2"1$), BAL NUMBER",,2),PLACE VARCHAR2"1$),CONSTRAINT UNIBANK UNIQUE"ACNO,ACTYPE))% PRIMARY KEY"TABLE LEVEL) CREATE TABLE BANK" ACNO NUMBER"2), ACTYPE VARCHAR2"2) CONSTRAINT CKBANK CHECK "ACTYPE IN "(SB(,(CA(,(RD()),AMOUNT NUMBER) 1 2 # D-./0a1 234 D42a-0. 56 a00 47/05144. 859:-n; -n 234 .a74 D4/a9274n2 a. (FORD( D-./0a1 234 d42a-0. 56 a00 47/05144. 835 a94 <5-n4d =46594 (FORD( D-./0a1 234 Na74. 56 a00 234 47/05144. 835 a94 a00 ;422-n; 234 .a0a91 *94a249 23an 234 .a0a91 56 (SMITH( a05n; 8-23 234 d-66494n>4 -n .a0a91 D-./0a1 a00 234 47/05144. 859:-n; -n >3->a;5

'

SUBQUERIES SIN*LE RO? SUBQUERY MULTIPLE RO? SUBQUERY SIN*LE RO? SUBQUERY 1 DISPLAY THE EMPLOYEES ?HOSE &OB IS SAME AS THAT OF &ONES S404>2 @ 6957 47/ 83494 <5= A ".404>2 <5= 6957 47/ ?3494 4na74 A B<5n4.C)% DISPLAY THE EMPLOYEES BELON*IN* TO MILLER(S DEPARTMENT S404>2 @ 6957 47/ 83494 dna74 A ".404>2 dna74 6957 47/ ?3494 4na74 A B7-049.C)% DISPLAY ALL THE EMPLOYEES REPORTIN* TO KIN* S404>2 @ 6957 47/ 83494 9na74 A ".404>2 9na74 6957 47/ ?3494 4na74 A B:-n;C)% ' DISPLAY ALL THE EMPLOYEES ?HO ARE *ETTIN* MAD SALARY S404>2 @ 6957 47/ 83494 =a.a0 A ".404>2 7aE"=a.a0) 6957 47/)% ) DISPLAY ALL THE DETAILS ?HERE SAL IS *REATER THAN MILLER(S SALARY AND ?HO ARE IN SALES DEPARTMENT

S404>2 @ 6957 47/ 83494 dna74 A B.a04.C and =a.a0 F ".404>2 =a.a0 6957 47/ 83494 4na74 A B7-049.C)%

DISPLAY ALL THE DETAILS ?HO HAVE &OINED IN SAME DATE AS THAT OF &AMES

S404>2 @ 6957 47/ 83494 d5< A ".404>2 d5< 6957 47/ 83494 4na74 A B<a74.C)% MULTIPLE ROW SUBQUERIES , DISPLAY ALL THE DETAILS ?HERE DEPT IS EITHER SALES OR RESEARCH

S404>2 @ 6957 47/ 83494 dna74 A an1".404>2 dna74 6957 47/ 83494 dna74 A B.a04.C 59 dna74 A B94.4a9>3C)% S404>2 @ 6957 47/ 83494 dna74 A an1".404>2 dna74 6957 47/ 83494 Dna74 -n "B.a04.C,C94.4a9>3C))% SUBQUERY RETURNING MULTIPLE COLUMNS SELECT ENAME,&OB,M*R FROM EMP ?HERE "&OB,M*R) IN"SELECT &OB,M*R FROM EMP ?HERE EMPNOA,,GG)%

EXPRESSIONS WITH SUBQUERIES SELECT @ FROM EMP ?HERE SALA"SELECT SALH)$ FROM EMP ?HERE ENAMEA(&ONES()% ROWID 958(. 958: @ @ @ F59 4a>3 958 -n 234 da2a=a.4, 234 RO?ID /.4Id5>50I7n 942I9n. a add94.. RO?ID Ja0I4. >5n2a-n -n6597a2-5n n4>4..a91 25 05>a24 a 83->3 da2a =05>: -n 234 da2a 6-04 83->3 958 -n 234 da2a =05>: "6-9.2 958 -. $) 83->3 da2a 6-04 "6-9.2 6-04 -. 1)

ROWNUM F59 4a>3 958 942I9n4d =1 a KI491, 234 RO?NUM /.4Id5>50I7n 942I9n. a nI7=49 -nd->a2-n; 234 59d49 -n 83->3 O9a>04 .404>2. 234 958 6957 a 2a=04 59 .42 56 <5-n4d 958. T34 6-9.2 958 .404>24d 3a. a RO?NUM O6 1, 234 .4>5nd 3a. 2, and .5 5n CORRELATED SUBQUERY

FIRST TRY USIN* MAD 5TH HIGHEST SALARY SELECT @ FROM EMP A ?HERE )A"SELECT COUNT"DISTINCT SAL)FROM EMP B ?HERE A SALLAB SAL)%

DELETE DUPLICATE DEPARTMENT NUMBERS DELETE FROM EMP A ?HERE RO?ID NOT IN "SELECT MIN"RO?ID) FROM EMP B ?HERE A EMPNOAB EMPNO)% DISPLAY ALTERNATE ROWS SELECT @ FROM EMP ?HERE RO?ID IN "SELECT DECODE"MOD"RO?NUM,2),$,RO?ID) FROM EMP)% TO DISPLAY NTH HIGHEST SALARY

SELECT MAD"SAL) FROM EMP A ?HERE MNA"SELECT COUNT"DISTINCT SAL) FROM EMP B ?HERE A SALLAB SAL)% SELECT @ FROM EMP A ?HERE MNA"SELECT COUNT"DISTINCT SAL) FROM EMP B ?HERE A SALLAB SAL)% DELETE DUPLICATE OCCURENCES DELETE FROM DEPT ?HERE DEPTNO IN"SELECT DEPTNO FROM DEPT *ROUP BY DEPTNO HAVIN* COUNT"DEPTNO)F1)% DELETE FROM 47/ A ?HERE RO?ID NOT IN"SELECT MIN"RO?ID) FROM 47/ ?HERE A DEPTNOAB DEPTNO)% DISPLAY ALTERNATE ROWS SELECT @ FROM *DEPT ?HERE RO?ID IN"SELECT DECODE"MOD"RO?NUM,2),$,RO?ID) FROM *DEPT)% DISPLAY from NTH ROW SELECT @ FROM DEPT ?HERE RO?ID NOT IN"SELECT RO?ID FROM DEPT ?HERE RO?NUMLA"SELECT COUNT"@)NMN FROM DEPT))% DISPLAY DETAILS OF ALL EMPLOYEES WHOSE SAL IS GREATER THAN AVG(SAL) OF EMPLOYEES IN RESPECTIVE DEPTS

SELECT A ENAME,A DEPTNO,A SAL FROM EMP A,EMP B ?HERE B SALF"SELECT AV*"SAL) FROM EMP B *ROUP BY DEPTNO) DISPLAY ALL THE DETAILS WHERE SAL> LOWEST SAL OF EMPLOYEES IN DEPTNO 2 SELECT @ FROM EMP ?HERE SALF ANY"SELECT SAL FROM EMP ?HERE DEPTNOA2$)% SELECT @ FROM EMP ?HERE SALF ANY "SELECT SAL FROM EMP ?HERE DEPTNOA2$)% DISPLAY ALL THE DETAILS WHERE SAL> HIGHEST SAL OF EMPLOYEES IN DEPTNO 2 DECLARE NAME EMP ENAMEOTYPE% SALARY EMP SALOTYPE% DESI* EMP &OBOTYPE:A(M&OB(% BE*IN SELECT ENAME,SAL,&OB INTO NAME,SALARY ,DESI* FROM EMP ?HERE &OBADESI*% DBMSPOUTPUT PUTPLINE"NAMEQQ( (QQSALARYQQ( (QQDESI*)% END% 1 d-./0a1 na74,3-94da24 56 a00 47/05144. I.-n; >I9.59. 2 DISPLAY DETAILS OF ALL EMPLOYEES ?HO ARE CLERKS # DISPLAY DETAILS OF ALL EMPLOYEES ?HEN DEPTNO IS 1$ ' EDAMPLES FOR OFOUND A B C ) @ASSI*NMENT CLERK 2$$RNINCREMENT MANA*ER INSERT TO TEMP ANALYST DELETE SALESMAN AND ANNSALF1)$$$ #$$RN DECREMENT + EDAMPLE FOR OISOPEN , EDAMPLE FOR C1ORO?COUNT ", A, , B)@ d-./0a1 6-9.2 ) 94>59d. G d-./0a1 d42a-0. 56 6-9.2 ) 3-;301 /a-d 47/05144. ! EVEN RO?S 1$ NTH RO? 11 CURSOR USIN* FOR LOOP 12 IF ANNSALF1$$$$ AND &OBACLERK INCOME TAD IS 1$O,IF ANNSALF1)$$$ AND &OBASALESMAN TAD IS 2$O,IF ANNSALF1$$$$ AND &OBAMANA*AER INCOME TAD IS #$O,ELSE A MESSA*E L1$$$$ 1# CURSOR PARAMETERS TO PASS EMPLOYEE NUMBER AND *ET THE DETAILS 1' PASS &OB M *ET THE DETAILS 1) PASS DEPTNO AND &OB AND *ET THE DETIALS 1+ CURSOR LOCKS 1, EDAMPLE FOR IMPLICIT CURSORS 1G INSERT ?ITH IMPLICIT CURSORS 1! UPDATE AND SELECT ?ITH IMPLICIT CURSORS 2$ DELETE ?ITH IMPLICIT CURSORS

21 DISPLAY NAMES OF EMPLOYEES ?ITH SAL IN DESCENDIN* ORDER ?ITHOUT USIN* ORDER BY 22 DISPLAY &OB CATE*ORIES ,COUNT"&OB) AND SUM"SAL) FROM EMP A!"#$r"% &' ()"*+,- !,m$./)r$(,0$ of ,++ $m*+o-$$" 1")!2 31r"or" DECLARE >I9.59 >1 -. .404>2 4na74,3-94da24 6957 47/% na74 Ja9>3a9"2$)% 3da24 da24% 5/4n >1% 055/ 642>3 >1 -n25 na74,3da24% 4E-2 834n >1ONOTFOUND% d=7.P5I2/I2 /I2P0-n4"na74QQ( (QQ3da24)% 4nd 055/% >05.4 >1%

=4;-n

4nd% (VERY IMPORTANT POINT TO BE NOTED IS THAT E4IT WHEN CONDITION IS SATISFIED WHEN THE FETCH RETURNS FALSE AND WE WILL COME OUT OF LOOP WHEN E4IT CONDITION IS TRUE') 5' E4AMPLES FOR DECLARE 6FOUND

>I9.59 >1 -. .404>2 4na74,.a0,DEPTNO 6957 47/ ?HERE DEPTNOA1$% na74 Ja9>3a9"2$)% .0 nI7=49% dn5 nI7=49%

=4;-n

5/4n >1% 055/ 642>3 >1 -n25 na74,.0,dn5 % IF >1On52FOUND THEN DBMSPOUTPUT PUTPLINE"(CURSOR IS NOT FOUND()% 4E-2% 40.-6 >1O65Ind 234n DBMSPOUTPUT PUTPLINE"(FOUND(QQ( (QQC1ORO?COUNT)% NNINSERT INTO TEMP VALUES"NAME,SL,DNO)% END IF% 4nd 055/% >05.4 >1% 4nd% 5 B DECLARE >I9.59 >1 -. .404>2 @ 6957 47/ ?HERE DEPTNOAMd4/2n5% a 47/O95821/4%

=4;-n

5/4n >1% LOOP 642>3 >1 -n25 a% IF >1OFOUND THEN DBMSPOUTPUT PUTPLINE"A ENAMEQQ( (QQA SALQQ( (QQA DEPTNO)% 40.4 EDIT% END IF% END LOOP% >05.4 >1% 4nd% 5 C DECLARE >I9.59 >1 -. .404>2 @ 6957 47/ ?HERE DEPTNOAMd4/2n5% a 47/O95821/4% 5/4n >1%

=4;-n 055/

642>3 >1 -n25 a% IF n52 >1OFOUND THEN 4E-2% 40.4 DBMSPOUTPUT PUTPLINE"a 4na74QQ( (QQa .a0)% END IF% 4nd 055/% >05.4 >1% 4nd% ) CLERK 2$$RNINCREMENT MANA*ER INSERT NAME,SAL TO TEMP ANALYST DELETE SALESMAN AND ANNSALF1)$$$ #$$RN INCREMENT DECLARE CURSOR C1 IS SELECT @ FROM EMP% A C1ORO?TYPE% BE*IN OPEN C1% LOOP FETCH C1 INTO A% EDIT ?HEN C1ONOTFOUND% IF A &OBA(CLERK( THEN UPDATE EMP SET SALAA SALH2$$ ?HERE EMPNOAA EMPNO% COMMIT% ELSIF A &OBA(MANA*ER( THEN DBMSPOUTPUT PUTPLINE"(RO? INSERTED()% INSERT INTO TEMP VALUES"A ENAME,A &OB,A SAL)% COMMIT% ELSIF A &OBA(ANALYST( THEN DBMSPOUTPUT PUTPLINE"(RO? DELETED()% DELETE FROM EMP ?HERE EMPNOAA EMPNO% COMMIT% ELSIF A &OBA(SALESMAN( AND A SAL@12F)$$$ THEN DBMSPOUTPUT PUTPLINE"(RO? SALESMAN UPDATED()% UPDATE EMP SET SALASALH#$$ ?HERE EMPNOAA EMPNO%

COMMIT% ELSE DBMSPOUTPUT PUTPLINE"(NO CHAN*ES()% END IF% END LOOP% CLOSE C1% END% CREATE TABLE TEMP" A VARCHAR2"1$),B VARCHAR2"1$),C NUMBER",,2))% 7' E4AMPLE FOR 6ISOPEN DECLARE CURSOR C1 IS SELECT @ FROM EMP% A C1ORO?TYPE% BE*IN IF C1OISOPEN THEN DBMSPOUTPUT PUTPLINE"(CURSOR ALREADY OPEN()% ELSE DBMSPOUTPUT PUTPLINE"(CURSOR IS YET TO BE OPENED()% OPEN C1% END IF% LOOP FETCH C1 INTO A% EDIT ?HEN C1ONOTFOUND% DBMSPOUTPUT PUTPLINE"A SALQQ( (QQA ENAMEQQ( (QQA &OB)% END LOOP% CLOSE C1% END% 7' B IF NOT C1OISOPEN OPEN C1% ELSE DBMSPOUTPUT PUTPLINE"(CURSOR IS NOT OPEN()% END IF%

8'E4AMPLE FOR C&6ROWCOUNT ()"*+,- f)r"0 5 r$3or(" DECLARE =4;-n >I9.59 >1 -. .404>2 @ 6957 47/% a >1O95821/4% 5/4n >1% 055/ 642>3 >1 -n25 a%

4nd%

4E-2 834n >1O958>5In2F+% d=7.P5I2/I2 /I2P0-n4"a 4na74QQ( (QQa .a0QQ( (QQa <5=QQ( (QQC1ORO?COUNT)% 4nd 055/% >05.4 >1%

8 B o0/$r m$0/o( for ,9o:$ *2m DECLARE >I9.59 >1 -. .404>2 @ 6957 47/% a >1O95821/4% =4;-n 5/4n >1% 055/ 642>3 >1 -n25 a% 4E-2 834n >1On5265Ind% -6 >1O958>5In2LA+ 234n d=7.P5I2/I2 /I2P0-n4"a 4na74QQ( (QQa .a0QQ( (QQa <5=)% 4nd -6% 4nd 055/% >05.4 >1%

4nd% ; ()"*+,- ($0,)+" of f)r"0 5 /)2/+- *,)( $m*+o-$$" DECLARE =4;-n >I9.59 >1 -. .404>2 @ 6957 47/ 59d49 =1 .a0 d4.>% a >1O95821/4% 5/4n >1% 055/ 642>3 >1 -n25 a% 4E-2 834n >1O958>5In2F+% d=7.P5I2/I2 /I2P0-n4"a 4na74QQ( (QQa .a0QQ( (QQa <5=QQ( (QQC1ORO?COUNT)% 4nd 055/% >05.4 >1% 4nd% <' ()"*+,- o!+- $:$! ro#" DECLARE =4;-n >I9.59 >1 -. .404>2 @ 6957 47/ % a >1O95821/4% 5/4n >1% 055/ 642>3 >1 -n25 a% 4E-2 834n >1On5265Ind% -6 75d">1O958>5In2,2)A$ 234n d=7.P5I2/I2 /I2P0-n4"a 4na74QQ( (QQa .a0QQ( (QQa <5=)% 4nd -6% 4nd 055/% >05.4 >1%

4nd%

(for odd ro ! "#$%g& ' (o )*+ & ()"*+,- !0/ ro# >I9.59 >1 -. .404>2 @ 6957 47/ % a >1O95821/4% n nI7=49%

DECLARE

=4;-n n:AMn% 5/4n >1% 055/ 642>3 >1 -n25 a% 4E-2 834n >1On5265Ind% -6 >1O958>5In2An 234n d=7.P5I2/I2 /I2P0-n4"a 4na74QQ( (QQa .a0QQ( (QQa <5=)% 4nd -6% 4nd 055/% >05.4 >1% 4nd% && 31r"or 1")!2 for +oo*

d4>0a94 >I9.59 >2 -. .404>2 @ 6957 47/% =4;-n 659 a -n >2 055/ d=7.P5I2/I2 /I2P0-n4"a 4na74QQ( (QQa .a0QQ( (QQa <5=)% 4nd 055/% 4nd% &2' IF ANNSAL>& AND =OB>CLER? INCOME TA4 IS & 6.IF ANNSAL>&5 AND =OB>SALESMAN TA4 IS 2 6.IF ANNSAL>& AND =OB>MANAGAER INCOME TA4 IS @ 6.ELSE A MESSAGE A& a0249 2a=04 47/ add"-2 nI7=49"#))% d4>0a94 >I9.59 >1 -. .404>2 @ 6957 EMP% a >1O95821/4% =4;-n 5/4n >1% 055/ 642>3 >1 -n25 a% 4E-2 834n >1On5265Ind% -6 a .a0@12F1$$$$ and a <5=A(CLERK( THEN UPDATE EMP SET ITAA SAL@12@$ 1 ?HERE EMPNOAA EMPNO% ELSIF A SAL@12F1)$$$ AND A &OB A(SALESMAN( THEN UPDATE EMP SET ITAA SAL@12@$ 2 ?HERE EMPNOAA EMPNO% ELSIF A SAL@12F1$$$$ AND A &OBA(MANA*ER( THEN UPDATE EMP SET ITAA SAL@12@$ # ?HERE EMPNOAA EMPNO% ELSIF A SAL@12L1$$$$ THEN DBMSPOUTPUT PUTPLINE"A ENAMEQQ( (QQ(SALL 1$$$$()% END IF% END LOOP% COMMIT% CLOSE C1% END%

&@

CURSOR PARAMETERS TO PASS EMPLOYEE NUMBER AND GET THE DETAILS

DECLARE CURSOR C1" S NUMBER) IS SELECT @ FROM EMP ?HERE DEPTNOAS% A C1ORO?TYPE% BE*IN OPEN C1"MDEPTNO)% LOOP FETCH C1 INTO A% EDIT ?HEN C1ONOTFOUND% DBMSPOUTPUT PUTPLINE"A ENAMEQQ( (QQA DEPTNOQQ( (QQA SAL)% END LOOP% CLOSE C1% END% &5 TO PASS =OB AND GET THE DETAILS DECLARE CURSOR C1" A VARCHAR) IS SELECT @ FROM EMP ?HERE &OBAA% A C1ORO?TYPE% BE*IN OPEN C1"(MA&OB()% LOOP FETCH C1 INTO A% EDIT ?HEN C1ONOTFOUND% DBMSPOUTPUT PUTPLINE"A &OBQQ( (QQA ENAMEQQ( (QQA EMPNOQQ( QQA SAL)% END LOOP% CLOSE C1% END% NOTE %)0 #)++ !o0 0,B$ Co9 )! 1**$r3,"$ "o 1**$r(Co9)>1**$r(,)

&5' TO PASS DESIGNATION AND DEPTNO AND GET THE DETAILS DECLARE CURSOR C1"A NUMBER,B VARCHAR) IS SELECT @ FROM EMP ?HERE DEPTNOAA AND &OBAB% A C1ORO?TYPE% BE*IN OPEN C1"MADETNO,(MB&OB()% LOOP FETCH C1 INTO A% EDIT ?HEN C1ONOTFOUND% DBMSPOUTPUT PUTPLINE"A ENAMEQQ( (QQA &OBQQ( (QQA SALQQ( QQA DEPTNO)% END LOOP% CLOSE C1% END%

&7 CURSOR LOC?ING DECLARE CURSOR C1 IS SELECT @ FROM EMP FOR UPDATE OF SAL% A C1ORO?TYPE% BE*IN OPEN C1% LOOP FETCH C1 INTO A% EDIT ?HEN C1ONOTFOUND% DBMSPOUTPUT PUTPLINE"A &OBQQ( (QQA ENAMEQQ( (QQA SALQQ( A DEPTNO)% IF A &OBA(CLERK( THEN UPDATE EMP SET &OBA(FDC( ?HERE 47/n5Aa 47/n5% 4nd -6% 4nd 055/% >05.4 >1% 4nd% &8 E4AMPLE FOR IMPLICIT CURSORS

(QQ

DECLARE CURSOR C1 IS SELECT @ FROM EMP% A C1ORO?TYPE% BE*IN OPEN C1% LOOP FETCH C1 INTO A% EDIT ?HEN C1ONOTFOUND% DBMSPOUTPUT PUTPLINE"C1ORO?COUNTQQ( (QQSQLORO?COUNTQQ( (QQA ENAME)% END LOOP% CLOSE C1% END% (YOU WILL NOT GET THE OUTPUT BECAUSE SQL,ROWCOUNT WILL RETURN A -ALUE ONLY WHEN THE PRE-IOUS DML OPERATION IS SUCCESSFULLY COMPLETLE* &;' IMPLICIT CURSOR WITH INSERT CREATE TABLE TEMP"A VARCHAR2"1$),B NUMBER",,2), C VARCHAR2"1$))% DECLARE CURSOR C2 IS SELECT @ FROM EMP% A C2ORO?TYPE% BE*IN OPEN C2% LOOP FETCH C2 INTO A% EDIT ?HEN C2ONOTFOUND% INSERT INTO TEMP VALUES"A ENAME,A SAL,A &OB)% IF SQLOFOUND THEN DBMSPOUTPUT PUTPLINE"SQLORO?COUNTQQ( (QQC2ORO?COUNTQQ( (QQ A SALQQ( (QQA ENAME)% ELSE EDIT% END IF % END LOOP%

CLOSE C2% END% &< DELETE WITH IMPLICIT CURSORS

DECLARE BE*IN DELETE FROM EMP ?HERE DEPTNOA1$% DBMSPOUTPUT PUTPLINE"SQLORO?COUNT)% END% 2 ' UPDATE AND SELECT WITH IMPLICIT CURSORS

DECLARE A EMPORO?TYPE% BE*IN SELECT @ INTO A FROM EMP ?HERE EMPNOA,,GG% DBMSPOUTPUT PUTP0INE"(AFTER SELECT SQLCOUNT(QQ ( (QQSQLORO?COUNT)% UPDATE EMP SET DEPTNOA!! ?HERE DEPTNOA1$% DBMSPOUTPUT PUTP0INE"(AFTER UPDATE SQLCOUNT(QQ ( (QQSQLORO?COUNT)% END% OUTPUT IS AFTER SELECT SQLCOUNT 1 AFTER UPDATE SQLCOUNT # 2&'DISPLAY NAMES OF EMPLOYEES WITH SAL IN DESCENDING ORDER WITHOUT USING ORDER BY DECLARE CURSOR C1 IS SELECT @ FROM EMP% A C1ORO?TYPE% N NUMBER% BE*IN OPEN C1% SELECT MAD"SAL) INTO N FROM EMP% LOOP FETCH C1 INTO A% EDIT ?HEN C1ONOTFOUND% DBMSPOUTPUT PUTPLINE"N)% SELECT MAD"SAL) INTO N FROM EMP ?HERE SALLN% END LOOP% CLOSE C1% END% 22'DISPLAY =OB CATEGORIES .COUNT(=OB) AND SUM(SAL) FROM EMP DECLARE CURSOR C1 IS SELECT &OB,COUNT"&OB) DY ,SUM"SAL) AB FROM EMP *ROUP BY &OB% A C1ORO?TYPE% BE*IN OPEN C1% LOOP FETCH C1 INTO A% EDIT ?HEN C1ONOTFOUND%

DBMSPOUTPUT PUTPLINE"(PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP( )% DBMSPOUTPUT PUTPLINE"( &OB (QQ( NUMBER (QQ( SUM OF SAL ()% DBMSPOUTPUT PUTPLINE"A &OBQQ( (QQ A DY QQ( (QQ A AB)% END LOOP% CLOSE C1% END% DECLARE CURSOR T1 IS SELECT @ FROM TEST1% TESTPREC T1ORO?TYPE% BE*IN FOR TEST IN T1 LOOP UPDATE TEST1 SET AREAA'$$ ?HERE RADIUSA)$% IF SQLORO?COUNT F$ THEN DBMSPOUTPUT PUTPLINE"(RECORD IS ALREADY EDISTS()% ELSE DBMSPOUTPUT PUTPLINE"(THERE IS NO RECORD()% END IF% END LOOP% END% DECLARE RDA AREAS RADIUSOTYPE% BE*IN SELECT RADIUS INTO RDA FROM AREAS ?HERE RADIUS A#')% EDCEPTION ?HEN NOPDATAPFOUND THEN DBMSPOUTPUT PUTPLINE"(RECORD NOT FOUND()% END% D,0,9,"$ o9C$30" TABLES,VIE?S,SYNONYM,INDED,CLUSTER,SEQUENCE,PROCEDURE,FUNCTION PACKA*E,TRI**ER VIEWS V-92Ia0 2a=04 >3an;4. 94604>24d -n 2a=04 M J->4J49.a n5 da2a 56 -2. 58n, n5 94dIndan>1 and .4>I9-21 A 05;->a0 2a=04 =a.4d 5n 5n4 59 7594 2a=04. 59 J-48. 1 CREATE VIE? EV AS SELECT @ FROM EMP% 2 CREATE VIE? EV1 AS SELECT ENAME,EMPNO,DEPTNO FROM EMP% # CREATE VIE? EV2"EMPNO,SALARY) AS SELECT EMPNO,SAL FROM EMP% ' CREATE VIE? EM1 AS SELECT ENAME,SAL,DEPTNO,EMPNO,&OB FROM EMP ?HERE DEPTNOA2$% READ ONLY -IEW VIE?S ?ITH *ROUP BY,ORDER BY ,A** , PRIMARY KEY AND CHECK CONSTRAINTS THE VIE? BECOMES A READ ONLY VIE?

1 2

CREATE VIE? EV AS SELECT DEPTNO,COUNT"@) COUNT FROM EMP *ROUP BY DEPTNO% CREATE VIE? EM1 AS SELECT ENAME,SAL,DEPTNO,EMPNO,&OB FROM EMP ?HERE DEPTNOA2$ ?ITH CHECK OPTION CONSTRAINT CK1%

FORCED VIEWS CREATE FORCE VIE? ABC AS SELECT EMPNO,ENAME,SAL FROM EMPOP% SEE THE VIEWS SELECT @ FROM LJ-48 na74F% DROP VIE? ABC% SELECT @ FROM USERPVIE?% CREATE VIE? MA* AS SELECT M MNO,M NAME,MA *P,MA NP FROM MA*I M,MA* MA % SYNONYMS A .1n5n17 -. an a0249na2-J4 na74 659 a 2a=04,J-48, .4KI4n>4, /95>4dI94, .2594d 6In>2-5n 1) PI=0-> .1n5n17 2) P9-Ja24 .1n5n17 CREATE SYNONYM T FOR EMP% CREATE PUBLIC SYNONYM VV FOR EMP% DROP SYNONYM T% SELECT @ FROM USERPSYNONYMS ?HERE TABLEPNAMEA(EMP(% INDE4ES An -nd4E -. a da2a=a.4 5=<4>2 23a2 >5n2a-n. an 4n291 659 4a>3 Ja0I4 23a2 a//4a9. -n 234 -nd4E4d >50I7n".) 56 234 2a=04 59 >0I.249 and /95J-d4. d-94>2, 6a.2 a>>4.. 25 958. PRIMARY ?EY AUTOMATICALLY INDE4ED HAS ITS EFFECT ON LARGER TABLES CREATE INDED AB ON EMP"EMPNO)% SELECT @ FROM USERPINDEDES ?HERE TABLEPNAMEA(EMP(% IF YOU ?ANT TO INDED A PRIMARY KEY COLUMN FIRST &UST DISABLE IT DROP INDED AB% SEDUENCES A .4KI4n>4 -. a da2a=a.4 5=<4>2 6957 83->3 7I02-/04 I.49. 7a1 ;4n49a24 In-KI4 -n24;49. Y5I >an I.4 .4KI4n>4. 25 aI257a2->a001 ;4n49a24 /9-7a91 :41 Ja0I4.

1 CREATE 2 CREATE MINVALUE # CREATE MINVALUE ' CREATE MINVALUE

SEQUENCE S1 INCREMENT SEQUENCE S) INCREMENT ) CYCLE CACHE 2% SEQUENCE S) INCREMENT U) CYCLE CACHE 2% SEQUENCE S+ INCREMENT U' CYCLE CACHE 2%

BY 1$ START ?ITH 1$ MADVALUE )$ BY 1$ START ?ITH 1$ MADVALUE )$ BY U2 START ?ITH 1$ MADVALUE 2$ BY U2 START ?ITH + MADVALUE 2$

SELECT @ FROM USERPSEQUENCES ?HERE TABLEPNAMEA(EMP(% DROP SEQUENCE S+%

CLUSTERS A >0I.249 -. a .>347a 5=<4>2 23a2 >5n2a-n. 5n4 59 7594 2a=04. 23a2 a00 3aJ4 5n4 59 7594 >50I7n. -n >5775n 1 2 # ' >94a24 >0I.249 >''"d4/2n5 nI7=49)% >94a24 2a=04 EMPC''"En5 nI7=49"!),d4/2n5 nI7=49, SAL NUMBER",,2),HIREDATE DATE)>0I.249 >''"d4/2n5)% >94a24 2a=04 DMPC''"d4/2n5 nI7=49,DNAME VARCHAR2"1$), LOC VARCHAR2"1$))>0I.249 >''"d4/2n5)% >94a24 -nd4E >1- 5n >0I.249 >'%

03+ 3omm,!(" ;9an2, 94J5:4 2r,!0 *r):)+$2$ o! 0,9+$!,m$ 0o 1"$r!,m$ (PRIVILEGES THAT CAN BE GRANTED ARE SELECT . UPDATE. DELETE. INSERT ALTER.REFERENCE.INDE4) 1 2 *RANT SELECT ON EMP TO SAVITHA *RANT SELECT ON EMP TO SAVITHA ?ITH *RANT OPTION REVOKE ALL ON EMP FROM *EETHA%

COMMIT. ROLLBAC? . SAVEPOINT SQLF SELECT @ FROM DEPT% DEPTNO NNNNNNNNN 1$ 2$ #$ '$ )$ DNAME NNNNNNNNNNNNNN ACCOUNTIN* RESEARCH SALES OPERATIONS CS LOC NNNNNNNNNNNNN NE? YORK DALLAS CHICA*O BOSTON MYSORE

SQLF SAVEPOINT A

SaJ4/5-n2 >94a24d SQLF INSERT INTO DEPT VALUES"+$,(IP(,(BAN*ALORE()% 1 958 >94a24d SQLF SAVEPOINT B%

SaJ4/5-n2 >94a24d SQLF INSERT INTO DEPT VALUES",$,(IT(,(*OA()%

1 958 >94a24d SQLF SELECT @ FROM DEPT% DEPTNO NNNNNNNNN 1$ 2$ #$ '$ )$ +$ ,$ DNAME NNNNNNNNNNNNNN ACCOUNTIN* RESEARCH SALES OPERATIONS CS IP IT LOC NNNNNNNNNNNNN NE? YORK DALLAS CHICA*O BOSTON MYSORE BAN*ALORE *OA

, 958. .404>24d SQLF ROLLBACK TO SAVEPOINT B% R500=a>: >57/0424 SQLF SELECT @ FROM DEPT% DEPTNO NNNNNNNNN 1$ 2$ #$ '$ )$ +$ DNAME NNNNNNNNNNNNNN ACCOUNTIN* RESEARCH SALES OPERATIONS CS IP LOC NNNNNNNNNNNNN NE? YORK DALLAS CHICA*O BOSTON MYSORE BAN*ALORE

+ 958. .404>24d

Tr.gg&r!:

A da2a=a.4 29-;;49 -. a .2594d PLRSQL /95;9a7 In-2 a..5>-a24d 8-23 a ./4>-6-> da2a=a.4 2a=04 O9a>04 4E4>I24. "6-94.) 234 da2a=a.4 29-;;49 aI257a2->a001 834n4J49 a ;-J4n SQL 5/49a2-5n a664>2. 234 2a=04 S5,In0-:4 .I=/95;9a7., 83->3 7I.2 =4 -nJ5:4d 4E/0->-201, da2a=a.4 29-;;49. a94 -nJ5:4d -7/0->-201 A75n; 52349 23-n;., 15I >an I.4 da2a=a.4 29-;;49. 25 aId-2 da2a 75d-6->a2-5n. 05; 4J4n2. 29an./a94n201 4n659>4 >57/04E =I.-n4.. 9I04. d49-J4 >50I7n Ja0I4. aI257a2->a001 -7/0474n2 >57/04E .4>I9-21 aI2359-Sa2-5n. 7a-n2a-n 94/0->a24 2a=04. CREATE TRI**ER L29-;;49na74F AFTER UPDATERINSERTRDELETE LCOLUMN NAMEF ON LTABLENAMEF FOR EACH RO? BE*IN NNNNN NNNNN 4E4>I2a=04 .2a2474n2.% NNNNN NNNNN END% DATABASE TRIGGERS OF

1 2 # ' ) + , G

?RITE A DATABASE TRI**ER ?HICH ?ILLN(T ALLO? THE USER TO INSERT,UPDATE OR DELETE BET?EEN NI*HT , AND MORNIN* + ?RITE A DATABASE TRI**ER ?HICH FIRES IF YOU TRY TO INSERT , UPDATE OR DELETE AFTER ,(O( CLOCK ?RITE A DATABASE TRI**ER BEFORE INSERTIN* VALUES ON TO EMP TABLE IF DEPTNO DOES NOT EDIST IN DEPT THEN RAISE THE ERROR ?RITE A DATABASE TRI**ER TO ILLUSTRATE TABLE LEVEL AND RO? LEVEL TRI**ERS ?RITE A DATABASE TRI**ER ?HICH ACTS &UST LIKE PRIMARY KEY AND DOES NOT ALLO? DUPLICATE VALUE CREATE A DATABASE TRI**ER ?HICH PERFORMS THE ACTION OF THE ON DELETE CASCADE% ?RITE A DATABASE TRI**ER TO INSERT DISTINCT EMPLOYEE NUMBER TO EMP TABLE "BEFORE INSERT) ?RITE A DATABASE TRI**ER TO UPDATE THE SAL FIELD IF SAL IS MORE THAN )$$$ OR LESS THAN 1$$$ THEN RAISE THE ERROR "BEFORE UPDATE) ?RITE A DATABASE TRI**ER ?HERE ?HEN CONDITION IS SPECIFIED ?HEN &OB IS MANA*ER THEN CHECK FOR SALARY IF SAL IS L1$$$ THEN RAISE THE ERROR ?RITE A DATABASE TRI**ER ?HICH SHOULD NOT DELETE FROM EMP TABLE IF THE DAY IS SUNDAY ?RITE A DATABASE TRI**ER ?HICH SHOULD NOT ALLO? US TO UPDATE IF ?E ARE DOIN* TRANSACTIONS IN LAST DAY OF THE MONTH ?RITE A DATABASE TRI**ERS ?HICH INSERTS THE EMPNO AND DEPTNO INTO TEMP TABLE"AFTER INSERT) ?RITE A DATABASE TRI**ER USIN* INSERTIN* AND UPDATIN* ?E SHOULD NOT INSERT ON SUNDAY AND ?E SHOULD NOT UPDATE ON LAST DAY OF THE MONTH UPDATE EMP TABLE AND CHAN*E OLD DEPTNO TO NE? DEPTNO IF OLD DEPTNO IS 2$ THEN DELETE FROM DEPT ?HERE DEPTNO IS EQUAL TO NE? DEPTNO ?RITE A DATABASE TRI**ER TO DELETE FROM DEPT TABLE INSERT THE OLD VALUES TO A TABLE AFTER DELETIN*

1$ 11 12 1# 1' 1) 1+ 1,

?RITE A DATABASE TRI**ER ?HICH SHOULD NOT DELETE THE RO? IF THE MONTH IS APRIL ?RITE A DATABASE TRI**ER ?HICH FIRES BEFORE PERFORMIN* INSERT OR UPDATE OPERATIONS IF THE &OB IS MANA*ER THEN HIS SALARY SHOULD BE IN THE *RADE ) ELSE RAISE THE APPLICATION ERROR

&' WRITE A DATABASE TRIGGER WHICH WILLNET ALLOW THE USER TO INSERT.UPDATE OR DELETE BETWEEN NIGHT 8 AND MORNING 7

CREATE OR REPLACE TRI**ER *EETIME BEFORE INSERT OR UPDATE OR DELETE ON EMP 659 4a>3 958 DECLARE A VARCHAR2"1$)% BE*IN NN.404>2 25P>3a9".1.da24,(332'() -n25 a 6957 dIa0% A:ATOPCHAR"SYSDATE,(HH2'()% IF TOPNUMBER"A) F 1! OR TOPNUMBER"A) L , 234n RAISEPAPPLICATIONPERROR"N2$)$$,(YOU CANT DO THIS OPERATION NO?()% END IF% END% 2'WRITE A DATABASE TRIGGER WHICH DELETE AFTER 8EOE CLOC? FIRES IF YOU TRY TO INSERT .UPDATE OR

CREATE OR REPLACE TRI**ER *EETIME BEFORE INSERT OR UPDATE OR DELETE ON EMP 659 4a>3 958 DECLARE A VARCHAR2"1$)% BE*IN SELECT TOPCHAR"SYSDATE,(HH:MI() INTO A FROM DUAL% IF A F ($+:$$( 234n RAISEPAPPLICATIONPERROR"N2$)$$,(YOU CANT DO THIS OPERATION NO?()% END IF% END% 2'WRITE A DATABASE TRIGGER BEFORE INSERTING VALUES ON TO EMP TABLE IF DEPTNO DOES NOT E4IST IN DEPT THEN RAISE THE ERROR' CREATE OR REPLACE TRI**ER IEMP BEFORE INSERT ON EMP FOR EACH RO? DECLARE A NUMBER% BE*IN SELECT COUNT"@) INTO A FROM DEPT ?HERE DEPTNOA:NE? DEPTNO% IF AA$ THEN RAISEPAPPLICATIONPERROR"N2$#$$,(PARENT KEY IS NOT EDISTIN*()% ELSE PRINT"(RECORD IS ALREADY INSERTED()% END IF% END% OUTPUT OF THE DUERY IS AS BELOW SQLF INSERT INTO EMP"EMPNO,DEPTNO) VALUES"2#,'')% INSERT INTO EMP"EMPNO,DEPTNO) VALUES"2#,'') @ ERROR a2 0-n4 1: ORAN2$#$$: PARENT KEY IS NOT EDISTIN* ORAN$+)12: a2 V*EETHA IEMPV, 0-n4 +

ORAN$'$GG: 49959 dI9-n; 4E4>I2-5n 56 29-;;49 (*EETHA IEMP( @'WRITE A DATABASE TRIGGER TO ILLUSTRATE TABLE LEVEL AND ROW LEVEL TRIGGERS' CREATE OR REPLACE TRI**ER UPTABLE BEFORE I/da24 ON EMP BE*IN DBMSPOUTPUT PUTPLINE"(UPDATE ON TABLE IS FIRED()% END% CREATE OR REPLACE TRI**ER UPRO? BEFORE UPDATE ON EMP FOR EACH RO? BE*IN DBMSPOUTPUT PUTPLINE"(UPDATE ON RO? IS FIRED()% END% 5'WRITE A DATABASE TRIGGER WHICH ACTS =UST LI?E PRIMARY ?EY AND DOES NOT ALLOW DUPLICATE VALUES CREATE OR REPLACE TRI**ER PRIKEY BEFORE INSERT ON EMP FOR EACH RO? DECLARE A NUMBER% BE*IN SELECT COUNT"@) INTO A FROM EMP ?HERE EMPNOA:NE? EMPNO% IF A FA1 THEN RAISEPAPPLICATIONP4RROR"N2$)$$,(THE PRI KEY RULE IS VOILATED()% ELSIF AA$ THEN PRINT"(RECORD IS INSERTED()% END IF% END% SQLF INSERT INTO EMP"EMPNO,DEPTNO) VALUES",,GG,2$)% INSERT INTO EMP"EMPNO,DEPTNO) VALUES",,GG,2$) @ ERROR a2 0-n4 1: ORAN2$)$$: THE PRI KEY RULE IS VOILATED ORAN$+)12: a2 V*EETHA PRIKEYV, 0-n4 + ORAN$'$GG: 49959 dI9-n; 4E4>I2-5n 56 29-;;49 (*EETHA PRIKEY( SQLF INSERT INTO EMP"EMPNO,DEPTNO) VALUES",,,2$)%

1 958 >94a24d 5' CREATE A DATABASE TRIGGER WHICH PERFORMS THE ACTION OF THE ON DELETE CASCADEF CREATE OR REPLACE TRI**ER DELDEPT AFTER DELETE ON DEPT FOR EACH RO? BE*IN DELETE FROM EMP ?HERE DEPTNOA:OLD DEPTNO%

PRINT"(RECORDS IN EMP ARE ALSO DELETED()% END% 7'WRITE A DATABASE TRIGGER TO INSERT DISTINCT EMPLOYEE NUMBER TO EMP TABLE (BEFORE INSERT) CREATE OR REPLACE TRI**ER PRIMPUNIQUE BEFORE INSERT ON 47/ FOR EACH RO? DECLARE NO NUMBER% BE*IN SELECT NVL"MAD"EMPNO),$)H1 INTO NO FROM EMP% :NE? EMPNO:ANO% END% 8'WRITE A DATABASE TRIGGER TO UPDATE THE SAL FIELD'IF SAL IS MORE THAN 5 OR LESS THAN & THEN RAISE THE ERROR'(BEFORE UPDATE)' CREATE OR REPLACE TRI**ER CHECKPSAL BEFORE I/da24 FOR EACH RO? BE*IN -6 :n48 .a0 L1$$$ 59 :n48 .a0F)$$$ 234n 9a-.4Pa//0->a2-5nP49959"N2$$$1,(>34>: .a0 ()% 4nd -6% END% ON 47/

;'WRITE A DATABASE TRIGGER WHERE WHEN CONDITION IS SPECIFIED' WHEN =OB IS MANAGER THEN CHEC? FOR SALARY' IF SAL IS A& THEN RAISE THE ERROR' CREATE OR REPLACE TRI**ER EMPNOPCHECK BEFORE INSERT ON 47/ FOR EACH RO? 834n "NE? <5=A(MANA*ER() BE*IN -6 :n48 SALL1$$$ THEN 9a-.4Pa//0->a2-5nP49959"N2$$$1,(PLEASE INCREASE THE SALARY ()% 4nd -6%

END%

<'WRITE A DATABASE TRIGGER WHICH SHOULD NOT DELETE FROM EMP TABLE IF THE DAY IS SUNDAY' CREATE OR REPLACE TRI**ER EMPNOPCHECK BEFORE DELETE ON 47/ BE*IN -6 25P>3a9".1.da24,(dA1()A(SUNDAY( 234n 9a-.4Pa//0->a2-5nP49959"N2$$$1,(TO DAY IS SUNDAY 4nd -6% END%

()%

& 'WRITE A DATABASE TRIGGER WHICH SHOULD NOT ALLOW US TO UPDATE IF WE ARE DOING TRANSACTIONS IN LAST DAY OF THE MONTH CREATE OR REPLACE TRI**ER EMPNOPCHECK BEFORE UPDATE ON 47/ BE*IN

END%

-6 25P>3a9".1.da24)ALASTPDAY"SYSDATE) 234n 9a-.4Pa//0->a2-5nP49959"N2$$$1,(TO DAY IS LAST DAY OF MONTH()% 4nd -6%

&&'WRITE A DATABASE TRIGGERS WHICH INSERTS THE EMPNO AND DEPTNO INTO TEMP TABLE(AFTER INSERT) CREATE OR REPLACE TRI**ER AFTERPINS AFTER INSERT ON 47/ FOR EACH RO? BE*IN INSERT INTO TEMP"EMPNO,DEPTNO)VALUES":NE? EMPNO,:NE? DEPTNO)% END% &2'WRITE A DATABASE TRIGGER USING INSERTING AND UPDATING WE SHOULD NOT INSERT ON SUNDAY AND WE SHOULD NOT UPDATE ON LAST DAY OF THE MONTH' CREATE OR REPLACE TRI**ER EMPNOPCHECK BEFORE INSERT OR UPDATE ON 47/ FOR EACH RO? BE*IN IF INSERTIN* THEN -6 25P>3a9".1.da24,(d1()A(75n( 234n 9a-.4Pa//0->a2-5nP49959"N2$$$1,(TO DAY IS SUNDAY 4nd -6% 4nd -6% IF UPDATIN* THEN -6 25P>3a9".1.da24)ALASTPDAY"SYSDATE) 234n 9a-.4Pa//0->a2-5nP49959"N2$$$1,(TO DAY IS MONTHY LAST DAY .5 n5 I/da2-n; ()% 4nd -6% END IF% END%

()%

&@'UPDATE EMP TABLE AND CHANGE OLD DEPTNO TO NEW DEPTNO' IF OLD DEPTNO IS 2 THEN DELETE FROM DEPT WHERE DEPTNO IS EDUAL TO NEW DEPTNO CREATE OR REPLACE TRI**ER AFTERPUPDATE AFTER UPDATE ON EMP FOR EACH RO? BE*IN IF :OLD DEPTNOA2$ THEN DELETE FROM DEPT ?HERE DEPTNOA:NE? DEPTNO% END IF% END% &5'WRITE A DATABASE TRIGGER TO DELETE FROM DEPT TABLE 'AFTER DELETING INSERT THE OLD VALUES TO A TABLE' CREATE OR REPLACE TRI**ER AFTERPd40424 AFTER d40424 ON DEPT

BE*IN END%

FOR EACH RO? -n.492 -n25 d4/21 Ja0I4.":50d d4/2n5,:50d dna74,:50d 05>)%

&5'WRITE A DATABASE TRIGGER WHICH SHOULD NOT DELETE THE ROW IF THE MONTH IS APRIL' CREATE OR REPLACE TRI**ER 75n23PCHECK BEFORE DELETE ON 47/ -6 25P>3a9".1.da24,(75n23()A(<I01( 234n 9a-.4Pa//0->a2-5nP49959"N2$$$1,(23-. 75n23 -. 350-da1 4nd -6% ()%

BE*IN

END%

&7'WRITE A DATABASE TRIGGER WHICH FIRES BEFORE PERFORMING INSERT OR UPDATE OPERATIONS' IF THE =OB IS MANAGER THEN HIS SALARY SHOULD BE IN THE GRADE 5'ELSE RAISE THE APPLICATION ERROR' >94a24 59 94/0a>4 29-;;49 <5=;9ad4 =46594 -n.492 59 I/da24 56 &OB,SAL 5n 47/ 659 4a>3 958 834n "n48 <5=A(MANA*ER() d4>0a94 05 nI7=49% 3- nI7=49% =4;-n .404>2 05.a0,3-.a0 -n25 05,3- 6957 .a0;9ad4 83494 ;9ad4A)% -6 :n48 .a0F05 and :n48 .a0L3- 234n /9-n2"(-n.492 .I>>4..()% 40.4 9a-.4Pa//0->a2-5nP49959"N2$)$$,(IN.492 5/49a2-5n n52 a00584d()% 4nd -6% 4nd%

E4TRA INFORMATION FOR MISS'MG >94a24 59 94/0a>4 29-;;49 da1. =46594 d40424 5n 47/ d4>0a94 a nI7=49:A25PnI7=49"25P>3a9".1.da24,(d()) % dI771 Ja9>3a9"2$)% =4;-n -6 NOT a -n"1,+) 234n 9a-.4Pa//0->a2-5nP49959"N2$$$2,(25da1 n5 29an.a>2-5n()% 40.4 =4;-n .404>2 I.49 -n25 dI771 6957 dIa0% -6 dI771 LF(;4423a( 234n

9a-.4Pa//0->a2-5nP49959"N2$$$',(NOT A PROPER USER()% 40.4 d="(a /95/49 I.49 ()% 4nd -6% 4nd -6% 4nd% 4nd%

d4>0a94 dI771 Ja9>3a9"2$)% =4;-n .404>2 I.49 -n25 dI771 6957 dIa0% -6 dI771 LF(*EETHA( 234n 9a-.4Pa//0->a2-5nP49959"N2$$$2,(25da1 n5 29an.a>2-5n()% 40.4 d="(a /95/49 I.49 ()% 4nd -6% 4E>4/2-5n 834n n5Pda2aP65Ind 234n d="(n5 da2a 65Ind()% 4nd% CREATE OR REPLACE TRI**ER T2 BEFORE INSERT ON EMP FOR EACH RO? DECLARE A NUMBER% BE*IN SELECT COUNT"@) INTO A FROM EMP ?HERE DEPTNOA:NE? DEPTNO% IF AFA1 THEN RAISEPAPPLICATIONPERROR"N2$1$1,(PRIMARY KEY VIOLATION()% ELSE DBMSPOUTPUT PUTPLINE"(VALUE INSERTED()% END IF% END% CREATE OR REPLACE TRI**ER DELDEPT AFTER DELETE ON DEPT FOR EACH RO? BE*IN DELETE EMP ?HERE DEPTNOA:OLD DEPTNO% DBMSPOUTPUT PUTPLINE"(SDFSDF()% END% CREATE OR REPLACE TRI**ER CHECKPSAL BEFORE I/da24 ON 47/ FOR EACH RO? BE*IN -6 :n48 .a0 L1$$$ 59 :n48 .a0F)$$$ 234n 9a-.4Pa//0->a2-5nP49959"N2$$$1,(>34>: .a0 ()% 4nd -6% END% EDCEPTION NNNNNNNNN PRENDEFINED : NNNNNNNNNNN NOPDATAPFOUND

TOOPMANYPRO?S VALUEPERROR INVALIDPNUMBER CURSORPALREADYPOPEN INVALIDPCURSOR TEROPERROR STORA*EPERROR PRO*RAMPERROR LO*INPDENIED DUPPVALPINDED USERNDEFINED EDCEPTION NNNNNNNNNNNNNNNNNNNNNN NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN VALUEPERROR: NNNNNNNNNNN DECLARE S1 NUMBER% BE*IN A:A1$$$% SELECT SAL INTO S1 FROM EMP ?HERE EMPNOA,$$% DBMSPOUTPUT PUTPLINE"S1)% EDCEPTION ?HEN NOPDATAPFOUND THEN DBMSPOUTPUT PUTPLINE"(NO SUCH EMPLOYEE()% ?HEN VALUEPERROR THEN A:A1$$% UPDATE EMP SET SALASALHA% END% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN VIOLATIN* UNIQUE 1$$R$ A NUMBER"#) A NUMBER A:A1$$$% A:A(DDD(

USERNDEFINED EDCEPTION NNNNNNNNNNNNNNNNNNNNNN DECLARE A1 EDCEPTION% S1 EMP SALOTYPE% BE*IN SELECT SAL INTO S1 FROM EMP ?HERE EMPNOA,!$$% RAISE A1% EDCEPTION ?HEN A1 THEN

END%

UPDATE EMP SET SALAS1H2$$$ ?HERE EMPNOA,!$$%

NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

DECLARE RAD NUMBER% AREA2 NUMBER% BE*IN SELECT RADIUS,AREA INTO RAD,AREA2 DBMSPOUTPUT PUTPLINE"RADQQAREA2)% FROM TEST1 ?HERE RADIUS IN"1$,2$)%

EDCEPTION ?HEN TOOPMANYPRO?S THEN DBMSPOUTPUT PUTPLINE"(TOO MANY RO?S()% END%

1 ?RITE A FUCTION TO DISPLAY THE SYSTEM TIME AND THE CORRESPONDIN* PLRSQL BLOCK "STORED FUNCTION) ?RITE A FUNCTION TO DISPLAY THE &OB ?HEN THE NUMBER IS PASSED ?RITE A FUNCTION TO ACCEPT NAME AND PRINT &OB ?RITE A FUCTION TO ADD 2 NUMBERS "STORED FUNCTION) ?RITE A FUNCTION TO CHECK ?HETHER NUMBER IS EVEN OR ODD "LOCAL FUNCTION) ?RITE A FUNCTION TO *ET SALARY ?HEN NUMBER IS PASSED

'

) ?RITE A FUNCTION TO ILLUSTRATE IN OUT PARAMETERS

+ , PASSED G

EDAMPLE FOR IN PARAMETER ?RITE A FUNCTION TO ILLUSTRATE OUT PARAMETER ?RITE A FUNCTION TO DISPLAY NAME,&OB AND SALARY ?HEN NUMBER IS

! 1$ 11

IF ANNSALF1$$$$ TAD IS 1$O IF ANNSALF1)$$$ TAD IS 2$O IF ANNSALF2$$$$ INCOME TAD IS #$O ELSE INCOME TAD IS TERO ?RITE A FUNCTION TO FIND THE FACTORIAL OF A NUMBER ?RITE A BLOCK TO CALCULATE *ROSS SALARY ?HEN NUMBER IS PASSED *ROSSABASICHHRA"#$O)HDA")$O)NPF"1$O)

?RITE A FUNCTION TO RETURN THE AVERA*E SALARY OF THE EMPLOYEES IF THE NUMBER OF EMPLOYEES ARE MORE THAN 2 THEN ONLY CALCULATE THE AVERA*E 12 -. 1# 89-24 a /0R.K0 =05>: 25 d40424 a 94>59d .I>>4..6I0 942I9n 1 40.4 942I9n $ I6 d40424 5/49a2-5n

89-24 a /0R.K0 =05>: 25 /a.. 234 47/05144 nI7=49 and 234 -n>9474n2 a75In2 FUNCTION SHOULD RETURN THE NET SALARY 1' 89-24 a /0R.K0 =05>: 25 -00I.29a24 d46aI02 a. -n /a9a74249

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@ FUNCTIONS ~~~~~~~~~ 1 ?RITE A FUCTION TO DISPLAY THE SYSTEM TIME AND THE CORRESPONDIN* PLRSQL BLOCK CREATE OR REPLACE FUNCTION TIME1 RETURN VARCHAR IS TIM VARCHAR"1$)% BE*IN SELECT TOPCHAR"SYSDATE,(HH:MI:SS() INTO TIM FROM DUAL% RETURN TIM% END% DECLARE

AB VARCHAR"#$)% BE*IN AB:ATIME1% DBMSPOUTPUT PUTP0INE"AB)% END% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP 2 "STORED FUNCTION) ?RITE A FUNCTION TO DISPLAY THE &OB ?HEN THE NUMBER IS PASSED CREATE OR REPLACE FUNCTION SAL "N NUMBER) RETURN VARCHAR IS DESI* EMP &OBOTYPE% BE*IN SELECT &OB INTO DESI* FROM EMP ?HERE EMPNOAN% RETURN DESI*% END% SELECT SAL"MN) FROM DUAL% IF YOU *IVE THE VALUE FOR N IMMEDIATELY VALUE ?ILL BE DISPLAYED DECLARE A VARCHAR"1$)% BE*IN A:ASAL"MEMPNO)% DBMSPOUTPUT PUTPLINE"A)% END% PPPPPPPPPPPPPPPPPPPPP ?RITE A FUNCTION TO ACCEPT NAME AND PRINT &OB S CREATE OR REPLACE FUNCTION FUN"N VARCHAR2) RETURN VARCHAR2 IS & VARCHAR2"1$)% BE*IN SELECT &OB INTO & FROM EMP ?HERE ENAMEAN% RETURN &% END% D4>0a94 A Ja9>3a92"2))% B Ja9>3a92"2))% B4;-n A:A 6In"M=)% D=7.P5I2/I2 /I2P0-n4"a)% End% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP # "STORED FUNCTION) ?RITE A FUNCTION TO CHECK ?HETHER NUMBER IS EVEN OR ODD

CREATE OR REPLACE FUNCTION EVPODD"N NUMBER) RETURN VARCHAR IS BE*IN IF MOD"N,2)A$ THEN RETURN"(NUMBER IS EVEN()% ELSE RETURN"(NUMBER IS ODD()% END IF% END% DECLARE NOPTEST NUMBER:AMNOPTEST% MES VARCHAR"2))% BE*IN MES:AEVPODD"NOP2EST)% DBMSPOUTPUT PUTPLINE"MES)% END% PPPPPPPPPPPPPPPPPPPPPP CREATE OR REPLACE FUNCTION ADD1"N1 NUMBER,N2 NUMBER) RETURN NUMBER IS RES NUMBER% BE*IN RES:AN1HN2% RETURN RES% END% SELECT ADD1"2,#) FROM DUAL% OR YOU CAN ALSO HAVE A PLRSQL BLOCK TO EDECUTE THE FUNCTION PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP ' "LOCAL FUNCTION) ?RITE A FUNCTION TO *ET SALARY ?HEN NUMBER IS PASSED DECLARE A NUMBER% FUNCTION F1"N NUMBER) RETURN NUMBER IS SALARY EMP SALOTYPE% BE*IN SELECT SAL INTO SALARY FROM EMP ?HERE EMPNOAN% RETURN SALARY% END%

BE*IN A:AF1"MN)% DBMSPOUTPUT PUTPLINE"A)% END%

PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP

PP ) ?RITE A FUNCTION TO ILLUSTRATE IN OUT PARAMETERS

>94a24 59 94/0a>4 6In>2-5n FUN"n IN OUT nI7=49) 942I9n nI7=49 IS BE*IN N:ANH1$% RETURN N% END%

d4>0a94 n1 nI7=49 :A1$% n2 nI7=49% =4;-n n2 :A6In"n1)% d=7.P5I2/I2 /I2P0-n4"n2)% 4nd%

PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP + CREATE RETURN SALARY BE*IN SELECT RETURN END% EDAMPLE FOR IN PARAMETER OR REPLACE FUNCTION FUN1"N IN NUMBER) NUMBER IS NUMBER% SAL INTO SALARY FROM EMP ?HERE EMPNOAN% SALARY%

DECLARE SALARY NUMBER",,2)% BE*IN SALARY:AFUN1",,GG)% DBMSPOUTPUT PUTP0INE"SALARY)% END% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP , NN?RITE A FUNCTION TO ILLUSTRATE OUT PARAMETER NN?RITE A FUNCTION TO DISPLAY NAME,&OB AND SALARY ?HEN NUMBER IS PASSED CREATE OR REPLACE FUNCTION FUN)"DESI* EMP EMPNOOTYPE,SALARY EMP SALOTYPE, S OUT EMP &OBOTYPE) OUT

RETURN VARCHAR2 IS NAME VARCHAR"#$)% BE*IN SELECT ENAME,&OB,SAL INTO NAME,S,SALARY FROM EMP ?HERE EMPNOADESI*% RETURN NAME% EDCEPTION ?HEN OTHERS THEN RETURN "(ERROR()% END% DECLARE A EMP EMPNOOTYPE:AMEMPNO% B VARCHAR"#$)% C VARCHAR"#$)% D NUMBER"G,2)% BE*IN B:AFUN)"A,D,C)% DBMSPOUTPUT PUTPLINE"AQQ( (QQBQQ( (QQCQQ( (QQd)% END% OUTPUT OF THE QUERY IS En249 Ja0I4 659 47/n5: ,!$$ 50d 2: A EMP EMPNOOTYPE:AMEMPNO% n48 2: A EMP EMPNOOTYPE:A,!$$% C577-2 >57/0424 ,!$$ &AMES CLERK !)$ PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP G IF ANNSALF1$$$$ TAD IS 1$O IF ANNSALF1)$$$ TAD IS 2$O IF ANNSALF2$$$$ INCOME TAD IS #$O ELSE INCOME TAD IS TERO CREATE OR REPLACE FUNCTION INCOMETAD"N NUMBER) RETURN NUMBER IS SC NUMBER% ANN NUMBER% IT NUMBER% BE*IN SELECT SALHNVL"COMM,$) INTO SC FROM EMP ?HERE EMPNOAN% ANN:ASC@12% IF ANNF1$$$$ AND ANNL1)$$$ THEN IT:AANN@$ 1% ELSIF ANNF1)$$$ AND ANNL2$$$$ THEN IT:AANN@$ 2% ELSIF ANNF2$$$$ THEN IT:AANN@$ #% ELSE IT:A$%

END IF% RETURN IT% END% DECLARE IT NUMBER% BE*IN IT:AINCOMETAD"MEMPNO)% DBMSPOUTPUT PUTPLINE"(INCOME TAD OF THE EMPLOYEE IS()% DBMSPOUTPUT PUTPLINE"IT)% END% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP ! NN?RITE A FUNCTION TO FIND THE FACTORIAL OF A NUMBER CREATE OR REPLACE FUNCTION FACT" N NUMBER) RETURN NUMBER IS F NUMBER:A1% BE*IN FOR I IN 1 N LOOP F:AF@I% END LOOP% RETURN F% END% DECLARE RESULT NUMBER% N NUMBER:AMN% BE*IN RESULT:A FACT"N)% DBMSPOUTPUT PUTPLINE"(FACTORIAL OF(QQ END% OR SELECT FACT"') FROM DUAL% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP 1$ ?RITE A BLOCK TO CALCULATE *ROSS SALARY ?HEN NUMBER IS PASSED *ROSSABASICHHRA"#$O)HDA")$O)NPF"1$O)

N QQ (IS(QQRESULT)%

CREATE OR REPLACE FUNCTION *ROSS"N NUMBER) RETURN NUMBER IS S NUMBER% HRA NUMBER% DA NUMBER% PF NUMBER% ;95.. NUMBER% BE*IN SELECT SAL INTO S FROM EMP ?HERE EMPNOAN% HRA:AS@$ #%

DA:AS@$ )% PF:AS@$ 1% ;95..:ASHHRAHDANPF% RETURN ;95..% END% DECLARE *ROSS1 NUMBER% ENO NUMBER:AMEMPNO% SALARY NUMBER% BE*IN SELECT SAL INTO SALARY FROM EMP ?HERE EMPNOAENO% DBMSPOUTPUT PUTPLINE"(BEFORE FUNCTION CALL SALARY IS(QQ( (QQSALARY)% *ROSS1:A*ROSS"ENO)% DBMSPOUTPUT PUTPLINE"(AFTER FUNCTION CALL SALARY IS(QQ( (QQ*ROSS1)% END% OR SQLF SELECT *ROSS",!#') FROM DUAL% *ROSS",!#') NNNNNNNNNNN 221$ PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP 11 ?RITE A FUNCTION TO RETURN THE AVERA*E SALARY OF THE EMPLOYEES IF THE NUMBER OF EMPLOYEES ARE MORE THAN 2 THEN ONLY CALCULATE THE AVERA*E CREATE OR REPLACE FUNCTION AVSAL"N NUMBER) RETURN NUMBER IS CO1 NUMBER% A* NUMBER% BE*IN SELECT COUNT"@) INTO CO1 FROM EMP ?HERE DEPTNOAN% IF NF2 THEN SELECT AV*"SAL) INTO A* FROM EMP ?HERE DEPTNOAN% END IF% RETURN A*% END% DECLARE N NUMBER:AMDEPTNO% ASAL NUMBER% BE*IN ASAL:AAVSAL"N)% DBMSPOUTPUT PUTP0INE"(AVERA*E SALARY OF DEPTNO(QQ( (QQNQQ( (QQASAL)% END%

IS

PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP

12

NN89-24 a /0R.K0 =05>: 25 d40424 a 94>59d NNIS.I>>4..6I0 942I9n 1 40.4 942I9n $

I6 d40424

5/49a2-5n

>94a24 59 94/0a>4 6In>2-5n 6In#"n 47/ 47/n5O21/4) 942I9n nI7=49 -. a nI7=49% =4;-n d40424 6957 47/ 83494 47/n5An% -6 .K0O65Ind 234n 942I9n 1% 40.4 942I9n $% 4nd -6% NN4E>4/2-5n NN834n n5Pda2aP65Ind 234n NN942I9n 1$$% 4nd% d4>0a94 n nI7=49% =4;-n n:A6In#"M47/n5)% d=7.P5I2/I2 /I2PL-n4"n)% -6 nA$ 234n d=7.P5I2/I2 /I2P0-n4"(d4042-5n In.I>>4..6I00()% 40.-6 nA1 234n d=7.P5I2/I2 /I2P0-n4"(d4042-5n .I>>4..6I00()% 4nd -6% 4nd% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP 1# 89-24 a /0R.K0 =05>: 25 /a.. 234 47/05144 nI7=49 and 234 -n>9474n2 a75In2 FUNCTION SHOULD RETURN THE NET SALARY >94a24 59 94/0a>4 6In>2-5n 9a-.4P.a0"4n5 nI7=49,-n>94 nI7=49) 942I9n nI7=49 -. a nI7=49% =4;-n .404>2 >5In2"@) -n25 a 6957 47/ 83494 47/n5A4n5% -6 aA$ 234n 9a-.4Pa//0->a2-5nP49959"N2$#$$,(47/05144 d54. n52 4E-.2()% 40.4 I/da24 47/ .42 .a0A.a0H-n>94 83494 47/n5A4n5% .404>2 .a0 -n25 a 6957 47/ 83494 47/n5A4n5% 4nd -6% 942I9n a% 4nd%

d4>0a94 n42.a0 nI7=49% =4;-n n42.a0:A9a-.4P.a0"M47/n5,M.a0a91)% d=7.P5I2/I2 /I2P0-n4"(N42 .a0a91 -.(QQ( (QQn42.a0)% 4nd% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP 1' 89-24 a /0R.K0 =05>: 25 -00I.29a24 d46aI02 a. -n /a9a74249 >94a24 -. .a0a91 =4;-n .404>2 942I9n 4nd% 59 94/0a>4 6In>2-5n d46"n nI7=49 d46aI02 ,#+!) 942I9n nI7=49 47/ .a0O21/4% .a0 -n25 .a0a91 6957 47/ 83494 47/n5An% .a0a91%

.404>2 d46 6957 dIa0% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP

6In>2-5n. :

1) 2)

.-n;04 958 6In>2-5n. 7I02-/04 958 6In>2-5n.";95I/)"a;;94;a24)

S-n;04 958 6In>2-5n. ~~~~~~~~~~~~~~~~~~~~ 1) ARITHMETIC 2) CHARACTER #) *ENERAL ') DATE )) CONVERSION 1 ARITHMETIC FUNCTIONS ~~~~~~~~~~~~~~~~~~~~ AB. >4-0"Fn) 60559"Ln) 75d /5849 .-;n .K92 29In> 95Ind "SIN,COS,TAN,SINH,LO*,LN) 2 CHARACTER FUNCTIONS ~~~~~~~~~~~~~~~~~~~~~~~~~~~ INITCAP LO?ER UPPER LPAD RPAD SOUNDED LTRIM RTRIM SUBSTR LEN*TH INSTR

CONCAT *ENERAL FUNCTIONS

~~~~~~~~~~~~~~~~~~~~~~~~~ NVL DECODE TRANSLATE REPLACE *REATEST LEAST ' DATE FUNCTIONS ~~~~~~~~~~~~~~~~~~~~~~~~~ SYSDATE ADDPMONTHS MONTHSPBET?EEN LASTPDAY NEDTPDAY ) CONVERSION FUNCTIONS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TOPDATE TOPCHAR TOPNUMBER *ROUP FUNCTIONS ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ COUNT SUM MAD MIN AV* SYMBOL DEFINITION ~~~~~~ ~~~~~~~~~~ D NUMBER OF DAY IN ?EEK"1N, STARTS ?ITH SUNDAY) DD DAY IN NUMBERS DDD NUMBER OF DAYS SINCE &AN1 DAY DAY FULLY SPELT OUT DY FIRST # CHARACTERS OF THE DAY MM MONTH IN NUMBERS MONTH MONTH FULLY SPELT OUT MON MONTH IN # LETTERS ?? NUMBER OF ?EEKS OVER SINCE &AN 1 ? NUMBER OF ?EEKS OVER IN THAT MONTH Y 1 DI*IT YEAR YY 2 DI*IT YEAR YYY # DI*IT YEAR YYYY ' DI*IT YEAR YEAR YEAR FULLY SPELT OUT HH HOUR MI MINUTES SS SECONDS SSSS MILLISECONDS HH2' 2' HOUR FORMAT HH12 12 HOUR FORMAT FMDDTH 1ST,2ND,#RD NNNN"ORDINAL FORMAT) RM ROMAN NUMERAL MONTH FMDDSPTH SPELLED FORMAT "FIRST, SECOND, THIRD)

*ROUP BY AND HAVIN* CLAUSE ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1) NUMBER OF EMPLOYEES DEPTNO?ISE 2) SUM OF SALARIES DEPTNO?ISE #) NUMBER OF EMPLOYEES &OB?ISE ') SUM,MAD,MIN AND AV* OF SAL &OB?ISE )) AV*"SAL) DEPTNO?ISE ?ITH SALF'$$$

KI491 25 .404>2 n23 94>59d ~~~~~~~~~~~~~~~~~~~~~~~~~~~ QI491 25 d40424 n23 94>59d ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ d40424 6957 47/ 83494 958-d -n " .404>2 958-d 6957 47/ 83494 958nI7LAMn 7-nI. .404>2 958-d 6957 47/ 83494 958nI7LAMnN1)% HBN .404>2 @ 6957 47/ 83494 958-d -n " .404>2 958-d 6957 47/ 83494 958nI7LAMn 7-nI. .404>2 958-d 6957 47/ 83494 958nI7LAMnN1)% d-./0a1 n 94>59d. -n =42844n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CORRECT QUERY ~~~~~~~~~~~~~~ SELECT RO?NUM,RO?ID,ENAME FROM EMP ?HERE RO?NUMLAMN MINUS SELECT RO?NUM,RO?ID,ENAME FROM EMP ?HERE RO?NUMLAMN

"TRIALS) ~~~~~~~~~ .404>2 958nI7,958-d,47/n5,4na74,<5= FROM EMP A ?HERE RO?ID " "SELECT RO?ID FROM EMP ?HERE RO?NUM LA "SELECT COUNT"@)NMN FROM EMP)) 7-nI. ".404>2 958-d 6957 47/ 83494 958nI7LA ".404>2 >5In2"@) NMn 6957 47/)) )% "SECOND TRIAL) ~~~~~~~~~~~~~~ .404>2 958nI7,958-d,47/n5,4na74,<5= FROM EMP A ?HERE RO?ID " "SELECT RO?ID FROM EMP ?HERE RO?NUM L "SELECT COUNT"@)NMN FROM EMP)) 7-nI. ".404>2 958-d 6957 47/ 83494 958nI7LA ".404>2 >5In2"@) NMn 6957 47/)) )% "THIRD TRIAL) ~~~~~~~~~~~~~~~ DELETE FROM EMP A ?HERE RO?ID IN " " SELECT RO?ID FROM EMP ?HERE RO?NUMLAMN) MINUS "SELECT RO?ID FROM EMP ?HERE RO?NUMLAMN) )%

IN

IN

DISPLAY ALL THE DETAILS OF EMPLOYEES ?HOSE &OB IS SAME AS THAT OF &ONES 1 D-./0a1 234 D42a-0. 56 a00 E7/05144. a05n; 8-23 234-9 D4/a9274n2 In6597a2-5n .404>2 4 @ ,d dna74,d d4/2n5,d 05> 6957 47/ 4,d4/2 d 83494 4 d4/2n5Ad d4/2n5% 2 D-./0a1 234 D42a-0. 56 a00 E7/05144. 835 a94 *422-n; Sa0a91 *94a249 23an 234 Sa0a91 56 ADAMS .404>2 a 4na74,a .a0,= 4na74,= .a0 6957 47/ a,47/ = 83494 a 4na74A(FORD( AND B SALFA SAL% SELECT ENAME,SAL,&OB FROM EMP ?HERE SALF"SELECT SAL FROM EMP ?HERE ENAMEA(ADAMS()% # D-./0a1 234 d42a-0. 56 a00 47/05144. 835 a94 <5-n4d =46594 (FORD(

SELECT A ENAME,A SAL,A HIREDATE,B ENAME,B SAL,B HIREDATE FROM EMP A,EMP B ?HERE A ENAMEA(FORD( AND B HIREDATELA HIREDATE% SELECT @ FROM EMP ?HERE HIREDATE L"SELECT HIREDATE FROM EMP ?HERE ENAMEA(FORD()% ' 2 D-./0a1 234 d42a-0. 56 a00 234 47/05144. 835 a94 <5-n4d A6249 SMITH BI2 B46594 M-0049 SELECT A ENAME,A HIREDATE ,B HIREDATE,C HIREDATE FROM EMP A,EMP B,EMP C ?HERE B ENAMEA(SMITH( AND C ENAMEA(MILLER( AND A HIREDATEF B HIREDATE AND A HIREDATELC HIREDATE% SELECT @ FROM EMP ?HERE HIREDATE F"SELECT HIREDATE FROM EMP ?HERE ENAMEA(SMITH() AND HIREDATE L"SELECT HIREDATE FROM EMP ?HERE ENAMEA(MILLER()% ) D-./0a1 234 D42a-0. 56 a00 47/05144. a05n; 8-23 234-9 7ana;49. Na74 AND E7/05144 NI7=49 SELECT A EMPNO,A ENAME,A &OB,B &OBVREPORTV,B ENAME VREPNAMEV FROM EMP A ,EMP B ?HERE A M*RAB EMPNO% + D-./0a1 234 D42a-0. 56 a00 47/05144. 859:-n; -n 234 .a74 D4/a9274n2 a. (FORD( .404>2 @ 6957 47/ 83494 83494 4na74A(FORD()% d4/2n5A".404>2 d4/2n5 6957 47/

.404>2 a 4na74,a .a0,a <5=,a d4/2n5 6957 47/ a,47/ = 83494 a d4/2n5A= d4/2n5 and = 4na74A(FORD(% , D-./0a1 234 d42a-0. 56 a00 234 47/05144. 835 a94 *422-n; 234 L4.. >577-.-5n 23an (FORD ( C5n.-d49 NULL >577-.-5n a. ($( SELECT A ENAME,A COMM,B COMM,B ENAME FROM EMP A,EMP B ?HERE NVL"A COMM,$) FNVL"B COMM,$) AND B ENAMEA(FORD(%

SQLF 2 #

ENAME COMM COMM ENAME NNNNNNNNNN NNNNNNNNN NNNNNNNNN NNNNNNNNNN ALLEN #$$ FORD ?ARD )$$ FORD MARTIN 1'$$ FORD

SELECT a 4na74 59-na74,a >577 59->577, = 4na74,= >577 6957 47/ a,47/ = ?HERE A COMM L B COMM AND B ENAMEA(MARTIN(% SELECT a 4na74 59-na74,a >577 59->577, = 4na74,= >577 6957 47/ a,47/ = 83494 NVL"a >577,$)LNVL"= >577,$) and = 4na74A(MARTIN(% G D-./0a1 234 d42a-0. 56 a00 234 47/05144. 659 8357 234 F59d -. 234 Mana;49 SELECT A ENAME ACTUALNAME,A SAL,A &OB,B ENAME REPORTSTO ,B SAL, B &OB FROM EMP A,EMP B ?HERE B ENAMEA(FORD( AND A M*RAB EMPNO% ! D-./0a1 234 D42a-0. 56 a00 234 47/05144. 835 a94 <5-n4d -n 234 .a74 75n23 56 FORD SELECT A ENAME,A HIREDATE,B ENAME,B HIREDATE FROM EMP A,EMP B ?HERE B ENAMEA(FORD( AND TOPCHAR"A HIREDATE,(MONTH()A TOPCHAR"B HIREDATE,(MONTH()%

1$

D-./0a1 234 d42a-0. 56 a00 234 47/05144. 835 a94 -n 234 SALES D4/a9274n2 SELECT @ FROM EMP ?HERE DEPTNOA"SELECT DEPTNO FROM DEPT ?HERE DNAMEA(SALES()% SELECT A ENAME,A DEPTNO,A &OB,B DEPTNO,B DNAME FROM EMP A,DEPT B ?HERE B DNAMEA(SALES( AND A DEPTNOAB DEPTNO%

11

D-./0a1 234 d42a-0. 56 a00 234 47/05144. 835 a94 n52 ANALYSTS and *422-n; Sa0a91 *944a249 23an (CLARK(% SELECT A ENAME,A &OB,A SAL,B ENAME,B SAL,B &OB FROM EMP A,EMP B ?HERE A &OBWA(ANALYST( AND A SAL FB SAL AND B ENAMEA(CLARK(% SELECT @ FROM EMP ?HERE &OB NOT IN (ANALYST( AND SAL F "SELECT SAL FROM EMP ?HERE ENAMEA(CLARK()%

12

D-./0a1 A00 234 47/05144 Na74. a05n; 8-23 234-9 Mana;49 SELECT A EMPNO,A ENAME,A &OB,B ENAME MANA*ER,B &OB REPORTIN* FROM EMP A,EMP B ?HERE A M*RAB EMPNO%

1#

D-./0a1 234 Na74. 56 a00 234 47/05144. 835 a94 a00 ;422-n; 234 .a0a91 *94a249 23an 234 .a0a91 56 (SMITH( SELECT @ FROM EMP ?HERE SAL F"SELECT SAL FROM EMP ?HERE ENAMEA(SMITH()% SELECT A ENAME,A &OB,A SAL,B ENAME,B SAL FROM EMP A,EMP B ?HERE B ENAMEA(SMITH( AND A SAL F B SAL%

1'

D-./0a1 234 Na74. 56 a00 234 47/05144. 835 a94 a00 ;422-n; 234 .a0a91 *94a249 23an 234 .a0a91 56 (SMITH( a05n; 8-23 234 d-66494n>4 -n .a0a91 SELECT A ENAME,A &OB,A SAL,B ENAME,B SAL,A SALNB SAL FROM EMP A,EMP B ?HERE B ENAMEA(SMITH( AND A SALFB SAL %

1)

D-./0a1 234 d42a-0. 56 a00 234 47/05144. 835.4 .a0 -. ;94a249 23an 234 aJ49a;4 .a0a91 56 234 47/05144. -n 234-9 94./4>2-J4 d4/a974n2. SELECT @ FROM EMP A ?HERE SAL F " SELECT AV*"SAL) FROM EMP B ?HERE A DEPTNOAB DEPTNO

)%

1+

?RITE A QUERY TO PRINT THE MULTIPLICATION TABLE SELECT MR QQ (@(QQ( ( QQLPAD"RO?NUM,',( ()QQ( A (QQ MR @ RO?NUM FROM EMP ?HERE RO?NUM LA 1$%

1,

LIST FOLLO?IN* DETAILS FOR EMPLOYEES ?HO EARN #+$$$RN A YEAR OR ARE CLERKS SELECT A ENAME,A &OB,A SAL@12,B DNAME FROM EMP A,DEPT B ?HERE A DEPTNOAB DEPTNO AND A SAL@12F#$$$$ OR A DEPTNOAB DEPTNO AND A &OBA(CLERK(%

1G .404>2 4na74,.a0, d4>5d4".a0,04a.2".a0,1$$$),(L1$$$(, ;94a24.2"04a.2".a0,2$$$)),(F1$$$ and L2$$$(, ;94a24.2"04a.2".a0,#$$$)),(F2$$$ and L#$$$() 6957 47/% ENAME SAL DECODE"SAL,LEAS NNNNNNNNNN NNNNNNNNN NNNNNNNNNNNNNNN SMITH G$$ L1$$$ ALLEN 1+$$ F1$$$ and L2$$$ ?ARD 12)$ F1$$$ and L2$$$ &ONES 2!,) F2$$$ and L#$$$ MARTIN 12)$ F1$$$ and L2$$$ BLAKE 2G)$ F2$$$ and L#$$$ CLARK 2')$ F2$$$ and L#$$$

SCOTT KIN* TURNER ADAMS &AMES FORD MILLER R@SILLY@R

#$$$ )$$$ 1)$$ 11$$ !)$ #$$$ 1#$$

F2$$$ and L#$$$ F1$$$ F1$$$ L1$$$ F2$$$ F1$$$ and L2$$$ and L2$$$ and L#$$$ and L2$$$

.404>2 .a0,>5In2"@) aa, d4>5d4".a0,04a.2".a0,1$$$),(L1$$$(, ;94a24.2"04a.2".a0,2$$$)),(F1$$$ and ;94a24.2"04a.2".a0,#$$$)),(F2$$$ and d4>5d4".a0,04a.2".a0,1$$$),(L1$$$(, ;94a24.2"04a.2".a0,2$$$)),(F1$$$ and ;94a24.2"04a.2".a0,#$$$)),(F2$$$ and

L2$$$(, L#$$$() 6957 47/ ;95I/ =1 L2$$$(, L#$$$(),.a0%

OR SELECT SAL,DECODE"FLOOR"SALR1$$$),$,(L1$$$(,1,(F 1$$$ AND L 2$$$(, #,(F2$$$ AND L #$$$(,(F #$$$() FROM EMP% OR "SAN&AYA) SELECT SAL,DECODE"*REATEST"SAL,1$$$),1$$$,(L 1$$$(, LEAST"SAL,2$$$), ( F 1$$$ AND L 2$$$(, LEAST"SAL,#$$$), (F 2$$$ AND L #$$$(, LEAST"SAL,'$$$),( A #$$$(,( F #$$$ () FROM EMP% 1! d-./0a1 234 d42a-0. 56 a00 234 47/05144. 835.4 .a0a91 -. 4KIa0 25 9an;4 a. ./4>-6-4d -n ;9ad4 ) .404>2 .a0 6957 47/ 83494 .a0 F ".404>2 05.a0 6957 .a0;9ad4 83494 ;9ad4A)) and .a0L ".404>2 3-.a0 6957 .a0;9ad4 83494 ;9ad4A))% 2$ CREATE A SEQUENCE AND *ENERATE SOME NUMBERS INTO THE TABLE BY CONCATENATIN* IT ?ITH E >94a24 .4KI4n>4 .1 .2a92 8-23 1 -n>9474n2 =1 1 7aEJa0I4 1$ -n.492 -n25 EM#"A) Ja0I4. ">5n>a2"(4(,.12 n4E2Ja0))% 21 .404>2 0/ad"( (,04J40N1)QQ4na74 6957 47/ START ?ITH <5= A (PRESIDENT( CONNECT BY PRIOR EMPNO A M*R% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP INSERT THESE NUMBERS

PP END OF REPORT PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP .404>2 a .a0,a 4na74,a d4/2n5 6957 47/ a ;95I/ =1 a d4/2n5 3aJ-n; a .a0Fa00".404>2 aJ;".a0) 6957 47/ = 6957 47/ = ;95I/ =1 d4/2n5)% .404>2 d-.2-n>2 a .a0, a 4na74, a d4/2n5 6957 47/ a,47/ = 83494 a d4/2n5A= d4/2n5 and a .a0 Fa00".404>2 aJ;".a0) 6957 47/ = ;95I/ =1 d4/2n5)% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

d4>0a94 a nI7=49:AMa% = nI7=49:AM=% > nI7=49% =4;-n >:Aa@=% =:AaH=% a:A75d">,=)% d=7.P5I2/I2 /I2P0-n4"( d=7.P5I2/I2 /I2P0-n4"( d=7.P5I2/I2 /I2P0-n4"( 4nd%

(QQa)% (QQ=)% (QQ>)%

d4>0a94 a nI7=49:AMa% n nI7=49% =4;-n 659 - -n 1 1$ 055/ n:Aa@-% d=7.P5I2/I2 /I2P0-n4"aQQ(@(QQ-QQ(A(QQn)% 4nd 055/% 4nd% d4>0a94 a nI7=49:AMa% = nI7=49% > nI7=49:A2% =4;-n 659 - -n 1 1$ 055/ -6 a:A1 234n

=:A>H2% 40.4 =:A2H-% d=7.P5I2/I2 /I2P0-n4"=)% 4nd -6% 4nd 055/% 4nd%

d4>0a94 =4;-n 659 - -n 1 d=7.P5I2/I2 d=7.P5I2/I2 d=7.P5I2/I2 4nd 055/% 4nd%

# 055/ /I2P0-n4"(X()% n48P0-n4% /I2"X)%

d4>0a94 a nI7=49"1$)% =4;-n a:A1% d=7.P5I2/I2 /I2P0-n4"a)% a:A12% d=7.P5I2/I2 /I2P0-n4"a)% a:A12#% d=7.P5I2/I2 /I2P0-n4"a)% a:A12#'% d=7.P5I2/I2 /I2P0-n4"a)% a:A12#')% d=7.P5I2/I2 /I2P0-n4"a)% a:A12#')+% d=7.P5I2/I2 /I2P0-n4"a)% a:A12#')+,% d=7.P5I2/I2 /I2P0-n4"a)% a:A12#')+,G% d=7.P5I2/I2 /I2P0-n4"a)% a:A12#')+,G!% d=7.P5I2/I2 /I2P0-n4"a)% a:A12#')+,G!$% d=7.P5I2/I2 /I2P0-n4"a)% 4nd% d4>0a94 41 nI7=49% 42 nI7=49% 4# nI7=49% Ja0 nI7=49% =4;-n Ja0:AM4#% .404>2 d4/2n5 -n25 42 6957 47/ 83494 47/n5AJa0% -6 42A1$ 234n I/da24 47/ .42 >577A1$$$ 83494 47/n5AJa0% 40.-6 42 A 2$ 234n I/da24 47/ .42 >577A2$$$ 83494 47/n5AJa0%

40.-6 4#A#$ 234n I/da24 47/ .42 >577A#$$$ 83494 47/n5AJa0% 4nd -6% 4nd% d4>0a94 21/4 21/41 -. 94>59d"4n5 nI7=49"') n52 nI00:A,,GG,4na 47/ 4na74O21/4)% 494> 21/41% =4;-n .404>2 47/n5,4na74 -n25 494> 6957 47/ 83494 47/n5A,,GG% d=7.P5I2/I2 /I2P0-n4"494> 4n5QQ494> 4na)% 4nd% d4>0a94 .a0a91 47/ .a0O21/4% 7;9PnI7 47/ 7;9O21/4% 47n5 47/ 47/n5O21/4% 4na7 47/ 4na74O21/4% =4;-n .404>2 4na74,47/n5,.a0, 7;9 -n25 4na7,47n5,.a0a91, 7;9PnI7 6957 47/ 83494 47/n5A,,GG% 83-04 .a0a91L'$$$ 055/ I/da24 47/ .42 .a0A1$$$ 83494 47/n5A7;9PnI7% 4nd 055/% -n.492 -n25 47/1 Ja0I4."nI00,.a0a91,4na7)% >577-2% 4nd% d4>0a94 n5 nI7=49% na74 Ja9>3a92"2$)% .a0a91 nI7=49",,2)% =4;-n .404>2 4na74,.a0 -n25 na74,.a0a91 6957 47/ 83494 47/n5AMn5% -n.492 -n25 47/1 Ja0I4."na74,.a0a91)% 4nd% d4>0a94 .29 Ja9>3a92"2$)% 94J Ja9>3a92"2$)% =4;-n .29:A(M-n/I2(% -6 04n;23".29)A$ 234n d=7.P5I2/I2 /I2P0-n4"(nI00()% 40.4 659 - -n 1 04n;23".29) 055/ 94J:A.I=.29".29,-,1)% 4nd 055/% 4nd -6% d=7.P5I2/I2 /I2P0-n4"(94J .29-n;( QQ94J)% 4nd% d4>0a94 a nI7=49%

= nI7=49:A1% =4;-n a:AMn5% 659 - -n 1 a 055/ =:A=@-% 4nd 055/% d=7.P5I2/I2 /I2P0-n4"=)% 4nd% ORACLE ?ORKSHEET QUESTIONS I 1: a QUESTIONS BASED ON DATA DEFINITION LAN*UA*E COMMANDS : CREATE A TABLE EMP AND DEPT USIN* THE FOLLO?IN* INFORMATION:N DEPT :

COLUMN NAME DATATYPE"SITE) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NNNNNNNN NNNNNNNNNNNNN DEPTNO NUMBER"2) DNAME VARCHAR2"1') LOC VARCHAR2"1#) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN = EMP: COLUMN NAME DATATYPE"SITE) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NNNNNNNN NNNNNNNNNNNN EMPNO NUMBER"') ENAME VARCHAR2"1$) &OB VARCHAR2"!) M*R NUMBER"') HIREDATE DATE SAL NUMBER",,2) COMM NUMBER",,2) DEPTNO NUMBER"2) 2: #: ': CHECK THE DEFAULT SITE OF A NUMBER,CHAR AND DATE DATATYPES DESCRIBE THE STRUCTURE OF THE DEPT TABLE AND EMP TABLE ADD T?O COLUMNS TO THE TABLE EMP ?ITH THE FOLLO?IN* INFORMATION IN ONE SIN*LE ALTER COMMAND :N COLUMN NAME DATATYPE"SITE) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN SED CHAR"1) PLACE CHAR"1)) MODIFY THE COLUMN &OB PRESENT IN THE EMP TABLE ?ITH THE FOLLO?IN* INFORMATION *IVEN BELO? :N COLUMN NAME DATATYPE"SITE) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN &OB VARCHAR2"1)) MODIFY THE COLUMN ENAME PRESENT IN THE EMP TABLE

):

+:

?ITH THE FOLLO?IN* INFORMATION *IVEN BELO? :N COLUMN NAME DATATYPE"SITE) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN ENAME CHAR"1)) ,: DECREASE THE SITE FOR THE COLUMN EMPNO ?ITH THE FOLLO?IN* INFORMATION :N COLUMN NAME DATATYPE"SITE) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN EMPNO NUMBER"2) MODIFY THE COLUMN NAME OF EMPNO TO EMPLOYEEPNUMBER PRESENT IN THE EMP TABLE VERIFY THE RESULT BET?EEN &OB AND M*R

G:

!: ADD A NE? COLUMN NATIONALITY PLACED COLUMNS AND VERIFY THE RESULT 1$: 11: DROP THE TABLE DEPT AND EMP

?HAT IS THE DATA TYPE OF THE COLUMN HIREDATE AND HO? MANY BYTES IT OCCUPIES QUESTIONS BASED ON CONSTRAINTS :

12: a

CREATE A TABLE EMP AND DEPT USIN* THE FOLLO?IN* INFORMATIOM DEPT :

COLUMN NAME DATATYPE"SITE) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NNNNNNNN NNNNNNNNNNNNN DEPTNO NUMBER"2)CONSTRAINT PKPDEPTNO PRIMARY KEY, DNAME VARCHAR2"1') LOC VARCHAR2"1#) EMP : COLUMN NAME DATATYPE"SITE) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NNNNNNNN NNNNNNNNNNNN EMPNO NUMBER"')CONSTRAINT PKPEMPNO PRIMARY KEY, ENAME VARCHAR2"1$)CONSTRAINT UQPENAME UNIQUE, &OB VARCHAR2"!), M*R NUMBER"'), HIREDATE DATE DEFAULT SYSDATE, SAL NUMBER",,2)CONSTRAINT CKPSAL CHECK"SALF$) NNPSAL NOT NULL, COMM NUMBER",,2), DEPTNO NUMBER"2)CONSTRAINT FKPDEPTNO REFERENCES DEPT"DEPTNO) 1#: SELECT ALL THE CONSTRAINTS IN EMP TABLE

SOL:

SELECT @ FROM USERPCONSTRAINTS ?HERE TABLEPNAMEA(EMP(%

1': SELECT THE O?NER,CONSTRAINT NAME,CONSTRAINT TYPE,TABLE NAME,STATUS FOR DEPT TABLE SOL: 1): SOL: 1+: SOL: 1,: SOL: 1G: SOL: II SELECT O?NER,CONSTRAINTPNAME,CONSTRAINTPTYPE,TABLEPNAME,STATUS FROM USERPCONSTRAINTS ?HERE TABLEPNAMEA(DEPT(% DROP THE CONSTRAINT UQPENAME FROM EMP TABLE ALTER TABLE EMP DROP CONSTRAINT UQPENAME% ADD A NE? COLUMN PINCODE ?ITH NOT NULL CONSTRAINT TO THE EDISTIN* TABLE DEPT ALTER TABLE DEPT ADD"PINCODE NUMBER"+) NOT NULL)% DISABLE THE CONSTRAINT PKPDEPTNO PRESENT IN DEPT TABLE

ALTER TABLE DEPT DISABLE CONSTRAINT PKPDEPTNO% ENABLE THE CONSTRAINT PKPDEPTNO ?HICH IS DEFINED IN THE DEPTNO COLUMN OF DEPT TABLE ALTER TABLE DEPT ENABLE CONSTRAINT PKPDEPTNO% QUESTIONS BASED ON DATA MANIPULATION LAN*UA*E COMMANDS :N PROBLEMS BASED ON INSERT COMMAND:N

1!: EMP:

INSERT THE *IVEN VALUES INTO THE TABLES: "-),#+!,SMITH,CLERK,,!$2,1,NDECNG$,G$$,NULL,2$ "--),'!!,ALLEN,SALESMAN,,+!G,2$NFEBNG1,1+$$,#$$,#$ "---),)21,?ARD,SALESMAN,,+!G,22NFEBNG1,12)$,)$$,#$ "-J),)++,&ONES,MANA*ER,,G#!,$2NAPRNG1,2!,),NULL,2$ "J),+)',MARTIN,SALESMAN,,+!G,2GNSEPNG1,12)$,1'$$,#$ "J-),+!G,BLAKE,MANA*ER,,G#!,$1NMAYNG1,2G)$,NULL,#$ "J--),,G2,CLARK,MANA*ER,,G#!,$!N&UNNG1,2')$,NULL,1$ "J---),,GG,SCOTT,ANALYST,,)++,1!NNOVN!+,#$$$,NULL,2$ "-E),G#!,KIN*,PRESIDENT,NULL,1,NNOVNG1,)$$$,NULL,1$ "E),G'',TURNER,SALESMAN,,+!G,$GNSEPNG1,1)$$,$,#$ "E-),G,+,ADAMS,CLERK,,,GG,2#NDECN!+,11$$,NULL,2$ "E--),!$$,&AMES,CLERK,,+!G,$#NDECNG1,!)$,NULL,#$ "E---),!$2,FORD,ANALYST,,)++,$#NDECNG1,#$$$,NULL,2$ "E-J),!#',MILLER,CLERK,,,G2,2#N&ANNG2,1#$$,NULL,1$ "EJ),!'#,&OHN,CLERK,,!'#,1$NDECNG#,2$$$,NULL,)$

DEPT: "-)1$,ACCOUNTIN*,NE? YORK "--)2$,RESEARCH,DALLAS "---)#$,SALES,CHICA*O "-J)'$,OPERATIONS,BOSTON "J))$,COMPUTER,AMERICA

2$: SOL: 21: SOL: 22: SOL:

INSERT ONLY THE RECORDS OF INTO EMP TABLE

EMPLOYEE NUMBER,NAME,SALARY

INSERT INTO EMP"EMPNO,ENAME,SAL) VALUES"(,!))(,(PAUL(,12$$)% INSERT T?O RO?S INTO EMP TABLE USIN* PARAMETER SUBSTITUTION INSERT INTO EMP VALUES"MEMPNO,(MENAME(,(M&OB(,MM*R,(MHIREDATE(, MSAL,MCOMM,MDEPTNO)% INSERT THE CURRENT TRANSACTION DATE INSERT INTO TEMP VALUES"SYSDATE)% PROBLEMS ON SELECT COMMAND:N TEMPORARY TABLE

2#: SOL: 2': SOL: 2): SOL: 2+: SOL: 2,: SOL: 2G: NAMES SOL: 2!: SOL: #$: SOL: #1:

LIST

THE INFORMATION OF ALL EMPLOYEES

SELECT @ FROM EMP% LIST THE INFORMATION OF ALL THE DEPARTMENTS SELECT @ FROM DEPT% LIST THE DEPARTMENT NUMBERS,EMPLOYEE NUMBERS AND THEIR MANA*ERS NUMBERS SELECT DEPT DEPTNO,EMP EMPNO,EMP M*R FROM EMP,DEPT% LIST DEPARTMENT NAME AND LOCATIONS FROM DEPT TABLE SELECT DNAME,LOC FROM DEPT% LIST THE INFORMATION OF EMPLOYEES AND THEIR DEPARTMENTS IN A SIN*LE DML COMMAND SELECT @ FROM EMP% COPY ALL THE RECORDS OF THREE COLUMNS EMPNO,ENAME,&OB FROM EMP TABLE AND INSERT THE RECORDS INTO A TEMP TABLE ?ITH COLUMN SAME AS EMPNO,ENAME,&OB INSERT INTO TEMP"EMPNO,ENAME,&OB) SELECT EMPNO,ENAME,&OB LIST THE DETAILS OF BOTH THE TABLES SELECT @ FROM EMP,DEPT% LIST THE INFORMATION OF ALL THE EMPLOYEES PRESENT IN THE USER NAMED SCOTT SELECT @ FROM SCOTT EMP% LIST THE INFORMATION OF ALL THE DEPARTMENTS FROM YOUR BATCHMATES

DEPT TABLE SOL: #2: SOL: ##: SOL: #': SOL: #): #+: SOL: #,: SOL: SELECT @ FROM ORA2)2P DEPT% LIST OUT ALL THE TABLE NAMES IN YOUR SCHEMA SELECT @ FROM TAB% LIST ALL THE SYSTEM TABLES SELECT @ FROM SYS DICTIONARY% *ET THE INFORMATION OF THE MADIMUM AVAILABLE BLOCKS ALLOTED TO A PARTICULAR USER FOR CREATIN* TABLES FROM THE SYSTEM TABLES SELECT @ FROM USERPTSPQUOTAS% LIST OUT ALL THE PRIVILA*ES *IVEN TO A PARTICULAR USER LIST OUT ALL THE TABLES ?HICH START ?ITH (S( SELECT TABLEPNAME FROM USERPTABLES ?HERE TABLEPNAME LIKE (SO(% COPY THE STRUCTURE CALLED TEMP1 OF DEPT TABLE ALONE TO A TEMPORARY TABLE

CREATE TABLE TEMP1 AS SELECT @ FROM DEPT ?HERE 1A2% PROBLEMS ON UPDATE COMMAND:N

#G: SOL: #!: SOL: '$: SOL: '1: SOL: '2: SOL: '# SOL:

UPDATE THE SALARY BY 1$O HIKE TO ANALYSTS ?ORKIN* IN DEPARTMENT NUMBER 2$ AND #$ UPDATE EMP SET SALASALH"SAL@$ 1) ?HERE DEPTNO IN "1$,2$) AND &OBA(ANALYST(% *IVE )O RAISE IN SALARY TO ALL THE SALESMAN UPDATE EMP SET SALASALH"SAL@$ )) ?HERE &OBA(SALESMAN(% PROMOTE ALL THE EMPLOYEES DESCRIBED AS SALESMAN TO SALES OFFICER IF THEIR *ROSS SALARY PER MONTH IS *REATER THAN #$$$ UPDATE EMP SET &OBA(SALES OFFICER( ?HERE &OBA(SALESMAN( AND SALF#$$$% *IVE ALL THE EMPLOYEES A COMMISSION OF RS )$$ UPDATE EMP SET COMMA)$$% CHAN*E THE DEPARTMENT OF &AMES TO 2$ UPDATE EMP SET DEPTNOA2$ ?HERE ENAMEA(&AMES(% CALCULATE ALL THE EMPLOYEES TOTAL SALARY ?ITH COMMISION SELECT SALHNVL"COMM) VTOTALV FROM EMP%

'': SOL: '): SOL: '+: SOL: ',: SOL: 'G: SOL: '!: SOL: )$: SOL: )1: SO0:

PROBLEMS ON DELETE COMMAND:N DELETE ALL THE RECORDS OF EMPLOYEES DELETE FROM EMP% *ET BACK THE ORI*INAL RECORDS OF EMPLOYEES BACK ROLLBACK% DELETE ALLEN(S RECORD ONLY DELETE FROM EMP ?HERE ENAMEA(ALLEN(% DELETE RECORDS OF ENAME COLUMN ONLY AND VERIFY IT NOT POSSIBLE DELETE THE RECORDS OF EMPLOYEE NUMBER ,,G2 DELETE FROM EMP ?HERE EMPNOA,,G2% DELETE THE EMPLOYEE(S RECORDS ?HO DOES(NT HAVE COMMISION DELETE FROM EMP ?HERE COMM IS NULL% *ET BACK THE ORI*INAL RECORDS ROLLBACK% DELETE THE DUPLICATE RECORDS OF THE EMPLOYEE TABLE DELETE FROM EMP A ?HERE RO?IDLF"SELECT MIN"RO?ID) FROM EMP B ?HERE A EMPNOAB EMPNO)% DELETE THE FIRST FIVE RECORDS OF EMPLOYEE TABLE DELETE FROM EMP D ?HERE )F"SELECT COUNT"RO?ID) FROM EMP Y ?HERE Y RO?IDLD RO?ID)% " OR ) DELETE FROM EMP ?HERE RO?NUM L+%

)2: SOL:

)#: SOL: III )': SOL: )):

DELETE THE RO?S OF THE TEMP TABLE PERMANENTLY TRUNCATE TABLE TEMP% PROBLEMS ON TRANSACTIONAL COMMANDS :N UPDATE A RECORD OF IN THE DATABASE EMP TABLE AND SAVE THE CHAN*ES PERMANENTLY

UPDATE EMP SET SALASALH1$$ ?HERE EMPNOA1$$% COMMIT% SQL@PLUS HAS THE FACILITY TO AUTOMATICALLY SAVE ALL THE

RECORDS, ?ITHOUT ISSUIN* THE TCL COMMAND ?HICH IS THAT SOL: SET AUTOCOMMIT ON PRIVILA*ES YOU HAVE OF A DATABASE OB&ECT TO

)+: *IVE ALL THE ANOTHER USER SOL: ),: SOL: )G: SOL: )!: SOL: IV

*RANT ALL ON EMP TO ORA2)#A% *IVE ONLY SELECT,INSERT PRIVILA*ES TO ANOTHER USER *RANT SELECT,INSERT ON EMP TO ORA2+,A% LIST THE USER(S ID AND ?HICH DATABASE OB&ECT YOU HAVE *RANTED

SELECT @ FROM USERPTABPPRIVS% *ET BACK THE PRIVILA*ES BACK FROM THE USER REVOKE ALL ON EMP FROM ORA2+,A% PROBLEMS BASED ON OPERATORS :N PROBLEMS BASED ON ARITHMETIC,RELATIONAL,LO*ICAL AND CHARACTER OPERATORS:N

+$: SOL: +1: NUMBER

LIST ALL THE EMPLOYEES SALARY ?ITH COMMISSION PROVIDE A NE? HEADIN* AS TOTAL SALARY SELECT SALHNVL"COMM,$) VTOTAL SALARYV FROM EMP % *IVE THE SALARY ?ITH A REDUCTION OF 1$O FROM THEIR SALARY TO PERSONS ?HOSE &OB IS CLERK AND AND BELON*IN* TO DEPARTMENT #$

SOL: UPDATE EMP SET SALASALN"$ 1@SAL) ?HERE &OBA(CLERK( AND DEPTNOA#$% +2: SOL: +#: SOL: +': SOL: +): SOL: LIST THE EMPLOYEES BELON*IN* TO DEPARTMENT 2$ SELECT @ FROM EMP ?HERE DEPTNOA2$% LIST THE NAME AND SALARY OF THE EMPLOYEES ?HOSE SALARY IS LESS THAN #$$$ SELECT ENAME,SAL FROM EMP ?HERE SALL#$$$% LIST THE NAME AND SALARY OF THE EMPLOYEES ?HOSE SALARY IS *REATER THAN #$$$ SELECT ENAME,SAL FROM EMP ?HERE SALF#$$$% LIST THE EMPLOYEE NUMBER AND NAME OF MANA*ERS SELECT EMPNO,ENAME FROM EMP ?HERE &OBA(MANA*ER(%

++: SOL: +,: SOL: +G: 1!G1 SOL: +!: SOL: ,$: SOL: ,1: SOL: ,2: #$$$ SOL: ,#: SOL: ,': SOL: ,): SOL: ,+: SOL: ,,: SOL: ,G: SOL:

LIST THE EMPLOYEES ?HOSE SALARY IS NOT EQUAL TO #$$$ SELECT @ FROM EMP ?HERE SALWA#$$$% LIST THE EMPLOYEE NAME AND SALARY ?HOSE SALARY IS BET?EEN 2$$$ AND #$$$ SELECT ENAME,SAL FROM EMP ?HERE SALFA2$$$ AND SALLA#$$$% LIST ALL THE EMPLOYEES ?HO HAVE &OINED BEFORE #$TH SEPTEMBER

SELECT @ FROM EMP ?HERE HIREDATELA(#$NSEPNG1(% LIST THE NAMES OF EMPLOYEES ?HO ARE NOT MANA*ERS SELECT ENAME FROM EMP ?HERE &OBLF(MANA*ER(% LIST ALL THE EMPLOYEES BELON*IN* TO THE DEPARTMENT 1$,#$ SELECT @ FROM EMP ?HERE DEPTNO IN"1$,#$)% LIST ALL EMPLOYEES NOT BELON*IN* TO MANA*ER,PRESIDENT SELECT @ FROM EMP ?HERE &OB NOT IN "(MANA*ER(,(PRESIDENT()% LIST EMPLOYEES NAME AND &OB ?HOSE SALARY IS BET?EEN 2$$$ AND SELECT ENAME,&OB FROM EMP ?HERE SAL BET?EEN 2$$$ AND #$$$% LIST THE EMPLOYEE NAMES AND THEIR DESI*NATION ?HO HAVE &OINED BEFORE #$TH &UNE (G1 AND AFTER DECEMBER (G1 SELECT ENAME FROM EMP ?HERE HIREDATE NOT BET?EEN (#$N&UNNG1( AND (#1NDECNG1(% LIST THE EMPLOYEE NAMES ?HO ARE NOT ELI*IBLE FOR COMMISSION SELECT ENAME FROM EMP ?HERE COMM IS NULL% LIST THE EMPLOYEE NAMES ?HO ARE ELI*IBLE FOR COMMISSION SELECT ENAME FROM EMP ?HERE COMM IS NOT NULL% LIST ALL THE EMPLOYEE NAMES BET?EEN THE LETTER (M( AND (O( SELECT @ FROM EMP ?HERE ENAME BET?EEN (M( AND (O(% LIST THE NAME OF THE EMPLOYEE AND &OB OF THE EMPLOYEE , ?HO DOES NOT BELON*S TO ANY BODY SELECT ENAME,&OB FROM EMP ?HERE M*R IS NULL% LIST THE EMPLOYEES ?HOSE NAMES START ?ITH AN VSV SELECT ENAME FROM EMP ?HERE ENAME LIKE (SO(%

,!: SOL: G$: SOL: G1: SOL: G2: SOL: G#: SOL: G': #$$$ SOL: G): SOL: G+: SOL: G,: SOL: GG: SOL: G!: SOL: !$: SOL: !1: SOL: DUAL% !2:

LIST THE EMPLOYEE NAMES ENDIN* ?ITH

VSV

SELECT ENAME FROM EMP ?HERE ENAME LIKE (OS(% LIST THE EMPLOYEES ?HOSE NAMES HAVE EDACTLY ) CHARACTERS SELECT ENAME FROM EMP ?HERE ENAME LIKE (P P P P P(% LIST THE EMPLOYEE NAMES HAVIN* (I( AS THE SECOND CHARACTER SELECT ENAME FROM EMP ?HERE ENAME LIKE (PIO(% LIST THE DIFFERENT &OBS AVAILABLE IN THE EMP TABLE SELECT DISTINCT &OB FROM EMP% LIST THE DISTINCT &OB FROM EMP IN DEPARTMENT #$ SELECT DISTINCT &OB FROM EMP ?HERE DEPTNOA#$% LIST THE EMPLOYEE NAME,SALARY, ?HOSE SALARY IS BET?EEN 2$$$ AND SELECT ENAME,SAL FROM EMP ?HERE SALFA2$$$ AND SALLA#$$$% LIST THE NAMES OF ANALYSTS AND SALESMAN SELECT ENAME FROM EMP ?HERE &OBA(SALESMAN( OR &OBA(ANALYST(% LIST THE EMPLOYEE NAMES ?HOSE &OB IS CLERK AND DEPTARTMENT IS #$ SELECT ENAME FROM EMP ?HERE &OBA(CLERK( AND DEPARTMENTA#$% DISPLAY ALL THE EMPLOYEE NAMES IN THE FORMAT AS VNAME IS ALLENV SELECT (NAME IS (QQENAME FROM EMP% DISPLAY THE ABSOLUTE VALUE OF N2) SELECT ABS"N2)) VABSOLUTEV FROM DUAL% DISPLAY THE SMALLEST INTE*ER *REATER THAN OR EQUAL TO 1+ , SELECT CEIL"1+ ,) VCEILIN*V FROM DUAL% DISPLAY THE *REATEST INTE*ER LESSER THAN OR EQUAL TO 1) #' SELECT FLOOR"1) #') VFLOORV FROM DUAL% DISPLAY THE COSINE OF THE AN*LE IN DE*REES SELECT COS"1G$@# 1'1)!2+)#)!R1G$)VCOSINE OF 1G$ DE*REESV FROM DISPLAY THE HYPERBOLIC COSINE OF $

SOL: !#: SOL: !': SOL: !): SOL: !+: NUMBER SOL: !,: SOL: !G: SOL:

SELECT COSH"$) VHYPERBOLIC COSINE OF $ V FROM DUAL% DISPLAY THE EDPONENTIAL PO?ER OF THE VALUE , SELECT EDP",) V4 TO THE ,TH PO?ER V FROM DUAL% DISPLAY THE NATURAL LO*ARITHM OF ,) SELECT LN",)) VNATURAL LO* OF ,)V FROM DUAL% DISPLAY THE LO*ARITHM, BASE 1$, OF 1$$ SELECT LO*"1$,1$$) VLO* BASE 1$ OF 1$$V FROM DUAL% DISPLAY REMAINDER TERO ?HEN A NUMBER IS DIVIDED BY AN EVEN

SELECT MOD"1$,2) VMODULUSV FROM DUAL% CHECK THE ORP ?HEN A VALUE MFN IN A MOD FUNCTION AND NOTE DO?N THE REASON FOR THAT KIND OF ORP SELECT MOD"2,1$) VMODULUSV FROM DUAL% DISPLAY THE VALUE ?HEN ! RAISED TO 2

SELECT PO?ER"!,2) VRAISED AS V FROM DUAL%

!!: DISPLAY THE VALUE FOR 1) 1!# ROUNDED TO FIRST DECIMAL PLACE FOR?ARD SOL: SELECT ROUND"1) 1!#,1) VROUNDV FROM DUAL%

1$$: DISPLAY THE VALUE FOR 1) 1!# ROUNDED TO FIRST DECIMAL PLACE BACK?ARDS SOL: 1$1: SOL: 1$2: SOL: 1$#: SOL: 1$': SOL: 1$): SOL: SELECT ROUND"1) 1!#,N1) VROUNDV FROM DUAL% DISPLAY THE SI*N OF N1) SELECT SI*N"N1)) FROM DUAL% DISPLAY THE SINE OF AN*LE #$ DE*REES SELECT SIN"#$@# 1'1)!2+)#)!R1G$) VSINE OF #$ DE*REESV FROM DUAL% DISPLAY THE HYPERBOLIC SINE OF 1 SELECT SINH"1) VHYPERBOLIC SINE OF 1 V FROM DUAL% DISPLAY THE SQUARE ROOT OF THE VALUE 2) SELECT SQRT"2)) VSQUARE ROOT V FROM DUAL% DISPLAY THE TAN*ENT OF THE VALUE 1#) IN DE*REES SELECT TAN"1#)@# 1'1)!2+)#)!R1G$)VTAN*ENT OF 1#) DE*REESV FROM

DUAL% 1$+: SOL: 1$,: SOL: 1$G: SOL: 1$!: SQL: 11$: SQL: 111: SQL: 112: SQL: 11#: SQL: 11': SQL: 11): SOL: 11+: SOL: 11,: SOL: TRUNCATE THE VALUE 1) ,! TO FIRST DECIMAL PLACES SELECT TRUNC"1) ,!,1)V TRUNCATE V FROM DUAL% TRUNCATE THE VALUE 1) ,! TO FIRST DECIMAL PLACE N DI*ITS LEFT TO THE DECIMAL POINT SELECT TRUNC"1) ,!,N1)VTRUNCATEV FROM DUAL% DISPLAY THE CHARACTER VALUE FOR THE NUMBER ,) SELECT CHR",)) VCHARACTER V FROM DUAL% DISPLAY THE ENAME AND &OB OF EMPNOA,!$$ IN THE FORMAT 4;:N ALLEN IS A SALESMAN SELECT ENAME QQ ( IS A ( QQ &OB FROM EMP%

CAPITALISE THE FIRST LETTER OF V234 .5a/ V SELECT INITCAP"( =9a-n8a94 -n6524>3"/) 02d() 6957 dIa0% DISPLAY THE ?ORDS IN LO?ER CASE LETTERS SELECT LO?ER"(BRAIN?ARE INFOTECH"P) LTD() FROM DUAL% DISPLAY THE LEFT PADDED CHAR(S TO THE STRIN* BRAIN?ARE ?HEN THE RETURN VALUE IS 1) AND PADDED CHARACTER IS (@( SELECT LPAD"(BRAIN?ARE(,1),(@() FROM DUAL% DISPLAY THE RI*HT PADDED CHAR(S TO THE STRIN* BRAIN?ARE ?HEN THE RETURN VALUE IS 1) AND PADDED CHARACTER IS (@( SELECT RPAD"(BRAIN?ARE(,1),(@() FROM DUAL% REMOVE CHARAECTER (RE( TO?ARDS RI*HT OF THE STRIN* FROM THE LETTER (BRAIN?ARE( SELECT RTRIM"(BRAIN?ARE(,(RE() FROM DUAL% REMOVE CHARAECTER (IN( TO?ARDS LEFT OF THE STRIN* FROM THE LETTER (BRAIN?ARE( SELECT LTRIM"(INFOTECH(,(IN() FROM DUAL% REPLACE THE CHARACTER (&( ?ITH (BL( FROM THE ?ORD &ACK AND &UE SELECT REPLACE"(&ACK AND &UE(,(&(,(BL() FROM DUAL% DISPLAY THE ENAME ?ITH THE PHONETIC REPRESENTATION OF (SMYTHE( FROM TABLE EMP SELECT ENAME FROM EMP ?HERE SOUNDED"ENAME)ASOUNDED"(SMYTHE()%

11G: SOL: 11!: SOL: 12$:

DISPLAY THE FIRST THREE LETTERS OF THE EMPLOYEE NAMES SELECT SUBSTR"ENAME,1,#) FROM 47/% DISPLAY THE CHARACTERS (AR( FROM THE ?ORD (BRAIN?ARE( SELECT SUBSTR"(BRAIN?ARE(,N#,2) FROM DUAL% CONVERT ALL THE CHARACTERS ?HICH IS (ABC T( TO LETTER (T( AND ALL DI*ITS ($12 !( TO DI*IT (!( FROM THE *IVEN CHARACTER ($12#KASL(

SOL: SELECT TRANSLATE"($12#KASL(,($12#')+,G!ABCDEF*HI&KLMNOPQRSTUV?DYT(, (!!!!!!!!!!TTTTTTTTTTTTTTTTTTTTTTTTTT() 6957 dIa0% 121: SOL: 122: SOL: 12#: SOL: 12': SOL: 12): SOL: 12+: SOL: 12,: DISPLAY THE ASCII VALUE OF THE CHARACTER (A( SELECT ASCII"(A() FROM DUAL% DISP0a1 THE ASCII VALUE OF CHARACTER(S (AB( FROM DUAL SELECT ASCII"(AB() FROM DUAL HINT:ASCII ?ILL DISPLAY ONLY THE FIRST LETTER (A( ONLY DISPLAY THE #RD OCCURRENCE OF CD AT THE THIRD OCCURRENCE OF ?ORD VABCDABCDABCD&&V SELECT INSTR"(ABCDABCDABCD&&(,(CD(,#,#) FROM DUAL% DISPLAY THE LEN*TH OF THE ?ORD (ALLEN( SELECT LEN*TH"(ALLEN() FROM DUAL% DISPLAY THE DATE OF THE NEDT TUESDAY AFTER MARCH 1),1!!2 SELECT NEDTPDAY"(1)NMARN!2(,(TUESDAY() VNEDT DAYV FROM DUAL% DISPLAY THE LAST DAY OF THIS MONTH SELECT LASTPDAY"SYSDATE) FROM DUAL% DISPLAY THE DIFFERENCE DATE BET?EEN CURRENT DATE AND LAST DAY OF THE SYSDATE

SOL: SELECT SYSDATE,LASTPDAY"SYSDATE) VLASTV,LASTPDAY"SYSDATE)N SYSDATE VDAYS LEFTV FROM DUAL% 12G: 1!!2V SOL: 12!: DISPLAY THE DIFFERENCE OF T?O DATES V$2N$2N1!!2V AND V$1N$1N SELECT MONTHSPBET?EEN"TOPDATE"($2N$2N1!!2(,(DDNMONNYYYY(), TOPDATE"($1N$1N1!!2(,(DDNMONNYYYY()) FROM DUAL% DISPLAY THE CURRENT DATE AND TIME

SOL: 1#$: SOL: 1#1: SOL: 1#2: SOL: 1##: SOL: 1#': SOL: 1#): SOL: 1#+: SOL: 1#,: SOL: 1#G: SOL:

SELECT TOPCHAR"SYSDATE,(DDNMONNYY HH2':MI:SS() FROM DUAL% ADD T?O MONTHS TO SYSDATE SELECT TOPCHAR"SYSDATE,2) FROM DUAL% ADD 1$ DAYS TO SYSDATE SELECT TOPCHAR"TOPDATE"SYSDATE,(DDNMONNYY(),(DD()H1$ FROM DUAL% DISPLAY THE NUMBER FORMAT OF THE NUMBER 12#'

SELECT TOPNUMBER"(12#'() FROM DUAL% CONVERT RO?ID OF EMPLOYEE NAME SMITH TO EMPLOYEE NAME SELECT ENAME FROM EMP ?HERE RO?IDA($$$$$,$, $$$$ $$$D(% DISPLAY THE SYSTEM DATE AS VMON DD YYYYV

SELECT TOPCHAR"SYSDATE,(MON DD YYYY() FROM DUAL% DISPLAY THE CURRENT DATE IN THE FORMAT DDTH MONTH YYYY SELECT TOPCHAR"SYSDATE,(FMDDTH MONTH YYYY() FROM DUAL% CONVERT THE FOLLO?IN* STRIN* TO ORACLE DATE FORMAT V12NAU*USTN!,V SELECT TOPDATE"(12NAU*USTN!,(,(DDNMONTHNYY() FROM DUAL% DISPLAY THE USERNAME IN ?HICH YOU ARE ?ORKIN* SELECT USER FROM DUAL% DISPLAY TH USERID NUMBER IN ?HICH YOU ARE ?ORKIN* SELECT UID FROM DUAL%

1#!: DISPLAY THE *REATEST OF THE LIST OF EDPRESSIONS VHARRYV VHARRIOTV VHAROLDV SOL: 1'$: SOL: 1'1: SELECT *REATEST"(HARRY(,(HARRIOT(,(HAROLD() FROM DUAL% DISPLAY THE LEAST OF THE LIST OF EDPRESSIONS VHARRYV VHARRIOTV VHAROLDV SELECT LEAST"(HARRY(,(HARRIOT(,(HAROLD() FROM DUAL%

DISPLAY ALL THE ENAMES ?HERE COMMISSION IS NULL AND PLACE THE EDPRESSION V NOT POSSIBLE V IN DEPTARTMENT #$ ?HERE COMMISSION IS NULL ELSE DISPALY THEIR COMMISSION SOL: SELECT ENAME,NVL"TOPCHAR"COMM),(NOT POSSIBLE() VCOMMISSIONV

FROM EMP ?HERE DEPTNOA#$% 1'2: SOL: DISPLAY THE *REEN?ICH TIME OF $):1) A M SELECT TOPCHAR"NE?PTIME"TOPDATE"($):1)(,(HH2':MI(),(PST(,(*MT(), (HH2':MI() FROM DUAL%

1'#: DISPLAY THE LAN*UA*E AND TERRITORY CURRENTLY USED BY YOUR SESSION SOL: 1'': SOL: 1'): SOL: 1'+: SOL: 1',: SOL: 1'G: SOL: 1'!: SOL: 1)$: SOL: 1)1: SOL: 1)2: SOL: 1)#: SOL: SELECT USERENV"(LAN*UA*E() FROM DUAL% DISPLAY THE NUMBER OF BYTES EACH EMPLOYEE OCCUPIES INTERNALLY SELECT VSITE"ENAME) VBYTESV FROM EMP% DISPLAY THE AVERA*E SALARY DEPARTMENT?ISE SELECT AV*"SAL),DEPTNO FROM EMP *ROUP BY DEPTNO% DISPLAY THE SUMMATION OF SALARIES DEPARTMENT?ISE SELECT SUM"SAL),DEPTNO FROM EMP *ROUP BY DEPTNO% DISPLAY THE SUMMATION OF SALARIES OF FIRST FIVE RECORDS SELECT SUM"SAL) FROM EMP ?HERE RO?NUMLA)% DISPLAY THE MINIMUM SALARY IN THE TABLE EMP SELECT MIN"SAL) FROM EMP% DISPLAY THE MADIMUM SALARY FROM THE TABLE EMP SELECT MAD"SAL) FROM EMP% DISPLAY ALL THE SALARIES SUPRESSIN* THE DUPLICATES SELECT DISTINCT SAL FROM EMP% DISPLAY ALL THE &OB SUPRESSIN* THE DUPLICATES SELECT DISTINCT &OB FROM EMP% DISPLAY NUMBER OF RECORDS PRESENT IN EMP TABLE SELECT COUNT"@) FROM EMP% DISPLAY THE NUMBER OF &OBS IN EMP TABLE SELECT COUNT"&OB) FROM EMP%

1)': DISPLAY NUMBER OF RECORDS FOR DESI*NATION SUPRESSIN* THE DUPLICATES SOL: SELECT COUNT"DISTINCT &OB) FROM EMP%

1)): SOL: 1)+: SOL: 1),: SOL: 1)G: SOL: DUAL% 1)!: SOL:

DISPLAY THE MINIMUM HIREDATE HIRED FOR EMPLOYEES SELECT MIN"HIREDATE) FROM EMP% CALCULATE THE STANDARD DEVIATION OF SALARIES FROM EMP TABLE SELECT STDDEV"SAL) FROM EMP% CALCULATE THE VARIANCE OF ALL THE SALARIES FROM EMP TABLE SELECT VARIANCE"SAL) FROM EMP% DISPLAY THE YEAR 2$1, SELECT TOPCHAR"TOPDATE"(2,NNOVN2)(,(DDNMONNRR(),(YYYY() FROM IF DEPARTMENT NUMBER IS 1$ DISPLAY *OODCHOICE ELSE DISPLAY BADCHOICE IN ALL OTHER DEPARTMENT FIELDS SELECT DECODE"DEPTNO,1$,(*OODCHOICE(,(BADCHOICE() FROM EMP% PROBLEMS ON &OINS:N

1+$: SOL: 1+1: SOL: 1+2: SOL: 1+#: SOL: 1+': SOL: 1+): SOL:

LIST THE DEPARTMENT NAME,EMPLOYEES NAME,EMPLOYEE NUMBER SELECT EMP EMPNO,EMP ENAME,DEPT DNAME FROM EMP,DEPT% ?HERE EMP DEPTNOADEPT DEPTNO% LIST THE TOTAL SALARIES OF EACH DEPARTMENT SELECT EMP DEPTNO,SUM"SAL) FROM EMP,DEPT ?HERE EMP DEPTNOADEPT DEPTNO *ROUP BY EMP DEPTNO% LIST THE TOTAL EMPLOYEES SALARIES ?HO DOES NOT BELON* TO ANY DEPARTMENT SELECT DEPTNO,SUM"SAL) FROM EMP,DEPT ?HERE EMP DEPTNOADEPT DEPTNO"H)% LIST THE MANA*ER(S NAME AND EMPLOYEES NAME ?HO BELON*S TO THEIR MANA*ER(S SELECT M ENAMEQQ( (QQ(IS THE MANA*ER FOR(QQ( (QQ E ENAME FROM EMP E,EMP M ?HERE E M*RAM EMPNO% LIST THE EMPLOYEES ?HOSE SALARIES BET?EEN 2$$$ AND #$$$ SELECT @ FROM EMP ?HERE EMPNO IN "SELECT EMPNO FROM EMP ?HERE SAL BET?EEN 2$$$ AND #$$$)% LIST THE DEPARTMENT NAME OF THE EMPLOYEE ?HOSE NAME IS OF &ONES SELECT DEPT DNAME FROM EMP,DEPT ?HERE EMP DEPTNOADEPT DEPTNO AND ENAME LIKE (&ONESO(%

1++: SOL: 1+,: SOL:

LIST THE DEPARTMENT OF THE EMPLOYEES SELECT @ FROM EMP ?HERE DEPTNO AANY"SELECT DEPTNO FROM DEPT)% FIND OUT THE EMPLOYEES ?ITH SAME &OB AS &ONES SELECT ENAME,&OB FROM EMP INTERSECT SELECT ENAME,&OB FROM EMP ?HERE &OB IN "SELECT &OB FROM EMP ?HERE ENAME LIKE (&ONESO()% DISPLAY INFORMATION ABOUT EMPLOYEES ?HO EARN MORE THAN ANY EMPLOYEES IN DEPARTMENT #$ SELECT @ FROM EMP ?HERE SALFALL"SELECT SAL FROM EMP ?HERE DEPTNOA#$)% LIST ALL THE EMPLOYEES IN DEPARTMENT NUMBER 1$ ?ITH THE SAME &OB AS IN DEPARTMENT NUMBER #$ SELECT ENAME FROM EMP ?HERE DEPTNOA1$ INTERSECT SELECT ENAME FROM EMP ?HERE &OB IN "SELECT &OB FROM EMP ?HERE DEPTNOA#$)% LIST THE EMPLOYEES ?ITH EITHER THE SAME &OB AS &ONES OR SALARY *REATER THAN OR SAME AS FORD SELECT ENAME FROM EMP INTERSECT SELECT ENAME FROM EMP ?HERE &OB IN"SELECT &OB FROM EMP ?HERE ENAME LIKE (&ONESO( OR SALFA"SELECT SAL FROM EMP ?HERE ENAME LIKE (FORDO())% LIST THE EMPLOYEES IN DEPARTMENT 1$ ?ITH THE SAME &OB AS ANY ONE IN SALES DEPARTMENT SELECT ENAME,&OB FROM EMP ?HERE &OB IN "SELECT &OB FROM EMP ?HERE DEPTNOA1$) INTERSECT SELECT ENAME,&OB FROM EMP ?HERE DEPTNO IN "SELECT DEPTNO FROM EMP ?HERE &OBA(SALESMAN()% LIST EMPLOYEES ?HOSE SALARY IS SAME AS THAT OF SCOTT OR ?ARD SELECT ENAME FROM EMP TO LIST THE DEPARTMENT THAT HAS NO EMPLOYEES SELECT DEPTNO FROM DEPT MINUS SELECT DEPTNO FROM EMP%

1+G: SOL: 1+!: SOL:

1,$: SOL:

1,1: SOL:

1,2: SOL: 1,#: SOL:

"OR) SELECT DEPTNO FROM DEPT ?HERE DEPTNO NOT IN "SELECT DEPTNO FROM EMP)% 1,': SOL: TO LIST THE DEPARTMENT AND COUNT OF &OB IN ?HICH THERE ARE MORE THAN ON SALESMANS SELECT DEPTNO,&OB,COUNT"@) FROM EMP ?HERE &OBA(SALESMAN( *ROUP BY DEPTNO,&OB HAVIN* COUNT"@)F1% LIST THE DEPARTMENT IN ?HICH THEIR ARE MORE THAN ONE SALESMAN SELECT DEPTNO,&OB FROM EMP ?HERE &OBA(SALESMAN( AND DEPTNO IN "SELECT DEPTNO FROM EMP *ROUP BY DEPTNO HAVIN* COUNT"&OB)F1)% SELECT THE EVEN NUMBER OF RO?S FROM EMPLOYEE TABLE SELECT @ FROM EMP ?HERE RO?ID IN "SELECT DECODE"MOD"RO?NUM,2),$,RO?ID,NULL) FROM EMP)% LIST THE ODD NUMBER OF RO?S FROM EMPLOYEE TABLE SELECT @ FROM EMP ?HERE RO?ID IN "SELECT DECODE"MOD"RO?NUM,2),1,RO?ID,NULL) FROM EMP)% DELETE THE ODD NUMBER RO?S FROM EMPLOYEE TABLE

1,): SOL: 1,+: SOL:

1,,:

1,G: SOL:

DELETE FROM EMP ?HERE RO?ID IN "SELECT DECODE "MOD"RO?NUM,2),1,RO?ID,NULL) FROM EMP)% DELETE THE EVEN NUMBER RO?S FROM EMPLOYEE TABLE

1,!: SOL:

DELETE FROM EMP ?HERE RO?ID IN "SELECT DECODE "MOD"RO?NUM,2),$,RO?ID,NULL) FROM EMP)% LIST THE EMPLOYEES ?HOSE SALARY IS *REATER THAN THE AVERA*E SALARY OF HIS DEPARTMENT SELECT DEPTNO,EMPNO,SAL FROM EMP D ?HERE SALF"SELECT AV*"SAL) FROM EMP Y ?HERE D DEPTNOAY DEPTNO)% QUERY DEPARTMENT?ISE AVERA*ERMADIMUMRMINIMUM SALARIES SELECT EMP DEPTNO,DNAME,MAD"SAL),MIN"SAL),AV*"SAL) FROM EMP,DEPT ?HERE EMP DEPTNOADEPT DEPTNO

1G$: SOL: 1G1: SOL:

*ROUP BY EMP DEPTNO,DNAME% 1G2: SOL: COUNT THE NUMBER OF MALE AND FEMALE EMPLOYEES ALTER TABLE EMP ADD "SED CHAR"1))% SELECT SED,COUNT"@) FROM EMP *ROUP BY SED HAVIN* SED A(M(% UNION SELECT SED,COUNT"@) FROM EMP *ROUP BY SED HAVIN* SEDA(F(% 1G#: SOL: DISPLAY THE YEAR AND NUMBER OF EMPLOYEES FOR THE YEAR IN ?HICH MORE THAN ONE EMPLOYEE ?AS HIRED SELECT TOPCHAR"HIREDATE,(YYYY() YEAR,COUNT"@) FROM EMP *ROUP BY TOPCHAR"HIREDATE,(YYYY() HAVIN* COUNT"@)F1% DELETE THE DUPLICATE RO?S FROM DEPT TABLE DELETE FROM DEPT ?HERE DEPTNO IN "SELECT DEPTNO FROM DEPT *ROUP BY DEPTNO HAVIN* COUNT"DEPTNO)F1)% DELETE THE DUPLICATE RO?S EDCEPT ITS MINIMUM VALUE DELETE FROM EMP A ?HERE RO?IDLF"SELECT MIN"RO?ID) FROM EMP B ?HERE A EMPNOAB EMPNO)% LIST LAST FIVE RECORDS FROM EMP TABLE SELECT ENAME,SAL FROM EMP MINUS SELECT ENAME,SAL FROM EMP ?HERE RO?NUML"SELECT MAD"RO?NUM)N' FROM EMP )% LIST THE THIRD HI*HEST SALARY FROM EMP TABLE SELECT MAD"SAL) FROM EMP ?HERE SALL"SELECT MAD"SAL) FROM EMP ?HERE SALL"SELECT MAD"SAL) FROM EMP))% LIST FIVE EMPLOYEES IN LO?EST ORDER OF SALARY SELECT ENAME,SAL FROM EMP MINUS

1G': SOL:

1G): SOL:

1G+: SOL: 1G,: SOL:

1GG: SOL:

SELECT ENAME,SAL FROM EMP SALF"SELECT MIN"SAL) FROM SALF"SELECT MIN"SAL) FROM SALF"SELECT MIN"SAL) FROM SALF"SELECT MIN"SAL) FROM 1G!: SOL:

?HERE EMP ?HERE EMP ?HERE EMP ?HERE EMP))))%

LIST THE *IVEN RAN*E OF RECORDS AS PER THE STORA*E OF RO?S IN A *IVEN DATABASE TABLE NAMED EMP SELECT RO?ID FROM EMP D ?HERE NOT MNF"SELECT COUNT"RO?ID) FROM EMP Y ?HERE Y RO?IDLD RO?ID) INTERSECT SELECT RO?ID FROM EMP D ?HERE MMFA"SELECT COUNT"RO?ID) FROM EMP Y ?HERE Y RO?IDLD RO?ID)% LIST THE NTH HI*HEST SALARY IN THE EMPLOYEE TABLE SELECT DISTINCT SAL FROM EMP ?HERE SALA"SELECT DISTINCT SAL FROM EMP D ?HERE MNA"SELECT COUNT"DISTINCT SAL) FROM EMP Y ?HERE Y SALFD SAL))% LIST THE NTH LO?EST SALARY IN THE EMPLOYEE TABLE SELECT DISTINCT SAL FROM EMP D ?HERE MNA"SELECT COUNT"DISTINCT SAL) FROM EMP Y ?HERE D SALFY SAL)% LIST EMPLOYEES IN THE EMPLOYEE TABLE ACCEPTIN* THOSE FIRST FIVE AND LAST THREE IN THE ORDER OF DATA STORA*E SELECT RO?ID FROM EMP D ?HERE )F"SELECT COUNT"RO?ID) FROM EMP Y ?HERE Y RO?IDLD RO?ID) UNION SELECT RO?ID FROM EMP D ?HERE # F"SELECT COUNT"RO?ID) FROM EMP Y ?HERE Y RO?IDFD RO?ID)% LIST THE TREE STRUCTURED QUERY ?ITH EMPLOYEE NAME STARTIN* ?ITH KIN* SELECT LPAD"( (,+@"LEVELN1))QQENAME NAME FROM EMP START ?ITH ENAMEA(KIN*( CONNECT BY M*RAPRIOR EMPNO% LIST THE EMPLOYEES ?HOSE SALARY *REATER THAN OR EQUAL TO AVERA*E SALARY OF DEPARTMENT NUMBER 1$ SELECT SAL,ENAME FROM EMP ?HERE SALFA"SELECT AV*"SAL) FROM EMP *ROUP BY DEPTNO HAVIN* DEPTNOA1$)% SELECT ALL THE ENAMES ?ITH THE OCCURANCES OF THE LETTER (S( SELECT INSTR"ENAME,(A() FROM EMP%

1!$: SOL:

1!1: SOL:

1!2: SOL:

1!#: SOL:

1!': SOL:

1!): SOL:

1!+:

LIST THE DIFFERENT DESI*NATIONS IN DEPARTMENT 2$ AND #$

SOL:

SELECT DISTINCT &OB FROM EMP ?HERE DEPTNOA2$ UNION SELECT DISTINCT &OB FROM EMP ?HERE DEPTNOA#$% LIST THE &OBS COMMON IN DEPARTMENT 2$ AND #$ SELECT &OB FROM EMP ?HERE DEPTNOA2$ INTERSECT SELECT &OB FROM EMP ?HERE DEPTNOA#$% LIST THE &OBS UNIQUE TO DEPARTMENT 2$ SELECT &OB FROM EMP ?HERE DEPTNOA2$ MINUS SELECT &OB FROM EMP ?HERE DEPTNOA1$ MINUS SELECT &OB FROM EMP ?HERE DEPTNOA#$% LIST THE EMPLOYEES IF AND ONLY IF MORE THAN 1$ EMPLOYEES ARE PRESENT IN DEPARTMENT NUMBER 1$ SELECT @ FROM EMP ?HERE EDISTS "SELECT DEPTNO,COUNT"@) FROM EMP ?HERE DEPTNOA1$ *ROUP BY DEPTNO HAVIN* COUNT"@)FA#)% LIST THE EMPLOYEE NAMES ?HOSE SALARY IS *REATER THAN THE LO?EST SALARY OF AN EMPLOYEE BELON*IN* TO DEPARTMENT 2$ SELECT ENAME FROM EMP ?HERE SALFANY"SELECT SAL FROM EMP ?HERE DEPTNOA2$)% LIST THE EMPLOYEE NAMES ?HOSE SALARY IS *REATER THAN THE HI*HEST SALARY OF AN EMPLOYEE BELON*IN* TO DEPARTMENT NUMBER 2$ SELECT ENAME FROM EMP ?HERE SALFALL"SELECT SAL FROM EMP ?HERE DEPTNOA2$)% CREATE A VIE? ?ITH COLUMNS EMPNO AND A 1$O HIKE SALARY COLUMN AND TRY TO INSERT A RO? IN THIS VIE? AND VERIFY IT CREATE VIE? EMPSAL AS SELECT EMPNO,SAL@ 1 TOTPSAL FROM EMP% HINT: THE FOLLO?IN* VIE?S ARE READ N ONLY VIE?S - 4 NO INSERT OR UPDATE THROU*H THESE VIE?S IS POSSIBLE THIS IS A READ N ONLY VIE? BECAUSE OF THE PRESENCE

1!,: SOL:

1!G: SOL:

1!!: SOL:

2$$: SOL: 2$1: SOL:

2$2: SOL:

OF AN A**RE*ATE FUNCTION 2$#: CREATE A VIE? ?ITH THE COLUMNS EMPNO,ENAME,DEPTNO SELECTED FROM THE TABLE EMP AND CORRESPONDIN* DEPARTMENT NUMBER #$ INSERT RO?S INTO THIS VIE? AND VERIFY THE RESULT CREATE VIE? EMPDEPT AS SELECT EMPNO,ENAME,DEPTNO FROM EMP ?HERE DEPTNOA#$% HINT: THIS IS NOT A READ N ONLY VIE? RO?S CAN BE INSERTED INTO THE EMP TABLE USIN* THIS VIE? , BUT CANNOT BE VIE?ED BY THE EMPDEPT VIE? AS THE VIE? CAN ONLY RETRIEVE RO?S BELON*IN* TO DEPARTMENT #$ 2$': CREATE A VIE? ?ITH COLUMNS EMPNO,ENAME,DEPTNO AND DEPTNOA#$ ?ITH A CHECK OPTION AND INSERT A RO? INTO THE VIE? ?ITH DEPARTMENT NUMBER 2$ AND VERIFY THE RESULT CREATE VIE? EMPDEPT1 AS SELECT EMPNO,ENAME,DEPTNO FROM EMP ?HERE DEPTNOA#$ ?ITH CHECK OPTION% DERIVE A VIE? FROM ANOTHER VIE? HAVIN* CHECK OPTION CREATE VIE? EMPDEPT2 AS SELECT EMPNO,ENAME,DEPTNO FROM EMPDEPT1% LIST ALL THE VIE? NAMES CREATED IN YOUR LO*IN SELECT @ FROM USERPVIE?S% CREATE A SIMPLE SEQUENCE CREATE SEQUENCE S1 INCREMENT BY 1 START ?ITH 1$$$% INSERT THE SEQUENCE NUMBER INTO THE EMPNO COLUMN OF EMP TABLE INSERT INTO EMP"EMPNO) VALUES"S1 NEDTVAL)% CREATE A SEQUENCE ?ITH STEP VALUEA1% START VALUEA2%MINIMUM VALUEA1%MADIMUM VALUEA22 AND THE SEQUENCE TO RESET AUTOMATICALLY ?HEN IT COMES TO START VALUE CREATE SEQUENCE S2 INCREMENT BY 1 START ?ITH 2 MINVALUE 1 MADVALUE 22 CYCLE% DROP THE SEQUENCE DROP SEQUENCE S2%

SOL:

SOL:

2$): SOL: 2$+: SOL: 2$,: SOL: 2$G: SOL: 2$!:

SO0:

21$: SOL:

211: SOL: 212: SOL: 21#: SOL: 21': SOL: 21): SOL: 21+: SOL:

LIST ALL THE SEQUNCES CREATED IN YOUR LO*IN SELECT @ FROM USERPSEQUENCES% CREATE AN INDED ON COLUMN ENAME OF EMP TABLE CREATE INDED ID1 ON EMP"ENAME)% CREATE INDED ON T?O COLUMNS EMPNO,ENAME CREATE INDED ID2 ON EMP "EMPNO,ENAME)% DROP THE INDED YOU HAVE CREATED DROP INDED ID1% LIST THE INDEDES CREATED ON THE TABLE EMP SELECT @ FROM USERPINDEDES ?HERE TABLEPNAMEA(EMP(% CREATE A CLUSTER BASED ON THE DEPT AND EMP TABLE FOR THE FIELD DEPTNO CREATE CLUSTER C1 "DEPTNO NUMBER"2))% CREATE INDED ID# ON CLUSTER C1% CREATE TABLE DEPT1 "DNO NUMBER"2) PRIMARY KEY, DNAME CHAR"1)), LOC CHAR"1))) CLUSTER C1"DNO)% CREATE TABLE EMP1 "EMPNO NUMBER"') PRIMARY KEY, ENAME CHAR"1)), HIREDATE DATE, SALARY NUMBER"!,2), DEPTARTMENTNO NUMBER"2) REFERENCES DEPT1"DNO)) CLUSTER C1"DEPTARTMENTNO)%

21,: SOL:

INSERT INTO TABLES DEPT1 AND EMP1 EACH THREE RO?S AND CHECK THE RO?ID OF THE T?O CLUSTER TABLES% INSERT INTO DEPT1 VALUES"MDNO,(MDNAME(,(MLOC()% INSERT INTO EMP1 VALUES"MEMPNO,(MENAME(,(MHIREDATE(,MSALARY, MDEPARTMENTNO)% SELECT DEPT1 RO?ID,EMP1 RO?ID FROM DEPT1,EMP1% LIST ALL THE CLUSTERS CREATED IN YOUR LO*IN SELECT @ FROM USERPCLUSTERS% CREATE A SYNONYM FOR TABLE EMP CREATE SYNONYM SY1 FOR EMP% LIST INFORMATION OF SYNONYM

21G: SOL: 21!: SOL: 22$:

SOL: 221: SOL: 222: SOL:

SELECT @ FROM SY1% LIST ALL THE SYNONYM CREATED IN YOUR LO*IN SELECT @ FROM USERPSYNONYMS% DROP THE SYNONYM CREATED DROP SYNONYM SY1% &OB M*R HIREDATE SAL

EMPNO ENAME COMM DEPTNO 22#:

CREATE THE EMPLOYEE REPORT OF THE COLUMNS EMPNO,ENAME,&OB M*R,HIREDATE,SAL,COMM,DEPTNO IN THE FORMAT BELO?: BRAIN?ARE INFOTECH"P) LTD

HEADER:

EMPLOYEES REPORT COLUMN: NAMES EMPLOYEE EMPLOYEE DESI*NATION MANA*ER NUMBER NAME NUMBER COMMISION DEPARTMENT NUMBER DATE OF &OININ* CURRENT SALARY

FOOTER: SOL:

HAVE A NICE DAY W TTITLE BTITLE COLUMN COLUMN COLUMN COLUMN COLUMN COLUMN COLUMN COLUMN LEFT(BRAIN?ARE INFOTECH"P) LTDQ CENTER (EMPLOYEES REPORT( (HAVE A NICE DAYW( EMPNO HEADIN* (EMPLOYEE Q NUMBER( ENAME HEADIN* (NAME OF Q EMPLOYEE( &OB HEADIN* ( DESI*NATION( M*R HEADIN* (MANA*ER Q NUMBER( HIREDATE HEADIN* ( DATE OF Q &OININ* ( SAL HEADIN* ( CURRENT Q SALARY ( COMM HEADIN* (COMMISION ( DEPTNO HEADIN* (DEPARTMENT Q NUMBER(

Pa>:a;4 S/4>-6->a2-5n T34 /a>:a;4 ./4>-6->a2-5n >5n2a-n. /I=0-> d4>0a9a2-5n. T34 .>5/4 56 234.4 d4>0a9a2-5n. -. 05>a0 25 15I9 da2a=a.4 .>347a and ;05=a0 25 234 /a>:a;4 S5, 234 d4>0a94d 5=<4>2. a94 a>>4..-=04 6957 15I9 a//0->a2-5n

and 6957 an183494 -n 234 /a>:a;4 Y@@@@@@@@@@@@@@@@Y PACKA*ES Y@@@@@@@@@@@@@@@@Y Y@@@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@@@Y 1 FUNCTION ALL ?RITE A FUNCTION TO RETURN MAD"EMPNO)H1 ?RITE A PROCEDURE TO FETCH THE DETAILS ?HEN EMPNOARESULT OF ?RITE A FUNCTION TO PASS EMPLOYEE NUMBER AND *ET THE &OB ?RITE A PROCEDURE TO ACCEPT DEPTNO AND DISPLAY THE DETAILS OF EMPLOYEES OF THAT PARTICULAR DEPARTMENT "HINT : CURSOR) ?RITE A PACKA*E ?HICH INCLUDES ALL THESE PROCEDURES AND FUNCTIONS

PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPN CREATE OR REPLACE PACKA*E EMPPPACK IS FUNCTION NEDTEMP RETURN NUMBER% PROCEDURE P1% FUNCTION F2"ENO NUMBER) RETURN VARCHAR% PROCEDURE P2"DNO NUMBER)% CURSOR C1 IS SELECT @ FROM EMP% END 47/P/a>:% CREATE OR REPLACE PACKA*E BODY EMPPPACK IS FUNCTION NEDTEMP RETURN NUMBER IS CURRPMAD NUMBER:A$% BE*IN SELECT MAD"EMPNO) INTO CURRPMAD FROM EMP% CURRPMAD:ACURRPMADH1% RETURN CURRPMAD% END NEDTEMP% PROCEDURE P1 IS ENO NUMBER% NAME VARCHAR2"1$)% DEPNO NUMBER% SALARY EMP SALOTYPE% BE*IN ENO:AEMPPPACK NEDTEMP% PRINT"(NE? EMPLOYEE NUMBER IS(QQENO)% SELECT ENAME,SAL,DEPTNO INTO NAME,SALARY,DEPNO FROM EMP ?HERE EMPNOAENO% PRINT"ENOQQ( (QQNAMEQQ( (QQDEPNOQQ( (QQSALARY)% EDCEPTION ?HEN NOPDATAPFOUND THEN PRINT"(NO DATA FOUND()% END P1%

PROCEDURE P2"DNO NUMBER) IS CURSOR C1 IS SELECT @ FROM EMP ?HERE DEPTNOADNO% BE*IN FOR I IN C1 LOOP DBMSPOUTPUT PUTP0INE"I ENAMEQQ( (QQI &OBQQ( (QQI DEPTNO)% END LOOP% EDCEPTION ?HEN NOPdATAPFOUND THEN PRINT"(NO DATA FOUND()% END P2% FUNCTION F2"ENO NUMBER) RETURN VARCHAR IS DESI* EMP &OBOTYPE% BE*IN SELECT &OB INTO DESI* FROM EMP ?HERE EMPNOAENO% RETURN DESI*% END F2% END EMPPPACK% DECLARE NEDTEMP NUMBER% F2 EMP &OBOTYPE% BE*IN NEDTEMP:AEMPPPACK NEDTEMP% PRINT"(NEDTEMP IS (QQNEDTEMP)% EMPPPACK P1% F2:AEMPPPACK F2"MEMPNO)% PRINT"(PRINTIN* &OB FROM F2 (QQF2)% EMPPPACK P2"MDEPTNO)% END% Y@@@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@@@Y 1 C94a24 a /a>:a;4 23a2 >5n2a-n. 234 650058-n; .I= /95;9a7. "a) P95>4dI94 NE?PEMP 25 add a n48 47/05144 25 234 47/ 2a=04 "=) P95>4dI94 UPDATEPEMP 25 I/da24 234 47/05144 d42a-0. "d-./0a1 49959 74..a;4 -6 - 4 49959) ">) FIn>2-5n CHECKPEMP 25 >34>: -6 an 47/05144 -. 4E-.2-n; -n 234 2a=04

PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PP CREATE OR REPLACE PACKA*E *EEPACK IS PROCEDURE NE?PEMP"4n5 nI7=49,dn5 nI7=49,7; nI7=49,na74 Ja9>3a92)% PROCEDURE UPDATEPEMP"N NUMBER)% FUNCTION CHECKP4MP"N NUMBER) RETURN NUMBER% END *EEPACK%

CREATE OR REPLACE PACKA*E BODY *EEPACK IS

PROCEDURE NE?PEMP"ENO NUMBER, DNO NUMBER,M* NUMBER,NAME VARCHAR2) IS BE*IN INSERT INTO EMP"EMPNO,DEPTNO,M*R,ENAME) VALUES"ENO,DNO,M*,NAME)% END NE?PEMP% PROCEDURE UPDATEPEMP "N NUMBER) IS DESI* VARCHAR2"1$)% BE*IN SELECT &OB INTO DESI* FROM EMP ?HERE EMPNOAN% DBMSPOUTPUT PUTPLINE"(EMPNO A (QQNQQ( &OB A (QQDESI*)% IF DESI*A(CLERK( THEN UPDATE EMP SET &OBA(FDC( ?HERE EMPNOAN% /9-n2"(<5= I/da24d 25 6d>()% ELSIF DESI*A(MANA*ER( THEN UPDATE EMP SET &OBA(D*M( ?HERE EMPNOAN% /9-n2"(<5= I/da24d 25 d;7()% END IF% END UPDATEPEMP% FUNCTION CHECKP4MP "N NUMBER) RETURN NUMBER IS N1 NUMBER% BE*IN SELECT COUNT"@) INTO N1 FROM EMP ?HERE EMPNOAN% IF n1A$ 234n PRINT"(EMPLOYEE (QQnQQ( d54. n52 EDISTS ()% ELSE PRINT"(EMPLOYEE (QQnQQ( EDIST.()% END IF% 942I9n n1% END CHECKPEMP% END *EEPACK% d4>0a94 4n5 nI7=49:AM47/n5% dn5 nI7=49:AMd4/2n5% 7; nI7=49:AM7;9% na74 Ja9>3a92"1$):A(Mna74(% 94. nI7=49% =4;-n /9-n2"(n48P47/ -. >a004d and Ja0I4. 8-00 =4 -n.4924d()% ;44/a>: n48P47/"4n5,dn5,7;,na74)% ;44/a>: I/da24P47/"MI/da24n5)% 94.:A;44/a>: CHECKP4MP"M>34>:n5)% /9-n2"94.)% 4nd%

Y@@@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@@@Y ?RITE A FUNCTION TO RETURN MAD"EMPNO)H1 ?RITE A PROCEDURE TO FETCH THE DETAILS ?HEN EMPNOARESULT OF FUNCTION ?RITE A PROCEDURE TO ACCEPT DEPTNO AND DISPLAY THE DETAILS OF

ALL

EMPLOYEES OF THAT PARTICULAR DEPARTMENT "HINT : CURSOR) ?RITE A PACKA*E ?HICH INCLUDES ALL THESE PROCEDURES AND FUNCTIONS

CREATE OR REPLACE PACKA*E PACK IS FUNCTION F1 RETURN NUMBER % PROCEDURE P1"N NUMBER)% PROCEDURE P2"DNO NUMBER)% END% CREATE OR REPLACE PACKA*E BODY PACK IS FUNCTION F1 RETURN NUMBER IS T NUMBER% BE*IN SELECT MAD"EMPNO)H1 INTO T FROM EMP% RETURN T% END%

PROCEDURE P1"N NUMBER) IS A NUMBER% NAME VARCHAR2"1$)% BE*IN A:AF1% SELECT ENAME INTO NAME FROM EMP ?HERE EMPNOAA% PRINT"(THE NAME IS (QQA)% EDCEPTION ?HEN NOPDATAPFOUND THEN PRINT"(NO DATA()% END%

PROCEDURE P2"DNO NUMBE9) IS CURSOR C2 IS SELECT @ FROM EMP ?HERE DEPTNOADNO% BE*IN FOR I IN C2 LOOP PRINT"I ENAMEQQ( (QQI DEPTNO)% END LOOP% END % END%

DECLARE F1RES NUMBER% BE*IN

F1RES:APACK F1% PRINT"(THE RESULT OF FUNCTION IS (QQF1RES)% PACK P1"F1RES)% PACK P2"MDEPTNO)% END% >94a24 2a=04 O9dTa= " O9dId NI7=49, CI.25749PNa74 Ja9>3a92"1$), O9dDa24 Da24, T52a0 NI7=49 ) Pa92-2-5n B1 Ran;4"O9dId) " Pa92-2-5n P1 VA0I4. L4.. T3an "1$$), Pa92-2-5n P2 Va0I4. L4.. T3an "2$$), /a92-2-5n /# Ja0I4. 04.. 23an"#$$) )% F59 234 >50I7n 59d-d 56 234 59d2a= 2a=04 ./4>-6-4d Ja0I4. !! !G 1$$ 1)$ 1!! 2$$ 2)$ 2!$ 834n - 8a. a=5J4 25 -n.492 - 3aJ4 -n.4924d 234 =4058

#$$ 23-. -. 83a2 3a//4n4d

-n.492 -n25 59d2a="59d-d) Ja0I4."#$$) @ ERROR a2 0-n4 1: ORAN1''$$: -n.4924d /a92-2-5n :41 -. =415nd 3-;34.2 04;a0 /a92-2-5n :41

S5,25 5J49>574 23-. >94a24 2a=04 O9dTa= " O9dId NI7=49, CI.25749PNa74 Ja9>3a92"1$), O9dDa24 Da24, T52a0 NI7=49 ) Pa92-2-5n B1 Ran;4"O9dId) " Pa92-2-5n P1 VA0I4. L4.. T3an "1$$), Pa92-2-5n P2 Va0I4. L4.. T3an "2$$), Pa92-2-5n P# Va0I4. L4.. T3an "MaEVa0I4) )%

NO? I INSERTED THE VALUES !$ 1$$$ 2)$ #)$ ')$ 2$$ SELECT @ FROM ORDTAB PARTITION "P1)% ORDID CUSTOMERPN ORDDATE TOTAL NNNNNNNNN NNNNNNNNNN NNNNNNNNN NNNNNNNNN !$ TRY THE SAME THIN* ?ITH P2 AND P# SQLF SELECT PARTITIONPNAME FROM USERPTABPPARTITIONS%

PARTITIONPNAME NNNNNNNNNNNNNNNNNNNNNNNNNNNNNN P1 P2 P# SQLF ALTER TABLE ORDTAB SPLIT PARTITION P1 AT ")$)% Ta=04 a02494d SQLF SELECT PARTITIONPNAME FROM USERPTABPPARTITIONS%

PARTITIONPNAME NNNNNNNNNNNNNNNNNNNNNNNNNNNNNN P2 P# SYSPP+1 SYSPP+2 SQLF SELECT @ FROM ORDTAB PARTITION"SYSPP+1)% ORDID CUSTOMERPN ORDDATE TOTAL NNNNNNNNN NNNNNNNNNN NNNNNNNNN NNNNNNNNN ') SQLF SELECT @ FROM ORDTAB PARTITION"SYSPP+2)% ORDID CUSTOMERPN ORDDATE TOTAL NNNNNNNNN NNNNNNNNNN NNNNNNNNN NNNNNNNNN !$ +) ALTER TABLE ORDTAB SPLIT PARTITION P2 AT "1)$) INTO "PARTITION P),PARTITION P+)%

Ta=04 a02494d SQLF SELECT PARTITIONPNAME FROM USERPTABPPARTITIONS% "ALSO *IVE THE COMMAND SELECT PARTITIONPNAME,TABLEPNAME FROM USERP2ABPPARTITIONS) SELECT TABLEPNAME,PARTITIONPNAME,HI*HPVALUE FROM USERP2ABPPARTITIONS% PARTITIONPNAME NNNNNNNNNNNNNNNNNNNNNNNNNNNNNN P) P# SYSPP+1 SYSPP+2 P+ ADD PARTITION ~~~~~~~~~~~~~ CREATE TABLE ** " ACNO NUMBER"#), a>21/4 Ja9>3a92"#), a>=a0 nI7=49"')) /a92-2-5n =1 9an;4"a>=a0) "/a92-2-5n /1 Ja0I4. 04.. 23an")$$$), /a92-2-5n /2 Ja0I4. 04.. 23an"+$$$))% Ta=04 >94a24d SQLF a0249 2a=04 ;; add /a92-2-5n 7aE/ Ja0I4. 04.. 23an"7aEJa0I4)% Ta=04 a02494d DROP PARTITION ~~~~~~~~~~~~~~~~~ ALTER TABLE ** DROP PARTITION P1% ALTER TABLE LTABLENAMEF DROP PARTITION LPARTITION NAMEF RENAME PARTITION ~~~~~~~~~~~~~~~~~~ ALTER TABLE EMP RENAME PARTITION P) TO P+% >94a24 2a=04 59d2a= " 59d-d nI7=49"'), /9d-d nI7=49"'), 59dna74 Ja9>3a92"1$) ) /a92-2-5n =1 9an;4"59d-d,/9d-d) " /a92-2-5n /1 Ja0I4. 04.. 23an"2),)$), /a92-2-5n /2 Ja0I4. 04.. 23an")$,,)), /a92-2-5n /# Ja0I4. 04.. 23an",),1$$) )%

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ TO CREATE AN INDEDED PARTITION >94a24 2a=04 O9dTa= " O9dId NI7=49, CI.25749PNa74 Ja9>3a92"1$), O9dDa24 Da24, T52a0 NI7=49 ) Pa92-2-5n B1 Ran;4"O9dId) " Pa92-2-5n P1 VA0I4. L4.. T3an "1$$), Pa92-2-5n P2 Va0I4. L4.. T3an "2$$), /a92-2-5n /# Ja0I4. 04.. 23an"MADVALUE) )%

CREATE INDED ORDID ON ORDTAB"ORDID) LOCAL "PARTITION P1,PARTITION P2,PARTITION P#)% CREATE INDED ORDID ON ORDTAB"ORDID) *LOBAL PARTITION BY RAN*E"ORDID) "PARTITION P1 VALUES LESS THAN"1$), PARTITION P2 VALUES LESS THAN"2$), PARTITION P# VALUES LESS THAN"MADVALUE))% LIST THE TREE STRUCTURED QUERY ?ITH EMPLOYEE NAME STARTIN* ?ITH KIN* SOL: SELECT LPAD"( (,+@"LEVELN1))QQENAME NAME FROM EMP START ?ITH ENAMEA(KIN*( CONNECT BY M*RAPRIOR EMPNO%

~~~~~~~~~~~~~~~~~~~~ SIMPLE PLRSQL BLOCKS ~~~~~~~~~~~~~~~~~~~~ d4>0a94 a nI7=49% = nI7=49% =4;-n A:A2)% B:A)$% d=7.P5I2/I2 /I2P0-n4"(THE CONTENT OF A IS(QQA)% d=7.P5I2/I2 /I2P0-n4"(THE CONTENT OF B IS(QQB)% 4nd%

d4>0a94 a nI7=49:AMA% = nI7=4R:AMB% =4;-n d=7.P5I2/I2 /I2P0-n4"(THE CONTENT OF A IS (QQA)% d=7.P5I2/I2 /I2P0-n4"(THE CONTENT OF B IS (QQB)% 4nd% d4>0a94 a nI7=49:AMA% = nI7=4R:AMB% PROD NUMBER% =4;-n PROD:AA@B% d=7.P5I2/I2 /I2P0-n4"(THE CONTENT OF A IS (QQA)% d=7.P5I2/I2 /I2P0-n4"(THE CONTENT OF B IS (QQB)% d=7.P5I2/I2 /I2P0-n4"(THE PRODUCT IS (QQPROD)% 4nd% d4>0a94 a nI7=49:A1$% = nI7=49:A2$% 94. nI7=49% =4;-n 94.:AaH=% d=7.P5I2/I2 /I2P0-n4"aQQ ( (QQ=)% d=7.P5I2/I2 /I2P0-n4"(T34 .I7 -. (QQ94.)% 4nd%

d4>0a94 a nI7=49:AMa% = nI7=49:AM=% 94. nI7=49% =4;-n 94.:AaH=% d=7.P5I2/I2 /I2P0-n4"aQQ ( (QQ=)% d=7.P5I2/I2 /I2P0-n4"(T34 .I7 -. (QQ94.)% 4nd% d4>0a94 a nI7=49:AMa% = nI7=49:AM=% =4;-n -6 "aF=) 234n d=7.P5I2/I2 /I2P0-n4"(B-;;4.2 nI7=49 -.(QQ( (QQa)% 40.4 d=7.P5I2/I2 /I2P0-n4"(B-;;4.2 nI7=49 -.(QQ( (QQ=)% 4nd -6% 4nd% d4>0a94

a nI7=49:AMa% =4;-n -6 75d"a,))A$ 234n d=7.P5I2/I2 /I2P0-n4"(I2 -. d-J-.-=04 =1 )()% 40.4 d=7.P5I2/I2 /I2P0-n4"(I2 -. n52 d-J-.-=04 =1 )()% 4nd -6% 4nd%

d4>0a94 n >3a9"1$):A(Mn(% =4;-n SELECT UPPER"N) INTO N FROM DUAL% -6 nA(F( 234n d=7.P5I2/I2 /I2P0-n4"(FIRST CLASS()% ELSIF NA(S( THEN d=7.P5I2/I2 /I2P0-n4"(SECOND CLASS()% ELSIF NA(T( THEN d=7.P5I2/I2 /I2P0-n4"(THIRD CLASS()% 40.4 d=7.P5I2/I2 /I2P0-n4"(FAILED()% END IF% END% d4>0a94 n nI7=49:A1% =4;-n 055/ d=7.P5I2/I2 /I2P0-n4"n)% n:AnH1% 4E-2 834n nA11% 4nd 055/% 4nd% d4>0a94 a nI7=49:A1% =4;-n 83-04 "aLA1$) 055/ d=7.P5I2/I2 /I2P0-n4"a)% a:AaH1% 4nd 055/% 4nd% d4>0a94 =4;-n 659 a -n 1 1$ 055/ d=7.P5I2/I2 /I2P0-n4"a)% 4nd 055/% 4nd% d4>0a94 =4;-n 659 a -n 94J49.4 1

1$ 055/

d=7.P5I2/I2 /I2P0-n4"a)% 4nd 055/% 4nd% d4>0a94 n nI7=49:AMn% - nI7=49:A1% =4;-n 83-04 -LAn 055/ d=7.P5I2/I2 /I2P0-n4"-)% -:A-H2% 4nd 055/% 4nd% d4>0a94 n nI7=49:AMn% - nI7=49:A1% =4;-n 83-04 -LAn 055/ d=7.P5I2/I2 /I2"-)% -:A-H2% 4nd 055/% d=7.P5I2/I2 n48P0-n4% 4nd% DECLARE BE*IN FOR I IN 1 1$ LOOP DBMSPOUTPUT PUTPLINE"I)% IF IA) THEN EDIT% END IF% END LOOP% END% d4>0a94 n nI7=49:AMn% =4;-n d=7.P5I2/I2 /I2P0-n4"(4J4n nI7=49. a94()% 659 - -n 1 n 055/ -6 75d"-,2)A$ 234n d=7.P5I2/I2 /I2P0-n4"-)% 4nd -6% 4nd 055/% 4nd% 25 d-./0a1 nI7=49. 6957 1 25 n -n d4>0a94 n nI7=49:AMn% =4;-n 659 - -n 1 n 055/ d=7.P5I2/I2 /I2"-)% 4nd 055/% d=7.P5I2/I2 n48P0-n4% .a74 0-n4

4nd% 25 d-./0a1 234 .I7 56 n nI7=49. d4>0a94 n nI7=49:AMn% .I71 nI7=49:A$% =4;-n d=7.P5I2/I2 /I2P0-n4"(234 nI7=49. a94()% 659 - -n 1 n 055/ d=7.P5I2/I2 /I2P0-n4"-)% .I71:A.I71H-% 4nd 055/% d=7.P5I2/I2 /I2P0-n4"(SUM IS (QQSUM1)% END%

DECLARE N NUMBER:AMN% RES NUMBER% BE*IN FOR I IN 1 1$ LOOP

RES:AN@I% DBMSPOUTPUT PUTPLINE"N QQ ( @ END LOOP% END%

(QQ I QQ ( A (QQ RES )%

*ENERAL PROBLEMS 1 ?9-24 a PLRSQL P95;9a7 25 d-./0a1 1$$ a00 234 EVEN NI7=49 6957 1 25

2 ?9-24 a PLRSQL P95;9a7 25 0-.2 a00 234 EVEN M ODD NI7=49 6957 1 25 1$$ a. F50058. EJ4n NI7=49. Odd NI7=49. NNNNNNNNNNNNNNNNNNN NNNNNNNNNNNNNNNN N $ 1 2 # ' )

# ?9-24 a PLRSQL P95;9a7 25 F-nd 234 .I7 56 nI7=49. =42844n 1 and 1$$ 23a2 a94 d-J-.-=04 =1 ) =I2 n52 d-J-.-=04 =1 , ' ) + ?9-24 a PLRSQL S>9-/2 25 6-nd a00 234 PRIME NUMBERS 6957 1 25 1$$ ?9-24 a PLRSQL /95;9a7 25 6-nd ARMSTRON* NUMBERS 6957 1$$ 25 !!!

?9-24 a PLRSQL /95;9a7 25

L-.2 25 FIBBNOCI SERIES FROM $ TO 1$$ 234 MI02-/0->a2-5n Ta=04 659 234 -.

, ?9-24 a PLRSQL P95;9a7 25 D-./0a1 ;-J4n -n/I2

G ?9-24 a PLRSQL P95;9a7 25 D-./0a1 234 ;-J4n -n/I2 .29-n; PALINDROME OR NOT ! ?9-24 a PLRSQL P95;9a7 25 REVERSE 234 ;-J4n -n/I2 .29-n;

1$ ?9-24 a PLRSQL P95;9a7 25 F-nd 5I2 YEAR OR NOT

234 *-J4n In/I2 da2a -.

LEAP

11 ?9-24 a PLRSQL P95;9a7 25 d-./0a1 F-9.2, S4>5nd,T3-9d *94a24.2 nI7=49 F957 ;-J4 23944 nI7=49. 12 ?9-24 a PLRSQL P95;9a7 25 6-nd 5I2 234 RAMAN NUMBER =42844n 1$$$ and !!!! 4E : 12## , 12@12H##@## A 12## 1# ?9-24 a PLRSQL P95;9a7 25 d-./0a1 234 J5840. 6957 234 -n/I2 .29-n; 1' ?9-24 a PLRSQL P95;9a7 25 d-./0a1 234 J5840., N5 56 J5840.,/5.-2-5n 56 4a>3 J5840. and 5>>I994n>4. 56 4a>3 J5840. 1) ?9-24 a PLRSQL P95;9a7 25 6-nd 5I2 a ;-J4n .I= .29-n; 6957 234

;-J4n Ma-n .29-n; "?-235I2 INSTR FUNCTION)

I.-n; N5 56 >3a9a>249., N5 56

1+ ?9-24 a PLRSQL P95;9a7 25 6-nd 5I2 d-;-2., N5 56 ./4>-a0 C3a9a>249. 6957 234 ;-J4n -n/I2

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@ CURSOR PROBLEMS 1 ?9-24 a PLRSQL P95;9a7 25 C5/1 234 da2a 6957 On4 2a=04 25 an52349 83->3 3a. 234 .a74 .29I>2I94 8-23 234 RECORD NUMBER 2 A..I74 234 650058-n; 2a=04 659 234 ;-J4n /95=047 : ID NAME MARK1 MARK2 MARK# MARK' 1$$$ AYYAPPAN !$ 1$$ !! !) BASKER 1$$2 #$ 2$ 2) ,$ 1$$1 N B SIN* )$ +$ #) ?9-24 a PLRSQL P95;9a7 25 d-./0a1 a00 234 234 TOTAL, AVERA*E, T34 *RADE -. =a.4 5n 234 650058-n; >5nd-2-5n 1 =42844n 1$$ and !$ A *RADE 2 =42844n G! and G$ B *RADE # =42844n ,! and ,$ C *RADE ' 523498-.4 ?ASTE .2Id4n2 -n6597a2-5n !$

8-23 *RADE

?9-24 a PLRSQL P95;9a7 25 d-./0a1 234 650058-n; 5I2/I2 =a.4 5n 234 d4/a9274n2 : D4/a9274n2 Na74 L5> >57/I249 Ena74 <53n SMITH Ban;a0594 Sa0 )$$$ +$$$ C577 1$$ NULL

D4/a9274n2 N5 1$ E7/n5 H-94da24 1$$$ 12NMARN!G 1$$1 #$N&ANN!G

'

?9-24 a PLRSQL P95;9a7 25 d-./0a1 234 650058-n; 5I2/I2 : <5= : MANA*ER N5 56 Mana;49. SI7 56 Sa0a91 # )'$$$ &53n,.7-23,7-0049 <5= : CLERK NNNNNNN NNNNNNNN NNNNNNNNNNNNN

Na74.

) ?9-24 a PLRSQL P95;9a7 25 D-./0a1 234 F-9.2 ) MaE-7I7 Sa0a91 I.-n; Pa9a74249 25 T34 >I9.59 + ?9-24 a PLRSQL P95;9a7 25 d-./0a1 a00 234 .a0a91 59d49 8-235I2 I.-n; 234 59d49 =1 >0aI.4 -n 234 CURSOR SELECT .2a2474n2

=1

-n 234 d4.>4nd-n;

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@ EDCEPTION A..I74 234 650058-n; 2a=04 659 234 /95=047. ;-J4n =4058: Ta=04 Na74 : BANK A>>Pn5 A>>Pna74 CI99P=a0an>4 nI7=49"+) Ja9>3a9"'$) nI7=49"2$,')

1 ?9-24 a PLRSQL P95;9a7 25 ?ITHDRA? 75n41 6957 a /a92->I0a9 a>>5In2 T34 A>>Pn5 and CI99P=a0a>4 .35I0d =4 4n2494d 6957 :41=5a9d T34 4E>4/2-5n. 9a-.4d a94 a) A>>Pn5 n52 65Ind =) OJ49 D9a8n >) 255 7an1 958. 942I9n4d 2 ?9-24 a PLRSQL P95;9a7 25 CREDIT 75n41 25 a /a92->I0a9 a>>5In2 and 942I9n 234 >I994n2 =a0an>4 T34 a>>5In2 nI7=49 and a75In2 .35I0d =4 4n2494d 2395I;3 :41=5a9d T34 4E>4/2-5n. a94 : a) a>>5In2 nI7=49 n52 65Ind =)

# ?9-24 a PLRSQL P95;9a7 25 add a NE? a>>5In2 350d49 =1 ;422-n; 234 -n/I2 6957 234 I.49 I.-n; 234 4E>4/2-5n a) dI/0->a24 a>>5In2 nI7=49 =) 255 7an1 958. >) -nJa0-d nI7=49 and Ja0I4 49959 ' ?9-24 a PLRSQL P95;9a7 25 DELETE a>>5In2 350d49 =1 4n249-n; 234 a>>5In2 nI7=49 T34 4E>4/2-5n a)n5 da2a 65Ind =)B46594 d40424 d-./0a1 234 >I994n2 =a0an>4 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@ SUBPRO*RAM 1 ?9-24 a PLRSQL P95;9a7 25 S?AP 234 247/59a91 Ja9-a=04, =1 I.-n; 234 PROCEDURE 234 285 -n/I2 nI7=49 8-235I2 I.-n;

2 ?9-24 a PLRSQL P95;9a7 25 6-nd 5I2 234 6a>259-a0 56 nI7=49 I.-n; 94>I9.-J4 6In>2-5n

;-J4n -n/I2

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@

DATABASE 1 2 #

TRI**ERS

?9-24 a da2a=a.4 29-;;49 25 -7/0474n2 234 PRIMARY KEY CONSTRAINT ?9-24 a ?9-24 da2a=a.4 29-;;49 25 -7/0474n2 234 FOREI*N KEY CONSTRAINT a da2a=a.4 29-;;49 25 -7/0474n2 234 ON DELETE CASCADE d-.a0058 234 DELETE 5/49a2-5n 6957

' ?9-24 a da2a=a.4 29-;;49 25 52349. U.49 4E>4/2 O8n49

) ?9-24 a da2a=a.4 29-;;49 25 aI257a2->a001 >5nJ492 234 05849 >a.4 47/05144 na74 25 UPPER CASE 47/05144 na74 83-04 4n249-n; + ?9-24 a da2a=a.4 29-;;49 25 d-.a0058 an1 5/49a2-5n 5n SUNDAY and an1 da1 BEFORE ! AM AND AFTER + PM , ?9-24 a da2a=a.4 29-;;49 25 >5/1 234 d40424d 8-23 USER,DATE,TIME G ?9-24 a da2a=a.4 29-;;49 25 /a92->I0a9 2a=04 ! ?9-24 a da2a=a.4 ;4n49a24 94>59d 83->3 3a. =44n 234 .49-a0 nI7=49 659 234 a ' d-;-2

29-;;49 25 Ja0-da24 234 47/n5 a.

nI7=49 1$ ?9-24 a da2a=a.4 29-;;49 25 Ja0-da24 234 >577 7a1 =4 NULL 59 04.. 234n 1R' 56 234 .a0a91 and 7I.2 n52 =4 n4;a2-J4 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@ PACKA*ES 1 C94a24 a /a>:a;4 23a2 >5n2a-n. 234 650058-n; .I= /95;9a7. "a) P95>4dI94 NE?PEMP 25 add a n48 47/05144 25 234 47/ 2a=04 "=) P95>4dI94 UPDATEPEMP 25 I/da24 an1 47/5144. d42a-0. 8-23 /95/49 49959 74..a;4 ">) FIn>2-5n CHECKPEMP 25 >34>: -6 an 47/05144 -. 4E-.2-n; 234 2a=04 "d) P95>4dI94 DELETEPEMP 25 d40424 an 47/05144 Z. 94>59d "4) P95>4dI94 ERRORPMESSA*E 25 d-./0a1 49959 74..a;4 ;4n49a24d =1 an1 56 234 a=5J4 /95>4dI94 59 6In>2-5n. 2 C94a24 a /a>:a;4 25 >5ndI>2 =an: 29an.a>2-5n. -nJ50J-n; 234 650058-n; /95>4dI94. and 6In>2-5n. "a) D4=-2 "=) C94d-2 ">) N48 a>>5In2 "d) &5I9na0 4n291 94>59d-n; a00 29an.a>2-5n"A>>2P-d, T9an.P21/4, .1.da24) "4) En249 234 29an.a>2-5n. 8-23 .2a2I. /4nd-n; BLOCKS CREATED ON 1 *OTO 2 EDIT # EDIT ?HEN ' *ENERATE EVENRODD SERIES ) *ENERATE MULTIPLICATION TABLES + REVERSE OF NUMBER , REVERSE OF STRIN* G PRIME OR NOT ! SQUARE 1$ M TO PO?ER N 11 ODD AND EVEN SERIES TO*ETHER 12 ACCEPT SYMBOL FROM USER AND DEPENDIN* ON THAT ADD,SUBTRACT,MULTIPLY OR DIVIDE 2 NUMBERS 1# *ENERATE NUMBERS IN FIBONACCI SERIES 1' FACTORIAL OF NUMBER

1 NNNNNNNNN*OTO STATEMENT ~~~~~~~~~~~~~~ DECLARE BE*IN FOR I IN 1 1$ LOOP DBMSPOUTPUT PUTP0INE"I)% IF IA) THEN *OTO AA% END IF% END LOOP% LLAAFF DBMSPOUTPUT PUTP0INE"(OUTSIDE THE LOOP()% END% OUTPUT IS 1 2 # ' ) HELLO DECLARE A NUMBER:AMA% B NUMBER:AMB% BE*IN a:AaH=H1$$% -6 aF1$$$ 234n ;525 SS% 40.4 d=7.P5I2/I2 /I2P0-n4"(5I2 /I2 n52 ;94a249 23an 1$$$()% 4nd -6% LLSSFF d=7.P5I2/I2 /I2P0-n4"a)%

END %

2 NNNNNNNNNNNNNNNNNEDIT STATEMENT ~~~~~~~~~~~~~~ DECLARE BE*IN FOR I IN 1 1$ LOOP DBMSPOUTPUT PUTP0INE"I)% IF IA) THEN EDIT% END IF% END LOOP% END% OUTPUT IS 1 2 # ' )

# NNNNNNNNNNNNNNNNEDIT ?HEN STATEMENT ~~~~~~~~~~~~~~~~~~~ DECLARE BE*IN FOR I IN 1 1$ LOOP DBMSPOUTPUT PUTP0INE"I)% EDIT ?HEN IA)% END LOOP% END% OUTPUT IS 1 2 # ' ) ' NNNNNNNNNNNNNNNNNNNNNNN?HILE LOOP ~~~~~~~~~~ *ENERATE ODDREVEN NUMBERS DECLARE N NUMBER:AMN% I NUMBER:A1% BE*IN ?HILE"ILN) LOOP DBMSPOUTPUT PUTP0INE"I)% I:AIH2% END LOOP% END% "FOR EVEN SERIES REPLACE 1 ?ITH $)% DECLARE N NUMBER:AMN% BE*IN FOR I IN 1 N LOOP IF MOD"I,2)A$ THEN DBMSPOUTPUT PUTP0INE"I)% END IF% END LOOP% END% ) NNNNNNNNNNNNNNNNNNNNMULTIPLICATION TABLES ~~~~~~~~~~~~~~~~~~~~~ DECLARE N NUMBER:AMN% RES NUMBER% BE*IN DBMSPOUTPUT PUTP0INE"(THE MULTIPLICATION TABLE IS()% FOR I IN 1 1$ LOOP RES:AN@I% DBMSPOUTPUT PUTPLINE"N QQ( @ (QQI QQ( A (QQRES)%

END LOOP% END%

~~~~~~~~~~~~~~~~~~~~~ + NNNNNNNNNNNNNNNNREVERSE OF A NUMBER ~~~~~~~~~~~~~~~~~~~ DECLARE N NUMBER:AMN% R NUMBER:A$% L NUMBER% BE*IN L:ALEN*TH"N)% FOR I IN 1 L LOOP R:AR@1$HMOD"N,1$)% N:AFLOOR"NR1$)% END LOOP% NNDBMSPOUTPUT PUTPLINE"N)% DBMSPOUTPUT PUTPLINE"R)% END%

DECLARE N NUMBER:AMN% R NUMBER% L NUMBER% BE*IN DBMSPOUTPUT PUTPLINE"(THE NUMBER IS (QQN)% L:ALEN*TH"N)% FOR I IN 1 L LOOP R:ARQQMOD"N,1$)% N:AFLOOR"NR1$)% END LOOP% DBMSPOUTPUT PUTPLINE"(THE REVERSE OF THE NUMBER IS END% , NNNNNNNNNNNNNNNNNNREVERSE OF A STRIN*

(QQR)%

DECLARE N VARCHAR2"12):A(MN(% REV VARCHAR2"12)% LEN NUMBER% BE*IN DBMSPOUTPUT PUTPLINE"(STRIN* IS (QQN)% LEN:ALEN*TH"N)% FOR I IN REVERSE 1 LEN LOOP REV:AREVQQSUBSTR"N,I,1) % END LOOP% DBMSPOUTPUT PUTPLINE"(REVERSED STRIN* IS END%

(QQ9EV)%

GNNNNNNNNNNNNNNNNNNNNNPRIME OR NOT ~~~~~~~~~~~~ DECLARE N NUMBER:AMN% FLA* NUMBER:A1% BE*IN FOR I IN 2 NN1 LOOP IF MOD"N,I)A$ THEN FLA*:A$% EDIT% END IF% END LOOP% IF FLA*A$ THEN DBMSPOUTPUT PUTPLINE"(NUMBER IS NOT PRIME()% ELSE DBMSPOUTPUT PUTP0INE"(NUMBER IS PRIME()% END IF% END%

! NNNNNNNNNNNNNNNNNNDRA? A SQUARE DECLARE BE*IN FOR I IN 1 DBMSPOUTPUT DBMSPOUTPUT END LOOP% DBMSPOUTPUT FOR I IN 1 DBMSPOUTPUT END LOOP% FOR I IN 1 DBMSPOUTPUT DBMSPOUTPUT END LOOP% DBMSPOUTPUT END%

1$ LOOP PUT"(X()% PUT"( ()% NE?PLINE% 1$ LOOP PUTPLINE"(X 1$ LOOP PUT"(X()% PUT"( ()% NE?PLINE%

X()%

1$ NNNNNNNNNNNNNNNNNM RAISED TO NTH PO?ER DECLARE M NUMBER:AMM% N NUMBER:AMN% RES NUMBER% BE*IN RES:APO?ER"M,N)% DBMSPOUTPUT PUTP0INE"(M TO PO?ER OF N IS (QQRES)% END% 11 NNNNNNNNNNNNNNNNDISPLAY ODD AND EVEN SERIES

DECLARE BE*IN DBMSPOUTPUT PUTPLINE"(ODDNNNNNNNNNNNEVEN()% DBMSPOUTPUT PUTP0INE"(PPPPPPPPPPPPPPPPPP()% FOR I IN 1 2$ LOOP IF MOD"I,2) A $ THEN DBMSPOUTPUT PUTPLINE"( ELSE DBMSPOUTPUT PUT"I)% END IF% END LOOP% END%

(QQI)%

12 NNNNNNNNNNNNNNNNNNNNNNNNNNN ACCEPT SYMBOL FROM USER AND DEPENDIN* ON THAT ADD,SUBTRACT,MULTIPLY OR DIVIDE 2 NUMBERS

DECLARE NUM1 NUMBER:AMNUMBER1% SYB CHAR:A(MSYMBOL(% NUM2 NUMBER:AMNUMBER2% RESULT NUMBER% BE*IN IF SYBA(H( THEN RESULT:ANUM1HNUM2% ELSE IF SYBA(N( THEN RESULT:ANUM1NNUM2% ELSE IF SYBA(@( THEN RESULT:ANUM1@NUM2% ELSE IF SYBA(R( THEN RESULT:ANUM1RNUM2% END IF% END IF% END IF% END IF% DBMSPOUTPUT PUTPLINE"RESULT)% END%

PLRSQL Ta=04. O=<4>2. 56 21/4 TABLE a94 >a004d VPLRSQL 2a=04.,V 83->3 a94 75d4004d 5n "=I2 n52 234 .a74 a.) da2a=a.4 2a=04. PLRSQL 2a=04. I.4 a /9-7a91 :41 25 ;-J4 15I a99a1N0-:4 a>>4.. 25 958. T34 .-S4 56 a PLRSQL 2a=04 -. In>5n.29a-n4d T3a2 -., 234 nI7=49 56 958. -n a PLRSQL 2a=04 >an -n>94a.4 d1na7->a001 PLRSQL 2a=04. >an 3aJ4 5n4 >50I7n and a /9-7a91 :41, n4-2349 56 83->3 >an =4 na74d T34 >50I7n >an =405n; 25 an1 .>a0a9 21/4, =I2 234 /9-7a91 :41 7I.2 =405n; 25 21/4 BINARYPINTE*ER D4>0a9-n; PLRSQL Ta=04. PLRSQL 2a=04. 7I.2 =4 d4>0a94d -n 285 .24/. F-9.2, 15I d46-n4 a TABLE 21/4, 234n d4>0a94 PLRSQL 2a=04. 56 23a2 21/4 Y5I >an d4>0a94 TABLE 21/4. -n 234 d4>0a9a2-J4 /a92 56 an1 =05>:, .I=/95;9a7, 59 /a>:a;4 I.-n; 234 .1n2aE TYPE 21/4Pna74 IS TABLE OF [ >50I7nP21/4 Q Ja9-a=04OTYPE Q 2a=04 >50I7nOTYPE (D \NOT NULL] INDED BY BINARYPINTE*ER% 83494 V21/4Pna74V -. a 21/4 ./4>-6-49 I.4d -n .I=.4KI4n2 d4>0a9a2-5n. 56 PLRSQL 2a=04. and V>50I7nP21/4V -. an1 .>a0a9 da2a21/4 .I>3 a. CHAR, DATE, 59 NUMBER Y5I >an I.4 234 OTYPE a229-=I24 25 ./4>-61 a >50I7n da2a21/4 In 23-. 4Ea7/04, 15I d4>0a94 a TABLE 21/4 >a004d VEna74Ta=T1/V: DECLARE TYPE Ena74Ta=T1/ IS TABLE OF CHAR"1$) INDED BY BINARYPINTE*ER% Y5I >5I0d 3aJ4 I.4d OTYPE 25 /95J-d4 234 >50I7n da2a21/4, a. 650058.: DECLARE TYPE Ena74Ta=T1/ IS TABLE OF 47/ 4na74OTYPE INDED BY BINARYPINTE*ER% On>4 15I d46-n4 21/4 VEna74Ta=T1/,V 15I >an d4>0a94 PLRSQL 2a=04. 56

23a2 21/4, a. 650058.: 4na74P2a= Ena74Ta=T1/%

T34 -d4n2-6-49 V4na74P2a=V 94/94.4n2. an 4n2-94 PLRSQL 2a=04 L-:4 .>a0a9 Ja9-a=04., PLRSQL 2a=04. >an =4 d4>0a94d a. 234 6597a0 /a9a74249. 56 /95>4dI94. and 6In>2-5n. S574 /a>:a;4d 4Ea7/04. 650058:

PACKA*E 47/Pa>2-5n. IS TYPE Ena74Ta=T1/ IS TABLE OF 47/ 4na74OTYPE INDED BY BINARYPINTE*ER% TYPE Sa0Ta=T1/ IS TABLE OF 47/ .a0OTYPE INDED BY BINARYPINTE*ER% 4na74P2a= Ena74Ta=T1/% .a0P2a= Sa0Ta=T1/% PROCEDURE 3-94P=a2>3 "4na74P2a= Ena74Ta=T1/, .a0P2a= Sa0Ta=T1/, )% PROCEDURE 05;Pna74. "4na74P2a= Ena74Ta=T1/, nI7 BINARYPINTE*ER)% END 47/Pa>2-5n.% R46494n>-n; PLRSQL Ta=04. T5 946494n>4 958. -n a PLRSQL 2a=04, 15I ./4>-61 a /9-7a91 :41 Ja0I4 I.-n; 234 a99a1N0-:4 .1n2aE /0.K0P2a=04Pna74"/9-7a91P:41PJa0I4) 83494 V/9-7a91P:41PJa0I4V =405n;. 25 21/4 BINARYPINTE*ER F59 4Ea7/04,

15I 946494n>4 234 23-9d 958 -n PLRSQL 2a=04 V4na74P2a=V a. 650058.: 4na74P2a="#) Y5I >an a..-;n 234 Ja0I4 56 a PLRSQL 4E/94..-5n 25 a ./4>-6-> 958 I.-n; 234 650058-n; .1n2aE: /0.K0P2a=04Pna74"/9-7a91P:41PJa0I4) :A /0.K0P4E/94..-5n% In 234 n4E2 4Ea7/04, 15I a..-;n 234 .I7 56 Ja9-a=04. V.a0a91V and V-n>94a.4V 25 234 6-623 958 -n PLRSQL 2a=04 V.a0P2a=V: .a0P2a=")) :A .a0a91 H -n>94a.4% Un2-0 a 958 -. a..-;n4d a Ja0I4, -2 d54. n52 4E-.2 I6 15I 291 25 946494n>4 an In-n-2-a0-S4d 958, PLRSQL 9a-.4. 234 /94d46-n4d 4E>4/2-5n NOPDATAPFOUND C5n.-d49 234 650058-n; 4Ea7/04:

DECLARE TYPE &5=Ta=T1/ IS TABLE OF CHAR"1') INDED BY BINARYPINTE*ER% <5=P2a= &5=Ta=T1/% BE*IN <5=P2a="1) :A (CLERK(% IF <5=P2a="2) A (CLERK( THEN NN 9a-.4. NOPDATAPFOUND END IF% EDCEPTION ?HEN NOPDATAPFOUND THEN NN 3494 =4>aI.4 <5=P2a="2) d54. n52 4E-.2 END% In.492-n;RF42>3-n; R58. Y5I 7I.2 I.4 a 055/ 25 INSERT Ja0I4. 6957 a PLRSQL 2a=04 -n25 a da2a=a.4 >50I7n L-:48-.4, 15I 7I.2 I.4 a 055/ 25 FETCH Ja0I4. 6957 a da2a=a.4 >50I7n -n25 a PLRSQL 2a=04 F59 4Ea7/04, ;-J4n 234 d4>0a9a2-5n. DECLARE TYPE E7/n5Ta=T1/ IS TABLE OF NUMBER"') INDED BY BINARYPINTE*ER% TYPE Ena74Ta=T1/ IS TABLE OF CHAR"1$) INDED BY BINARYPINTE*ER% 47/n5P2a= 4na74P2a= E7/n5Ta=T1/% Ena74Ta=T1/%

15I 7-;32 I.4 234 650058-n; /95>4dI94 25 INSERT Ja0I4. 6957 234 PLRSQL 2a=04. -n25 234 V47/V da2a=a.4 2a=04: PROCEDURE -n.492P47/Pda2a "958. BINARYPINTE*ER, 47/n5P2a= E7/n5Ta=T1/, 4na74P2a= Ena74Ta=T1/, ) IS BE*IN FOR - IN 1 958. LOOP INSERT INTO 47/ "47/n5, 4na74, ) VALUES "47/n5P2a="-), 4na74P2a="-), END LOOP% END%

)%

C5nJ49.401, 15I 7-;32 I.4 234 n4E2 /95>4dI94 25 FETCH a00 958. 6957 234 da2a=a.4 2a=04 -n25 PLRSQL 2a=04. V47/n5P2a=V and V4na74P2a=V:

PROCEDURE 642>3P47/Pda2a "958. OUT BINARYPINTE*ER, 47/n5P2a= OUT E7/n5Ta=T1/, 4na74P2a= OUT Ena74Ta=T1/, ) IS BE*IN 958. :A $% FOR 47/94> IN "SELECT @ FROM 47/) LOOP 958. :A 958. H 1% 47/n5P2a="958.) :A 47/94> 47/n5% 4na74P2a="958.) :A 47/94> 4na74% END LOOP% END% H584J49, 15I >ann52 946494n>4 PLRSQL 2a=04. -n 234 INTO >0aI.4 4Ea7/04, 234 650058-n; SELECT .2a2474n2 -. -004;a0: PROCEDURE 642>3P47/Pda2a "958. OUT BINARYPINTE*ER, 47/n5P2a= OUT E7/n5Ta=T1/, 4na74P2a= OUT Ena74Ta=T1/, ) IS BE*IN SELECT 47/n5, 4na74 INTO 47/n5P2a=, 4na74P2a= FROM 47/% END% D4042-n; R58. Y5I >ann52 d40424 -nd-J-dIa0 958. 6957 a PLRSQL 2a=04 =4>aI.4 234 DELETE .2a2474n2 >ann52 ./4>-61 PLRSQL 2a=04. H584J49, 15I >an I.4 a .-7/04 859:a95Ind 25 d40424 4n2-94 PLRSQL 2a=04. ?34n 15I 8an2 25 d40424 a PLRSQL 2a=04, .-7/01 a..-;n a nI00 25 -2, a. .358n -n 234 650058-n; 4Ea7/04: DECLARE TYPE NI7Ta=T1/ IS TABLE OF NUMBER INDED BY BINARYPINTE*ER% .a0P2a= NI7Ta=T1/% BE*IN R@ L5ad .a0a91 2a=04 FOR - IN 1 )$ LOOP .a0P2a="-) :A -% END LOOP% @R F59

NN -004;a0

R@ D40424 .a0a91 2a=04 @R .a0P2a= :A NULL% NN 9404a.4. a00 PLRSQL 2a=04 94.5I9>4.

END% S44 a0.5: Da2a21/4., Va9-a=04. and C5n.2an2., R4>59d., FETCH S2a2474n2, INSERT, DELETE

1 /0R.K0 =05>: 25 /9-n2 d42a-0. 56 47/05144. 834n nI7=49A,,GG% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ d4>0a94 nI7 nI7=49"))% na74 Ja9>3a9"1$)% .a0 nI7=49",,2)% =4;-n .404>2 47/n5,4na74,.a0 -n25 nI7,na74,.a0 6957 47/ 83494 47/n5A,!$2% d=7.P5I2/I2 /I2PL-n4"nI7QQ( (QQna74QQ( (QQ.a0)% 4nd% 2 /0R.K0 =05>: 25 /9-n2 d42a-0. 56 47/05144. 834n nI7=49An ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ d4>0a94 nI7 nI7=49"))% na74 Ja9>3a9"1$)% .a0 nI7=49",,2)% =4;-n .404>2 47/n5,4na74,.a0 -n25 nI7,na74,.a0 6957 47/ 83494 47/n5AMn% -n.492 -n25 a94a. Ja0I4."1$$,'$$$)% d=7.P5I2/I2 /I2PL-n4"nI7QQ( (QQna74QQ( (QQ.a0)% 4nd% DECLARE NAME VARCHAR2"1$):A(MNAME(% DESI* VARCHAR2"12)% SALARY NUMBER",,2)% NETSAL NUMBER",,2)% BE*IN SELECT &OB,SAL INTO DESI*,SALARY FROM EMP ?HERE ENAMEANAME% DBMSPOUTPUT PUTPLINE"NAMEQQ( (QQDESI*QQ( (QQSALARY)% IF DESI*A(CLERK( THEN UPDATE EMP SET SALASALARY@$ 1 HSALARY ?HERE ENAMEANAME% NETSAL:ASALARY@$ 1HSALARY% DBMSPOUTPUT PUTPLINE"(THE NET SALARY IS (QQNETSAL)% ELSE UPDATE EMP SET SALASALARY@$ 2 HSALARY ?HERE ENAMEANAME% NETSAL:ASALARY@$ 1HSALARY% DBMSPOUTPUT PUTPLINE"(THE NET SALARY IS (QQNETSAL)% END IF% END% # I/da24 .2a2474n2 -n /0R.K0 =05>: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

d4>0a94 nI7 nI7=49")):AMEMPNO% na74 Ja9>3a9"1$)% .a0a91 nI7=49",,2)% d4.-; Ja9>3a92"1$)% =4;-n .404>2 47/n5,4na74,.a0,<5= -n25 nI7,na74,.a0a91,d4.-; 6957 47/ 83494 47/n5ANUM% d=7.P5I2/I2 /I2PL-n4"nI7QQ( (QQna74QQ( (QQ.a0ARYQQ( (QQDESI*)% -6 d4.-;A(CLERK( THEN UPDATE EMP SET SALASALH2$$ ?HERE EMPNOANUM% ELSIF DESI*A(MANA*ER( THEN UPDATE EMP SET SALASALH#$$ ?HERE EMPNOANUM% END IF% COMMIT% 4nd% ' DELETE STATEMENT IN PLRSQL BLOCK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ d4>0a94 nI7 nI7=49"))% na74 Ja9>3a9"1$)% .a0a91 nI7=49",,2)% d4.-; Ja9>3a92"1$)% =4;-n .404>2 47/n5,4na74,.a0,<5= -n25 nI7,na74,.a0a91,d4.-; 6957 47/ 83494 47/n5AMn% -6 d4.-;A(CLERK( THEN DBMSPOUTPUT PUTPLINE"(RECORD DELETED()% DELETE FROM EMP ?HERE EMPNOANUM% ELSE DBMSPOUTPUT PUTPLINE"(RECORD NOT DELETED()% END IF% d=7.P5I2/I2 /I2PL-n4"nI7QQ( (QQna74QQ( (QQ.a0ARYQQ( (QQDESI*)% 4nd%

) INSERT STATEMENT IN PLRSQL BLOCK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DECLARE ENO NUMBER"')% M*R NUMBER"')% DEPNO NUMBER"#)% BE*IN INSERT INTO EMP"EMPNO,M*R,DEPTNO)VALUES"MENO,MM*R,MDEPNO)% DBMSPOUTPUT PUTPLINE"ENOQQ( (QQM*RQQ( (QQDEPNO)% COMMIT% END%

+ SELECTIN* THE VALUES FROM EMP M INSERTIN* TO TEMP TABLE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

d4>0a94 nI7 nI7=49"))% na74 Ja9>3a9"1$)% .a0a91 nI7=49",,2)% d4.-; Ja9>3a92"1$)% =4;-n .404>2 47/n5,4na74,.a0,<5= -n25 nI7,na74,.a0a91,d4.-; 6957 47/ 83494 47/n5AMn% -6 d4.-;A(CLERK( THEN DBMSPOUTPUT PUTPLINE"(RECORD INSERTED()% INSERT INTO TEMP VALUES"NUM,NAME,SALARY,DESI*)% END IF% d=7.P5I2/I2 /I2PL-n4"nI7QQ( (QQna74QQ( (QQ.a0ARYQQ( (QQDESI*)% COMMIT% 4nd% , DISPLAY NAME AND DESI*NATION OF MANA*ERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "THE BLOCK *IVES ERRORS IT IS &UST TO ILLUSTRATE THAT 4Ea>2 642>3 942I9n. 7594 23an 94KI4.24d nI7=49 56 958. ) DECLARE N NUMBER% NAME EMP ENAMEOTYPE% DESI* EMP &OBOTYPE% BE*IN SELECT COUNT"@) INTO N FROM EMP ?HERE &OBA(MANA*ER(% FOR I IN 1 N LOOP SELECT ENAME,&OB INTO NAME,DESI* FROM EMP ?HERE &OBA(MANA*ER(% DBMSPOUTPUT PUTPLINE"NAMEQQ( (QQDESI*)% END LOOP% END%

EDAMPLE FOR SELECT,INSERT,UPDATE,DELETE STATEMENTS IN PLRSQL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CREATE TABLE TEMP " ENAME VARCHAR2"1$), DESI* VARCHAR2"1$), SAL NUMBER",,2))% DECLARE NAME VARCHAR2"1$)% DESI* VARCHAR2"1$)% SALARY NUMBER",,2)% ENO NUMBER"'):AMEMPNO% BE*IN SELECT ENAME,&OB,SAL INTO NAME,DESI*,SALARY FROM EMP ?HERE EMPNOAENO% DBMSPOUTPUT PUTPLINE"ENOQQ( (QQNAMEQQ( (QQSALARYQQ( (QQDESI*)% IF DESI*A(CLERK( THEN

DELETE FROM EMP ?HERE EMPNOAENO% INSERT INTO TEMP VALUES"NAME,DESI*,SALARY)% DBMSPOUTPUT PUTPLINE"(DELETED FROM EMP AND INSERTED TO TEMP()% COMMIT% ELSIF DESI*A(MANA*ER( THEN UPDATE EMP SET SALASALARYH2$$ ?HERE EMPNOAENO% DBMSPOUTPUT PUTPLINE"(INCREMENTED SALARY IS (QQTOPCHAR"SALARYH2$$))% END IF% END% G SELECT MAD"DEPTNO) FROM DEPT TABLE AND INSERT TO TEMP TABLE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DECLARE MDEPNO NUMBER"#)% BE*IN FOR I IN 1 ' LOOP SELECT MAD"DEPTNO) INTO MDEPNO FROM DEPT)% INSERT INTO TEMP VALUES"MDEPNO)% DBMSPOUTPUT PUTPLINE"MDEPNO)% DELETE FROM DEPT) ?HERE DEPTNOAMDEPNO% COMMIT% END LOOP% END% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ ! 2 2a=04. a94 >94a24d In 5n4 2a=04 234 KIan2-1 and 234 /95dI>2 na74 -. .2594d and 234 52349 2a=04 -. dI771 2a=04 I6 84 ;-J4 /95dI>2 na74 234 d42a-0. 8-00 =4 d-./0a14d I6 234 nI7=49 56 /95dI>2. -. =4058 ) 234n -n.492 -n25 247/ 2a=04 5I2 56 .25>: and .1.da24 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ -nJ4n2591 2a=04 "-nJ) ~~~~~~~~~~~~~~~ KIan2-21 /95dna74 ! Ra>:42 G B55: ) P4n>-0 1 Ma9:49 >94a24 2a=04 -nJ"KIan2-21 nI7=49"#),/95dna74 Ja9>3a9"1$))% 247/ ~~~~ /95dna74

>5774n2

da241

>94a24 2a=04 247/" /95dna74 Ja9>3a92"1$), >577 Ja9>3a92"1+), da241 da24)% d4>0a94 K21 NUMBER"))% /na74 VARCHAR2"1$)% =4;-n .404>2 KIan2-21,/95dna74 -n25 K21,/na74 6957 -nJ 83494

/95dna74A(M/95dI>2na74(% -6 K21F) 234n DBMSPOUTPUT PUTPLINE"(THANK U FOR THE PURCHASES MADE VISIT A*AIN()% I/da24 -nJ .42 KIan2-21AKIan2-21N1 83494 /95dna74A/na74% >577-2% 40.4 DBMSPOUTPUT PUTPLINE"(STOCK LEVEL IS BELO? ORDER LEVEL()% -n.492 -n25 247/ Ja0I4."/na74,(5I2 56 .25>:(,.1.da24)% >577-2% 4nd -6% 4nd% 1$ 4Ea7/04 659 >5n.2an2 ~~~~~~~~~~~~~~~~~~~~~~~~ d4>0a94 a >5n.2an2 nI7=49:A)% =4;-n d=7.P5I2/I2 /I2PL-n4"a)% 4nd% "I6 84 7a:4 a a. an >5n.2an2 84 >ann52 I.4 a a. a a..-;n74n2 2a9;42 ?4 >an <I.2 /9-n2 aH2,aH# 42> ) d4>0a94 a >5n.2an2 nI7=49:A)% =4;-n d=7.P5I2/I2 /I2PL-n4"a)% d=7.P5I2/I2 /I2PL-n4"aH2)% 4nd% 11 4Ea7/04 659 d46aI02 @@@@@@@@@@@@@@@@@@@@@@@ d4>0a94 a nI7=49 d46aI02 #% =4;-n d=7.P5I2/I2 /I2PL-n4"a)% 4nd% "3ERE A CAN BE USED AS ASSI*NMENT TAR*ET) 12 ?9-24 a /0R.K0 =05>: 25 642>3 234 d42a-0. 56 a00 234 47/05144. 835.4 nI7=49 -. ,!$2 N58 -6 3-. .a0 -. 04.. 23an '$$$ 234n 642>3 .a0a91 7;9 and na74 56 234 47/05144. 835.4 47/n5 .35I0d =4 4KIa0 25 M*R 1# ?AP TO CHECK THE BANK DETAILS IN BANK TABLE ACCNO AND BALANCE IS STORED USER HAS TO ENTER THE ACCOUNT NUMBER AND ?ITHDRA? AMOUNT IF ?ITHDRA?L AMOUNT L BALANCE THEN UPDATE BALANCE OF BANK TABLE AND SUBTRACT THE ?ITHDRA?L AMOUNT FROM BALANCE ELSE INSERT A MESSA*E LIKE INSUFFICIENT FUNDS TO TEMP TABLE >94a24 2a=04 =an:

" a>>n5 nI7=49"#), =a0 nI7=49"+))% ACCNO BAL NNNNNNNN NNNNNNNNN 1$ )$$$ 2$ +$$$ #$ 2$ >94a24 2a=04 247/ " a>>n5 nI7=49"#), =a0 nI7=49"+), 947 Ja9>3a92"2$))% d4>0a94 a8-23 nI7=49"#):AMa8-23% a>Pn5 nI7=49"#):AMa>>n5% a=a0 nI7=49"+)% =4;-n .404>2 =a0 -n25 a=a0 6957 =an: 83494 a>>n5Aa>Pn5% -6 a=a0Fa8-23 234n I/da24 =an: .42 =a0A=a0Na8-23 83494 a>>n5Aa>Pn5% >577-2% 40.4 -n.492 -n25 247/ Ja0I4."a>Pn5,a=a0,(-n.I66Ind.()% >577-2% 4nd -6% 4nd% 1' ILLUSTRATE OTYPE @@@@@@@@@@@@@@@@@@@@@ d4>0a94 a 47/ d4/2n5O21/4% =4;-n .404>2 d4/2n5 -n25 a 6957 47/ 83494 47/n5AMA% d=7.P5I2/I2 /I2P0-n4"a)% 4nd% 1) ILLUSTRATE ORO?TYPE @@@@@@@@@@@@@@@@@@@@@@@ d4>0a94 a 47/ORO?21/4% =4;-n .404>2 @ -n25 a 6957 47/ 83494 47/n5AMN% d=7.P5I2/I2 /I2P0-n4"A ENAMEQQ( (QQA SALQQ( (QQA COMM)% 4nd% 1+ 89-24 a /0R.K0 =05>: 25 >a0>I0a24 234 .I7 and aJ49a;4 .a0a9-4. 56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a00 234 47/05144. 56 a /a92->I0a9 d4/a9274n2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DECLARE

NO NUMBER:AMDEPTNO% SUM1 NUMBER",,2)% AV*1 NUMBER",,2)% SELECT SUM"SAL),AV*"SAL) INTO SUM1,AV*1 FROM EMP ?HERE DEPTNOANO% DBMSPOUTPUT PUTP0-n4"(SI7 56 .a0a91 -.(QQSUM1)% DBMSPOUTPUT PUTPL-n4"(AJ49a;4 .a0a91 -.(QQAV*1)% END%

BE*IN

NESTED TABLE CREATE OR REPLACE TYPE EMPLOYEE AS OB&ECT P CREATE TYPE EMPLOYEE AS OB&ECT "NO NUMBER"'), NAME VARCHAR2"2$), &OB VARCHAR2"1$), SAL NUMBER",,2))% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

CREATE TYPE EMPTAB AS TABLE OF EMPLOYEE% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN CREATE "DNO DNAME EMPL TABLE DEPTNEST NUMBER"2), VARCHAR2"2$), EMPTAB) NESTED TABLE EMPL STORE AS EMPNEST%

NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN INSERT INTO DEPTNEST VALUES "1$,(ACCOUNTS(,EMPTAB" EMPLOYEE"1,(RA&(,(CLERK(,1$$$), EMPLOYEE"2,(SARAV(,(SALES(,2$$$)))% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN INSERT INTO THE"SELECT EMPL FROM DEPTNEST ?HERE DEPTNOA1$) VALUES "EMPTAB"#,(SHIV(,(SUPERV(,2#$$))%

SELECT D EMPL NAME FROM DEPTNEST D ?HERE D DNOA1$% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN SELECT TYPEPCODE,ATTRIBUTES FROM USERPTYPES ?HERE TYPEPNAMEA(DEPTNEST(% SELECT COLLPTYPES,ELEMPTYPE FROM USERPCOLPTYPES ?HERE TYPEPNAMEA( (% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NNNNNNNNNNNNNNNNNNNNNNNNNN VARRAY: NNNNNNNNNNNNN CREATE TYPE PHONE AS OB&ECT "NO NUMBER"+))% NNNNNNNNNN CREATE TYPE PHONETYPE AS VARRAY")) OF PHONE% NNNNNNNNNN CREATE TABLE CUST "NAME VARCHAR2"2$), PHONENO PHONETYPE)% NNNNNNNNNNN INSERT INTO CUST VALUES "(DDDD(, PHONETYPE"PHONE"2#2#22),PHONE"#')#')))% NNNNNNNNNNN SELECT COLI7nPNAME,DATAPTYPEPNAME FROM USERPTABPCOLUMNS ?HERE TABLEPNAMEA( (% SELECT TYPEPCODE,ATTRIBUTES FROM USERPTYPES ?HERE TYPEPNAMEA( (%

NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NNNNNNNNNNNNNNNNNNNNNNN

NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN Y@@@@@@@@@@@@@@Y PROCEDURES Y@@@@@@@@@@@@@@Y Y@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@YY@@@@@@ @@@@@@@@Y 1 2 # ' ) ?RITE A PROCEDURE TO DRA? A LINE ?RITE A PROCEDURE ?HICH ACTS &UST LIKE DBMSPOUTPUT PUTPLINE ?RITE A PROCEDURE TO FETCH THE NAME AND &OB ?HEN NO IS PASSED "23-. -. 25 -00I.29a24 =523 -n and 5I2 /a9a74249.) ?RITE A PROCEDURE TO PASS THE EMPLOYEE NUMBER AND THE AMOUNT TO BE INCREMENTED 4Ea7/04 25 -00I.29a24 -n 5I2 /a9a74249 EDAMPLE TO ILLUSTRATE LOCAL PROCEDURE I E DYNAMIC CREATION OF PROCEDURES "PROCEDURE ?ITHIN A BLOCK)

Y@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@YY@@@@@@@@@@@@@@YY@@@@@@ @@@@@@@@Y 1 NNNNNNNNNN ?RITE A PROCEDURE TO DRA? A LINE

CREATE OR REPLACE PROCEDURE LINE IS BE*IN FOR I IN 1 '$ LOOP DBMSPOUTPUT PUT"(P()% END LOOP% DBMSPOUTPUT NE?PLINE% END% EDEC LINE OR DECLARE CURSOR C1 IS SELECT @ FROM EMP ?HERE &OBA(CLERK(%

CURSOR C2 IS SELECT @ FROM EMP ?HERE &OBA(MANA*ER(% BE*IN LINE% LINE% FOR I IN C1 LOOP DBMSPOUTPUT PUTPLINE"I ENAMEQQ( (QQI &OB)% END LOOP% LINE% LINE% FOR I IN C2 LOOP DBMSPOUTPUT PUTPLINE"I ENAMEQQ( (QQI &OB)% END LOOP% LINE% LINE% END% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPP 2NNNNNNNNNNNNNNN?RITE A PROCEDURE ?HICH ACTS &UST LIKE DBMSPOUTPUT PUTPLINE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CREATE OR REPLACE PROCEDURE PRINT" N VARCHAR2) -. =4;-n d=7.P5I2/I2 /I2P0-n4"n)% 4nd% d4>0a94 A NUMBER:A2)% =4;-n PRINT"A)% /9-n2"(BRAIN?ARE()% 4nd% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP #NNNNNNNNNNNN?RITE A PROCEDURE TO FETCH THE NAME AND &OB ?HEN NO IS PASSED NNNNNNN"23-. -. 25 -00I.29a24 =523 -n and 5I2 /a9a74249.) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CREATE OR REPLACE PROCEDURE DISP"N NUMBER) IS NAME EMP ENAMEOTYPE% DESI* EMP &OBOTYPE% BE*IN SELECT ENAME,&OB INTO NAME,DESI* FROM EMP ?HERE EMPNOAN% DBMSPOUTPUT PUTPLINE"NAMEQQ( (QQDESI*)% END% EDEC DISP",'!!) DECLARE BE*IN DISP"MN)%

END%

OR

CREATE OR REPLACE PROCEDURE DISP1"ENO NUMBER, NAME OUT VARCHAR,DESI* OUT VARCHAR) IS BE*IN SELECT ENAME,&OB INTO NAME,DESI* FROM EMP ?HERE EMPNOAENO% END% DECLARE NAME1 VARCHAR2"#$)% DESI*1 VARCHAR2"1$)% N NUMBER:AMEMPNO% BE*IN DISP1"N,NAME1,DESI*1)% DBMSPOUTPUT PUTPLINE"NAME1QQ( (QQDESI*1QQ( (QQN)% END% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPP

'NNNNNNNNNNNNNNN?RITE A PROCEDURE TO PASS THE EMPLOYEE NUMBER AND THE AMOUNT TO BE INCREMENTED 4Ea7/04 25 -00I.29a24 -n 5I2 /a9a74249 >94a24 59 94/0a>4 /95>4dI94 3-:4P.a0"a -n 5I2 nI7=49,-n>94 nI7=49) -. =4;-n I/da24 47/ .42 .a0A.a0H-n>94 83494 47/n5Aa% -6 .K0O65Ind 234n a:A1% 40.4 a:A$% 4nd -6% 4nd% d4>0a94 n nI7=49:AM47/n5% -n>94 nI7=49:AM-n>9474n2% =4;-n d=7.P5I2/I2 /I2P0-n4"(n A (QQ nQQ( (QQ( -n>9474n2A(QQ-n>94)% 3-:4P.a0"n,-n>94)% d=7.P5I2/I2 /I2P0-n4"(n A (QQ nQQ( (QQ( -n>9474n2A(QQ-n>94)% -6 nA1 234n d=7.P5I2/I2 /I2P0-n4"(.a0a91 -n>9474n24d()% 40.4 d=7.P5I2/I2 /I2P0-n4"(.a0a91 -. n52 -n>9474n24d()% 4nd -6% 4nd% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP

)NNNNNNNNNNNEDAMPLE TO ILLUSTRATE LOCAL PROCEDURE NNNNNNNNNNNNI E DYNAMIC CREATION OF PROCEDURES "PROCEDURE ?ITHIN A BLOCK) DECLARE A NUMBER:A1$% & VARCHAR2"1$)% ENO NUMBER% PROCEDURE DISP&OB"N NUMBER,& OUT VARCHAR2) IS BE*IN SELECT &OB INTO & FROM EMP ?HERE EMPNOAN% END%

BE*IN

ENO:AMEMPNO% DBMSPOUTPUT PUTPLINE"(EMPLOYEE NUMBER IS(QQENO)% DISP&OB"ENO,&)% DBMSPOUTPUT PUTP0INE"(EMPNOA(QQENOQQ( &OBA(QQ&)% EDCEPTION ?HEN NOPDATAPFOUND THEN DBMSPOUTPUT PUTPLINE"(MESSA*E()% PRINT"(SORRRY NO EMPLOYEE EDISTS ?ITH THAT NUMBER()% END% PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP CURSORS NNNNNNN DECLARE CURSOR C1 IS SELECT ENAME,COMM FROM EMP ?HERE EMPNOA,!$$% NAME EMP ENAMEOTYPE% COMMISSION EMP COMMOTYPE% BE*IN OPEN C1% FETCH C1 INTO NAME,COMMISSION% DBMSPOUTPUT PUTPLINE"(THE VALUES ARE(QQ( (QQNAMEQQ( (QQCOMMISSION)% CLOSE C1% END% DECLARE CURSOR C1 IS SELECT EMPNO,ENAME ,DEPTNO FROM EMP% EMPNUM EMP EMPNOOTYPE% EMPNAME EMP ENAMEOTYPE% DEPTNUM EMP DEPTNOOTYPE% BE*IN OPEN C1% LOOP FETCH C1 INTO EMPNUM,EMPNAME,DEPTNUM% -6 >1On5265Ind 234n 4E-2% 40.4 d=7.P5I2/I2 /I2P0-n4"EMPNUMQQ( (QQEMPNAMEQQ( (QQDEPTNUM)% 4nd -6%

END LOOP% 4nd% DECLARE CURSOR C1 IS SELECT EMPNO,ENAME ,SAL FROM EMP ?HERE DEPTNOA1$% EMPNUM EMP EMPNOOTYPE% NAME EMP ENAMEOTYPE% SALARY EMP SALOTYPE% BE*IN OPEN C1% LOOP FETCH C1 INTO EMPNUM,NAME,SALARY% IF C1ONOTFOUND THEN EDIT% END IF% INSERT INTO TEMP VALUES"EMPNUM,NAME,SALARY)% END LOOP% NNCLOSE C1% END% RRCURSOR ALREADY OPEN DECLARE CURSOR C1 IS SELECT EMPNO,ENAME,DEPTNO FROM EMP% EMPNUM EMP EMPNOOTYPE% EMPNAME EMP ENAMEOTYPE% DEPTNUM EMP DEPTNOOTYPE% BE*IN OPEN C1% OPEN C1% FOR I IN 1 ) LOOP FETCH C1 INTO EMPNUM,EMPNAME,DEPTNUM% IF C1O NOTFOUND THEN EDIT% END IF% NNINSERT INTO TEMP VALUES"EMPNUM,EMPNAME,DEPTNUM)% END LOOP% CLOSE C1% END%

DECLARE CURSOR C1 IS SELECT EMPNO,SAL,COMM FROM EMP% EMPCODE EMP EMPNOOTYPE% SALARY EMP SALOTYPE% COM EMP COMMOTYPE% BE*IN OPEN C1% LOOP FETCH C1 INTO EMPCODE,SALARY,COM% EDIT ?HEN C1ONOTFOUND% INSERT INTO TEMP VALUES"EMPCODE,SALARY,COM)% END LOOP% CLOSE C1% END% RRRRRRRR"ISOPEN ?ITH CLOSE)

DECLARE CURSOR C1 IS SELECT EMPNO,SAL,COMM FROM EMP% EMPCODE EMP EMPNOOTYPE% SALARY EMP SALOTYPE% COM EMP COMMOTYPE% BE*IN LOOP IF C1OISOPEN THEN DBMSPOUTPUT PUTPLINE"(CURSOR IS OPEN()% EDIT% ELSE OPEN C1% FETCH C1 INTO EMPCODE,SALARY,COM% EDIT ?HEN C1ONOTFOUND% INSERT INTO TEMP VALUES"EMPCODE,SALARY,COM)% END IF% END LOOP% CLOSE C1% END% DECLARE CURSOR C1 IS SELECT EMPNO,ENAME,COMM FROM EMP% BE*IN NNOPEN C1% FOR I IN C1 LOOP DBMSPOUTPUT PUTPLINE"I EMPNOQQ( (QQI ENAMEQQ( (QQI COMM)% INSERT INTO TEMP VALUES"I EMPNO,I ENAME,I COMM)% END LOOP% NNCLOSE C1% END% ORO?TYPE NNNNNNNN DECLARE CURSOR C1 IS SELECT @ FROM EMP% TEMPRO? EMPORO?TYPE% BE*IN OPEN C1% LOOP FETCH C1 INTO TEMPRO?% EDIT ?HEN C1ONOTFOUND% DBMSPOUTPUT PUTPLINE"TEMPRO? EMPNOQQ( (QQTEMPRO? SAL)% END LOOP% CLOSE C1% DECLARE CURSOR C1 IS SELECT EMPNO,ENAME,SAL FROM EMP% TEMPRO? C1ORO?TYPE% BE*IN OPEN C1% LOOP FETCH C1 INTO TEMPRO?% EDIT ?HEN C1ONOTFOUND% DBMSPOUTPUT PUTPLINE"TEMPRO? EMPNOQQ( (QQTEMPRO? SAL)%

END LOOP% CLOSE C1% END% END% IMPLICIT CURSOR NNNNNNNNNNNNNNNN BE*IN UPDATE EMP SET HIREDATEA($1NSEPN!G( ?HERE DEPTNOA2$% DBMSPOUTPUT PUTPLINE"SQLORO?COUNTQQ(RO? UPDATED()% END%

RO?COUNT NNNNNNNN DECLARE CURSOR C1 IS SELECT @ FROM EMP% A C1ORO?TYPE% BE*IN IF NOT C1OISOPEN THEN OPEN C1% END IF% LOOP FETCH C1 INTO A% IF C1OFOUND THEN IF C1ORO?COUNTL) THEN DBMSPOUTPUT PUTPLINE"A EMPNOQQ( (QQA ENAMEQQ( (QQA DEPTNO)% ELSE EDIT% END IF% ELSE EDIT% END IF% END LOOP% CLOSE C1% END% EDCEPTION% NNNNNNNNNN "TEROPDIVIDE) NNNNNNNNNNNN DECLARE A NUMBER:AMA% B NUMBER:AMB% C NUMBER% BE*IN C:AARB% DBMSPOUTPUT PUTPLINE"C)% EDCEPTION ?HEN TEROPDIVIDE THEN DBMSPOUTPUT PUTPLINE"(THE DENOMINATOR IS TERO()% B:AA% C:AARB% DBMSPOUTPUT PUTPLINE"C)% END%

VALUE 49959% NNNNNNNNNNNNNNN DECLARE EMPNUM NUMBER"#)% NAME VARCHAR2"1$)% NO NUMBER:AMNO% BE*IN SELECT EMPNO,ENAME INTO EMPNUM,NAME FROM EMP ?HERE EMPNOANO% DBMSPOUTPUT PUTPLINE"EMPNUMQQ( (QQNAME)% EDCEPTION ?HEN VALUEPERROR THEN DBMSPOUTPUT PUTPLINE"(?IDTH IS NOT SUFFICIENT()% DECLARE ENUM EMP EMPNOOTYPE% BE*IN SELECT EMPNO,ENAME INTO ENUM,NAME FROM EMP ?HERE EMPNOANO % DBMSPOUTPUT PUTPLINE"ENUMQQ( (QQNAME)% END% END% INVALID NUMBER% NNNNNNNNNNNNNNN DECLARE NAME VARCHAR2"1$):A(MNAME(% NUM NUMBER"#)% BE*IN SELECT TOPNUMBER"NAME) INTO NUM FROM DUAL% DBMSPOUTPUT PUTPLINE"NUM)% EDCEPTION ?HEN INVALIDPNUMBER THEN DBMSPOUTPUT PUTPLINE"(INVALID NUMBER IS RAISED()% END% TOO MANY RO?S: NNNNNNNNNNNNNN DECLARE NAME 47/ ENAMEO21/4% E&OB EMP &OBOTYPE:A(M&OB(% BE*IN .404>2 ENAME -n25 NAME 6957 47/ ?HERE &OBAE&OB% d=7.P5I2/I2 /I2P0-n4"NAME)% 4E>4/2-5n 834n 255P7an1P958. 234n d=7.P5I2/I2 /I2P0-n4"(255 7an1 958. a94 65Ind()% DECLARE CURSOR C1 IS SELECT ENAME,&OB,SAL FROM EMP ?HERE &OBAE&OB% BE*IN IF C1OISOPEN THEN DBMSPOUTPUT PUTPLINE"(CURSOR IS OPEN()% END IF% FOR I IN C1 LOOP

END%

DBMSPOUTPUT PUTPLINE"I ENAMEQQ( (QQI &OBQQ( (QQI SAL)% END LOOP% END%

NOPDATAPFOUND NNNNNNNNNNNNN DECLARE NO EMP EMPNOOTYPE% NAME EMP ENAMEOTYPE% SALARY EMP SALOTYPE% DESI* EMP &OBOTYPE% BE*IN SELECT EMPNO,ENAME,SAL,&OB INTO NO,NAME,SALARY,DESI* FROM EMP ?HERE EMPNOAMEMPNO% IF SQLOFOUND THEN DBMSPOUTPUT PUTPLINE"NOQQ( (QQNAMEQQ( (QQSALARYQQ( (QQDESI*)% END IF% EDCEPTION ?HEN NOPDATAPFOUND THEN DBMSPOUTPUT PUTPLINE"(NO DATA FOUND()% DECLARE NE?NO EMP EMPNOOTYPE% NAME EMP ENAMEOTYPE% DESI* EMP &OBOTYPE% BE*IN SELECT ENAME,&OB INTO NAME,DESI* FROM EMP ?HERE EMPNOAMNE?NO% DBMSPOUTPUT PUTPLINE"NAMEQQ( (QQdESI*)% END% END%

INVALID CURSOR"OPENIN* IN LOOP) NNNNNNNNNNNNNN DECLARE CURSOR C1 IS SELECT @ FROM EMP% A EMPORO?TYPE% BE*IN LOOP FETCH C1 INTO A% OPEN C1% EDIT ?HEN C1ONOTFOUND% DBMSPOUTPUT PUTPLINE"A ENAMEQQ( (QQA &OBQQ( (QQA SAL)% END LOOP% CLOSE C1% EDCEPTION ?HEN INVALIDPCURSOR THEN DBMSPOUTPUT PUTPLINE"(INVALID CURSOR()% END%

CURSORPALREADYPOPEN NNNNNNNNNNNNNNNNNNNN DECLARE

CURSOR C1 IS SELECT @ FROM EMP % A C1ORO?TYPE% BE*IN 5/4n >1% LOOP OPEN C1% FETCH C1 INTO A% EDIT ?HEN C1ONO2FOUND% DBMSPOUTPUT PUTPLINE"a .a0QQ( (QQa 4na74)% END LOOP% CLOSE C1% 4E>4/2-5n 834n >I9.59Pa094ad1P5/4n 234n d=7.P5I2/I2 /I2P0-n4"(>I9.59 a094ad1 5/4nED()% END% ?HEN OTHERS NNNNNNNNNNNN DESC TEMP A VARCHAR2"1$) B VARCHAR2"2)) C VARCHAR2"2)) DECLARE ENO NUMBER"')% NAME VARCHAR2"1$)% DEPNO NUMBER"#)% ACODE NUMBER"')% BMS* VARCHAR2"'$)% EMPNO NUMBER"')% BE*IN SELECT EMPNO,ENAME,DEPTNO INTO ENO,NAME,DEPNO FROM EMP ?HERE 47/n5AM47/n5% DBMSPOUTPUT PUTPLINE"ENOQQ( (QQNAMEQQ( (QQDEPNO)% EDCEPTION ?HEN OTHERS THEN ACODE:ASQLCODE% BMS*:ASQLERRM% DBMSPOUTPUT PUTPLINE"(ACODE:(QQ( (QQACODEQQ( (QQBMS*)% NNINSERT INTO 247/ VALUES"ACODE,BMS* ,(a.d.()% END% DUPPVALPONPINDED NNNNNNNNNNNNNNNNN >94a24 2a=04 247/"a nI7=49"#) /9-7a91 :41, = Ja9>3a92"1$),> Ja9>3a92"1$))% d4>0a94 dn5 d4/2 d4/2n5O21/4% dna74 d4/2 dna74O21/4% 05> d4/2 05>O21/4% =4;-n -n.492 -n25 DEPT Ja0I4."Md4/2n5,(Mdna74(,(M05>()% 4E>4/2-5n 834n dI/PJa0P5nP-nd4E 234n

d=7.P5I2/I2 /I2P0-n4"(DUPPVALUESPONPINDED()% 4nd%

USERPDEFINEDPEDCEPTION NNNNNNNNNNNNNNNNNNNNNN DECLARE SALARY EMP SALOTYPE% COM EMP COMM OTYPE% MISPCOMM EDCEPTION% NETSAL NUMBER",)% BE*IN SELECT SAL,COMM INTO SALARY,COM FROM EMP ?HERE EMPNOAMN% DBMSPOUTPUT PUTPLINE"SALARYQQ( (QQCOM)% IF COM IS NULL THEN RAISE MISPCOMM% ELSE NETSAL:ASALARYHCOM% DBMSPOUTPUT PUTPLINE"SALARYQQ( (QQCOMQQ( (QQNETSAL)% END IF% EDCEPTION ?HEN MISPCOMM THEN DBMSPOUTPUT PUTP0INE"(ORA'21(QQ( (QQ(MISSPCOMM EDCEPTION()% END%

PARAMETER"ERROR) NNNNNNNNNN DECLARE I EMPORO?TYPE% CURSOR C1"TEMPENO NUMBER) IS SELECT @ FROM EMP ?HERE EMPNOATEMPENO% BE*IN OPEN C1",'!!)% FETCH C1 INTO I %

INSERT INTO EMP"EMPNO,ENAME,DEPTNO) VALUES"I EMPNO,I ENAME,I DEPTNO)% NNEDIT ?HEN C1ONOT FOUND% NNEND LOOP% END% ?EAK CURSOR"NO RETURN TYPE DECLARATION) NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN DECLARE TYPE T1 IS REF CURSOR% T2 T1% A EMPORO?TYPE% BE*IN OPEN T2 FOR SELECT @ FROM EMP% LOOP FETCH T2 INTO A% EDIT ?HEN T2ONOTFOUND% DBMSPOUTPUT PUTPLINE"A EMPNO)% END LOOP% CLOSE T2% END% DATA BASE TRI**ER: NNNNNNNNNNNNNNNNNN BEFORERAFTER INSERT OR UPDATE OR DELETE

ON

TABLENAME FOR EACH RO?

"ERROR) CREATE OR REPLACE TRI**ER T1 BEFORE INSERT ON EMP DECLARE A VARCHAR2"1$)% BE*IN SELECT TOPCHAR"SYSDATE,(DAY() INTO A FROM DUAL% IF A A(TUESDAY( THEN RAISEPAPPLICATIONPERROR"N2$!$!,(INSERTION NOT POSSIBLE()% END IF% END% ERROR NO: N2$$$$ TO N2$!!!

"FIND T1 OR T2 )"OK) CREATE OR REPLACE TRI**ER T2 BEFORE INSERT ON EMP FOR EACH RO? DECLARE A NUMBER% BE*IN SELECT COUNT"@) INTO A FROM EMP ?HERE DEPTNOA:NE? DEPTNO% IF AFA1 THEN RAISEPAPPLICATIONPERROR"N2$1$1,(PRIMARY KEY VIOLATION()% END IF% END% CREATE OR REPLACE TRI**ER DELDEPT AFTER DELETE ON DEPT FOR EACH RO? BE*IN

DELETE EMP ?HERE DEPTNOA:OLD DEPTNO% DBMSPOUTPUT PUTPLINE"(PARENT CHILD DELETED()% END% CREATE OR REPLACE TRI**ER CHECKPSAL BEFORE I/da24 ON 47/ FOR EACH RO? BE*IN IF :NE? SALL1$$$ OR :NE? SALF)$$$ THEN RAISEPAPPLICATIONPERROR"N2$$$1,(CHECK SAL ()% END IF% END% CREATE OR REPLACE TRI**ER T1 BEFORE INSERT ON DEPT FOR EACH RO? DECLARE A DEPT DEPTNOOTYPE% BE*IN SELECT COUNT"DEPTNO) INTO A FROM DEPT ?HERE DEPTNOA:NE? DEPTNO% IF AFA1 THEN RAISEPAPPLICATIONPERROR"N2$$$1,(MASTER EDIST()% END IF% EDCEPTION ?HEN NOPDATAPFOUND THEN DBMSPOUTPUT PUTPLINE"(N2$$$1 NO MASTER RECORD()% END% "MUTATIN* ERROR) CREATE OR REPLACE TRI**ER T# AFTER UPDATE ON EMP FOR EACH RO? DECLARE A NUMBER"1)% BE*IN SELECT COUNT"@) INTO A FROM EMP ?HERE DEPTNOA:50d DEPTNO% d=7.P5I2/I2 /I2P0-n4"(n48 d4/22n5(QQ( (QQ:50d d4/2n5)% IF AF1 THEN RAISEPAPPLICATIONPERROR"N2$$$1,(UPDATED()% END IF% END % VARRAY SELECT STATEMENT NNNNNNNNNNNNNNNNNNNNNNN R@DECLARE CURSOR C1 IS SELECT @ FROM TABLENAME% A CIORO?TYPE% BE*IN FOR I IN C1 LOOP DBMSPOUTPUT PUTPLINE"(SDFS :(QQ )% FOR I IN C1 COUNT LOOP DBMSPOUTPUT PUTPLINE"SDA)% END LOOP% END LOOP END%

@R

NESTED TABLES: NNNNNNNNNNNNNN SELECT D NAME FROM THE "SELECT EMPL FROM DEPTNEST ?HERE DNOA1$) D ?HERE D NAMEA(YYYY(% SUBPROGRAMS 1 PROCEDURE S1n2aE: CREATE OR REPLACE PROCEDURE LPROCNAMEF "PARAMETERLIST) LDECLARATIONF BE*IN EDECUTABLE STATEMENTS EDCEPTION HANDLERS END% E; : CREATE OR REPLACE PROCEDURE P1 "A NUMBER,B NUMBER) IS COMMISSION NUMBER% NULLPCOMM EDCEPTION% BE*IN SELECT COMM INTO COMMISSION FROM EMP ?HERE EMPNOAA% IF COMMISSION IS NULL THEN RAISE NULLPCOMM% ELSE UPDATE EMP SET COMMASALHB ?HERE EMPNOAA% END IF% EDCEPTION ?HEN NULLPCOMM THEN DBMSPOUTPUT PUTPLINE"(THE VALUE COMM IS NULL()% END% EDEC P1",'!!,1$$$)% 1 1 IN PARAMETER CREATE OR REPLACE PROCEDURE P2 "NO IN NUMBER) IS PRICE NUMBER% BE*IN SELECT ACTUALPRICE INTO PRICE FROM ITEM ?HERE ITEMIDANO% DBMSPOUTPUT PUTPLINE"(ORI*INAL PRICE IS(QQ( (QQTOPCHAR"PRICE))% IF PRICE IS NULL THEN DBMSPOUTPUT PUTPLINE"(PRICE IS NULL()% END IF% END% EDEC P2"1$)% 1 2 IN OUT PARAMETER IS

CREATE OR REPLACE PROCEDURE P# "INNER IN NUMBER, A OUT NUMBER) IS ID NUMBER% BE*IN SELECT DEPTNO INTO ID FROM EMP ?HERE EMPNOAINNER% IF IDL'$ THEN A:A)$% END IF% END%

DECLARE INNER NUMBER% A NUMBER% BE*IN P# ",'!!,A)% DBMSPOUTPUT PUTPLINE"(THE OUT VALUE IS (QQ( (QQTOPCHAR"A))% END% CREATE OR REPLACE PROCEDURE SAMPLE "A IN NUMBER,B IN OUT NUMBER) IS ID NUMBER% BE*IN SELECT ORDID,PRODID INTO ID ,B FROM ITEM ?HERE ITEMIDAA% IF BL)$$ THEN B:ABH1$$% END IF% END% DECLARE BE*IN END%

A NUMBER% B NUMBER% SAMPLE"1$,B)% DBMSPOUTPUT PUTPLINE"(B VALUE IS(QQ( (QQB)%

FUNCTIONS NNNNNNNNN LCREATE OR REPLACE FUNCTION NAMEF ["AR*UMENT) N IN ,OUT ,IN OUT^ RETURN DATATYPE IS F DECLARATION BE*IN EDECUTABLE STATEMENTS EDCEPTION EDCEPTION HANDLERS END% >94a24 59 94/0a>4 6In>2-5n 61 942I9n nI7=49 -. a 47/ .a0O21/4% =4;-n SELECT SAL INTO A FROM EMP ?HERE ENAMEA(ALLEN(% RETURN A% END%

DECLARE B NUMBER% BE*IN B:AF1% DBMSPOUTPUT PUTPLINE"B)% END% CREATE OR REPLACE FUNCTION FUN"ID NUMBER,AMOUNT NUMBER) RETURN BOOLEAN IS MINI NUMBER% MADI NUMBER% BE*IN SELECT MINPRICE,STDPRICE INTO MINI,MADI FROM PRICE ?HERE PRODIDAID% RETURN "MINIFAAMOUNT) OR "MADIFAAMOUNT)% END% TO EDECUTE IT: DECLARE ID NUMBER% AMOUNT NUMBER% REMARK BOOLEAN% ID:AMA% AMOUNT:AMB% REMARK:AFUN"ID,AMOUNT)% IF REMARKATRUE THEN DBMSPOUTPUT PUTPLINE"(TRUE()% DBMSPOUTPUT PUTPLINE"(FALSE()%

BE*IN

ELSE END IF% END%

CREATE OR REPLACE FUNCTION FUN"N VARCHAR2) RETURN VARCHAR2 IS & VARCHAR2"1$)% BE*IN SELECT &OB INTO & FROM EMP ?HERE ENAMEAN% RETURN &% END% SELECT FUN"(BLAKE() FROM DUAL% IN PARAMETER NNNNNNNNNNNNN CREATE OR REPLACE FUNCTION F1"NAME IN VARCHAR2) RETURN NUMBER IS A EMP SALOTYPE% BE*IN SELECT SAL INTO A FROM EMP ?HERE ENAMEANAME% RETURN A% END% DECLARE

B NUMBER% BE*IN B:AF1"(MA()% DBMSPOUTPUT PUTPLINE"B)% END% IN AND OUT NNNNNNNNNN CREATE OR REPLACE FUNCTION F1"NAME IN VARCHAR2,B OUT VARCHAR2) RETURN NUMBER IS A EMP SALOTYPE% BE*IN SELECT SAL,&OB INTO A,B FROM EMP ?HERE ENAMEANAME% RETURN A% END% DECLARE A NUMBER% &OB VARCHAR2"2$)% BE*IN A:AF1"(M>(,&OB)% DBMSPOUTPUT PUTPLINE"AQQ( (QQ&OB)% END% IN OUT NNNNNN CREATE OR REPLACE 6In>2-5n F1"A IN nI7=49,> OUT NUMBER) RETURN NUMBER IS B EMP COMMOTYPE% BE*IN SELECT SAL,COMM INTO .a01,>5771 FROM EMP ?HERE EMPNOAA% RETURN .a01% END% R@ ERROR @R DECLARE M2 NUMBER"))% M# NUMBER% M1 NUMBER% SALARY NUMBER% BE*IN M1:AF1"MM2,M#)% DBMSPOUTPUT PUTPLINE"M2QQ( (QQSALARY)% END%

PACKA*E SPECIATION NNNNNNNNNNNNNNNNNNN CREATE OR REPLACE PACKA*E PACK1 IS PROCEDURE P1% FUNCTION F1 RETURN NUMBER% A NUMBER% END PACK1% CREATE OR REPLACE PACKA*E BODY PACK1 IS PROCEDURE P1 IS

BE*IN DBMSPOUTPUT PUTPLINE"(P1 PACKA*E()% END P1% FUNCTION F1 RETURN NUMBER IS BE*IN A:A1$$$% RETURN A% END F1% END PACK1% DECLARE N NUMBER% BE*IN N:APACK1 F1% DBMSPOUTPUT PUTPLINE"N)% PACK1 P1% END% R@ CREATE OR REPLACE PACKA*E PACK2 IS PROCEDURE DDEP% FUNCTION BALANCE RETURN NUMBER% NAME VARCHAR2"1))% END PACK2%

CREATE PACKA*E BODY PACK2 IS FUNCTION BALANCE "NAME IN VARCHAR2) RETURN NUMBER AS BALANCE NUMBER"1$,2)% BE*IN SELECT SAL INTO BALANCE FROM EMP ?HERE ENAMEANAME% RETURN"BALANCE)% EDCEPTIONS ?HEN NOPDATAPFOUND THEN RAISEPAPPLICATIONPERROR"N2$1$1,(NO ?ORKER ON THAT NAME()% END PACK2% PROCEDURE DDEP"NAME IN VARCHAR2) IS BE*IN INSERT INTO DEPT"DEPTNO,DNAME,LOC) VALUES"1$,NAME,NULL)% END DDEP% END PACK2% @R PLRSQL COMPOSITE DATA TYPE NNNNNNNNNNNNNNNNNNNNNNNNNN DECLARE TYPE T1 IS TABLE OF EMP .a0 OTYPE INDED BY BINARYPINTE*ER% M BINARYPINTE*ER :A1% T2 T1% BE*IN FOR I IN 1 2$ LOOP

T2"M) :AI@1$% DBMSPOUTPUT PUTPLINE"T2"M)QQ( (QQ7)% M:AMH1% END LOOP% END% DECLARE TYPE T1 IS TABLE OF EMP ENAMEOTYPE INDED BY BINARYPINTE*ER% M BINARYPINTE*ER:A$% T2 T1% BE*IN FOR I IN "SELECT ENAME FROM EMP ) LOOP T2"M):AI ENAME% NNINSERT INTO DEPT1"DNAME) VALUES"T2"M))% d=7.P5I2/I2 /I2P0-n4"22"7)QQ( (QQ7)% M:AMH1% END LOOP% END% DECLARE TYPE T1 IS TABLE OF EMP ENAMEOTYPE INDED BY BINARYPINTE*ER% M BINARYPINTE*ER :A1% T2 T1% T# T1% BE*IN FOR I IN"SELECT ENAME FROM EMP) LOOP T2"M) :AI ENAME% T#"M):AT2% DELETE FROM EMP ?HERE ENAMEAT2"M)% DBMSPOUTPUT PUTPLINE"T#"M))% M:AMH1% END LOOP% END% DECLARE TYPE T1 IS TABLE OF DEPTORO?TYPE INDED BY BINARYPINTE*ER% T2 T1% M BINARYPINTE*ER :A1% BE*IN FOR I IN "SELECT @ FROM DEPT) LOOP T2"M) DEPTNO :AI DEPTNO% T2"M) DNAME :AI DNAME% T2"M) LOC :AI LOC% DBMSPOUTPUT PUTPLINE"T2"M) DEPTNOQQ( (QQT2"M) DNAMEQQ( (QQT2"M) LOC)% M :AMH1% END LOOP% END% NNRECORD"ONE RO?) DECLARE

TYPE T1 IS RECORD "A NUMBER"#),B VARCHAR2"#$),C VARCHAR2"#$))% T2 T1% BE*IN SELECT @ INTO T2 FROM DEPT ?HERE DEPTNOA1$% DBMSPOUTPUT PUTPLINE"T2 AQQT2 BQQT2 C)% END% BE*IN END% SELECT @ FROM EMP%

NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN BE*IN END% UPDATE EMP SET SALASALH2$$$%

NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN DECLARE I NUMBER :A,,GG% & NUMBER :A1$$$$% BE*IN UPDATE EMP SET SALA& ?HERE EMPNOAI% END% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN DECLARE I NUMBER:AMI% & NUMBER:AM&% BE*IN UPDATE EMP SET SALA& ?HERE EMPNOAI% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN DECLARE I NUMBER% & NUMBER% BE*IN UPDATE EMP SET SALAM& ?HERE EMPNOAMI% END% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN FOR LOOP NNNNNNNN FOR LVARF IN LMINF LOOP N N N END LOOP% LMADVALUEF

NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN d4>0a94 =4;-n FOR I IN 1 ) LOOP INSERT INTO TEMP VALUES "I)% END LOOP% 4nd% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN ?HILE LOOP NNNNNNNNNN ?HILE LCONDITIONF LOOP N N N END LOOP% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN DECLARE A NUMBER"2)% BE*IN A:AMA% FOR COUNT IN 1 A LOOP INSERT INTO TEMP VALUES "COUNT)% END LOOP% END% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN DECLARE I NUMBER:A1$% BE*IN ?HILE I LA1) LOOP INSERT INTO TEMP VALUES "I)% I:AIH1% END LOOP% END% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN DECLARE I NUMBER:A1% BE*IN ?HILE ILA1$ LOOP INSERT INTO TEMP VALUES"I,(DDDD()% IF IF) THEN EDIT% END IF% I:AIH1% END LOOP%

INSERT INTO TEMP VALUES"I,(YYYY()% END% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN *O TO STATEMENT NNNNNNNNNNNNNNN DECLARE I NUMBER:A1% BE*IN ?HILE ILA1$ LOOP INSERT INTO TEMP VALUES"I,(DDDD()% IF IA) THEN *OTO PROC% END IF% I:AIH1% END LOOP% LLPROCFF INSERT INTO TEMP VALUES"I,(PROC()% END% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN USIN* INTO CLASS NNNN DECLARE BE*IN END% SET SERVEROUT ON% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN RRRRRRRRRRRRRRRR"UPDATE ERROR) DECLARE TNO NUMBER :AMTEMPNO% TEMPSAL NUMBER % TEMPCOMM NUMBER% BE*IN SELECT SAL,COMM INTO TEMPSAL,TEMPCOMM FROM EMP ?HERE EMPNOATNO% IF TEMPCOMM F1$$$ AND TEMPSAL LA)$$$ THEN UPDATE EMP SET SALASALH2$$$ ?HERE EMPNOATNO% ELSIF TEMPSAL F2$$$ UPDATE EMP SET SALASALH1$$$ ?HERE EMPNOATNO% END IF% END% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN DECLARE TEMPEMPNO NUMBER:AMTEMPEMPNO% TEMP TEMPSAL NUMBER:A MTEMPNO% NUMBER%

SELECT SAL INTO TEMPSAL FROM EMP ?HERE EMPNOATEMP% DBMSPOUTPUT PUTPLINE"TEMPSAL)%

TEMPHIREDATE DATE% TEMPNAME VARCHAR2"2$)% BE*IN SELECT HIREDATE,ENAME INTO TEMPHIREDATE,TEMPNAME FROM EMP ?HERE EMPNOATEMPEMPNO% IF TEMPHIREDATE FA($1N&ANNG$( AND TEMPHIREDATE LA(#$N&ANNG)( UPDATE EMP SET COMMACOMMHCOMM@$ 1 ?HERE EMPNOATEMPEMPNO% END IF% END%

THEN

NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN DECLARE TEMPEMPNO NUMBER:AMTEMPEMPNO% TEMPDEPTNO NUMBER% BE*IN SELECT DEPTNO INTO TEMPDEPTNO ?HERE EMPNOATEMPEMPNO% IF TEMPDEPTNOA1$ THEN UPDATE EMP SET SALASALH1$$$ ?HERE EMPNOATEMPEMPNO% ELSIF TEMPDEPTNOA2$ THEN UPDATE EMP SET SALASALH2$$$ ?HERE EMPNOATEMPEMPNO% ELSIF TEMPDEPTNOA#$ THEN UPDATE EMP SET SALASALH#$$$ ?HERE EMPNOATEMPEMPNO% ELSE UPDATE EMP SET SALASALH'$$$ ?HERE EMPNOATEMPEMPNO% END IF%

END%

NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN DECLARE

A NUMBER% B NUMBER% C NUMBER% A:AMA% B:AMB% C:AAHB% DBMSPOUTPUT PUTPLINE"C)%

BE*IN

END% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NN OTYPE NNNNNNNN DECLARE SALARY EMP SALOTYPE% DO& EMP HIREDATEOTYPE% BE*IN SELECT SAL,HIREDATE INTO SALARY,DO& FROM EMP ?HERE EMPNOA,!$$% DBMSPOUTPUT PUTPLINE"SALARYQQ( (QQDO&)%

END% NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

Bewerten