You are on page 1of 435

ORACLE

ORACLE SYLABUS: DATA BASE CONCEPTS: WHAT IS DATABASE MANAGEMENT SYSTEMS (DBMS). BENEFITS OFDBMS. WHAT IS RELATONAL DATABASE MANAGEMENT SYSTEMS (RDBMS). 12RULES OFDR.E.F.CODDSRULESOFRDBMS. DBMSV/SRDBMS. OBJECTRELATIONALDATABASEMANAGEMENTSYSTEMS.(ORDBMS). RDBMSVSORDBMS. INTRODUCTION TO OODBMS. ORDBMS VS OODBMS. NORMALIZATION.

INSTALLATION OF ORACLE 9I: COMPLETE INSTALATION OF ORACLE I ON MICROSOFT !P. CHANGING THE DEFAULT PASSWORD FOR SYS. POST INSTALLATION STEPS. ACTIVATING/DEACTIVATING THE ORACLE I ENGINE. DISABLING AUTOMATIC STARTUP. MANUALLY ENABLING THE ORACLE I SERVICES. CREATING USERS THROUGH THE ENTERPRISE MANAGER. CREATING USER THROUGH S"L#PLUS. CREATING TABLE SPACES THROUGH ENTERPRISE MANAGER. CREATING TABLE SPACES THROUGH S"L#PLUS.

INTRODUCTION OF STRUCTURED QUERY LANGUAGE (SQL) AND SQL*PLUS: FEATURES OF S"L FEATURES OF S"L # PLUS S"L VS S"L#PLUS RULES FOR S"L. DDL$ DRL$ DML$ TCL$ DCL COMMANDS.

INTRODUCTION OF ISQL*PLUS: NEW FEATURE OF ORACLE I SAME AS S"L#PLUS THAT WILL BE OPNED ONLY IN BROWSER.

DATABASE OBJECTS: DATABASE OBJECTS. NAMING CONVENTIONS. THE CREATE TABLE STATEMENT. DISPLAYING TABLE STRUCTURE. THE DEFAULT OPTION. TABLES IN ORACLE DATABASE. "UERYING THE DATA DICTIONARY. DATA TYPES IN ORACLE. CREATING TABLE USING SELECT STATEMENT. ADDING$MODIFYING$DROPING COULMNS$ SET UNUSED OPTION. DROPING TABLE. CHANGING NAME OF A TABLE. ADDING COMMENTS TO TABLES.

INSERTING DATA IN A TABLE: THE INSERT STATEMENT.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ADDING A NEW ROW TO A TABLE. INSERTING ROWS WITH NULL VALUES. INSERTING SPECIFIC DATE VALUES$ INSERTING VALUES BY USING SUBSTITUTION VARIABLES. CREATING ROWS FROM ANOTHER TABLE USING SELECT STATEMENT. ORACLE I INSERT STATEMENTS.% o CONDITIONAL INSERT. o UNCONDITIONAL INSERT. o INSERT FIRST. o PIVOTING INSERT.

SELETING DATA IN A TABLE: SELECT STATEMENT SELETING ALL COLUMNS SELECTING WITH WHERE CLAUSE$ COULMN HEADING DEFAULTS.

UPDATING DATA IN A TABLE: THE UPDATE STATEMENT. UPDATING ROWS IN A TABLE. UPDATING ROWS IN A TABLE USING WHERE CLAUSE. UPDATING WITH MULTIPLE&COLUMN SUB"UERY. UPDATING ROWS BASED ON ANOTHER TABLE. UPDATING TWO OR MORE COLUMNS.

DELETING DATA IN A TABLE: CONSTRAINTS: WHAT ARE CONSTRAINTS. DEFINING CONSTRAINTS. NOT NULL CONSTRAINT. UNI"UE CONSTRAINT. PRIMARY 'EY CONSTRAINT. FOREIGN 'EY CONSTRAINT. FOREIGN 'EY CONSTRAINT WITH ON DELETE CASCADE. FOREIGN 'EY CONSTRAINT WITH ON DELETE SET NULL. CHEC' CONSTRAINT. GIVING CONSTRAINT AT COLUMN LEVEL. GIVINGCONSTRAINTATTABLELEVEL. GIVINGCONSTRAINTAFTERCREATIONOFTABLE. DROPING CONSTRAINTS. DISABLING CONSTRAINTS. ENABLING CONSTRAINTS. CASCADINGCONSTRAINTS. VIEWING CONSTRAINTS. VIEWING THE COLUMNS ASSOCIATED WITH CONSTRAINTS. THE DELETE STATEMENT. DELETING DATA IN A TABLE. DELETING DATA IN A TABLE BASED ON ANOTHER TABLE. COMMIT AND ROLL BAC' STATEMENTS. TRUNCATE DATA IN A TABLE. DELETE VS TRUNCATE.

I)PORTANT OPERATORS AND FUNCTIONS: WHERE CLAUSE. CHARACTERSTRINGS AND DATES. COMPARISON OPERATORS.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
BETWEEN OPERATOR. IN OPERATOR. LI'E OPERATOR. NULL OPERATOR. ISNULL OPERATOR. AND OPERATOR. OR OPERATOR. NOT OPERATOR. ARITHMETIC E!PRESSIONS. ARITHMETIC OPERATORS. OPERATOR PRECEDENCE. DEFINING NULL VALUE. NVL FUNCTION. DEFINING A COLUMN ALIASES.. CONCATENATION OPERATOR. DISTINCT FUNCTION. ORDER BY CLAUSE. SORTING BY COLUMN ALIASES. SORTING BY MULTIPLE COLUMNS.

SQL FUNCTIONS: JOINS: WHAT IS JOIN. CARTESIAN PRODUCT. E"UI&JOIN. NONE"UI&JOIN. OUTER&JOIN. SELF&JOIN. CHARACTER FUNCTIONS. NUMBER FUNCTIONS. DATE FUNCTIONS. E!PLICIT AND IMPLICIT DAAT TYPE CONVERSIONS. TO(NUMBER FUNCTIONS. TO(CHAR FUNCTIONS. TO(DATEFUNCTIONS. JULIAN DATE FUNTION. SOME SPECIAL DATE FUNCTIONS. DECODE FUNCTION. SOUNDE!. NULLIF NVL2. COALSEC.

SET OPERATORS: UNION ALL. UNION. INTERSECT. MINUS.

GROUP FUNCTIONS AND GROUP BY CLAUSE: WHAT ARE GROUP FUNCTIONS. TYPES OF GROUP FUNCTIONS. CREATING GROUPS OF DATA &GROUP BY CLAUSE. HAVING CLAUSE. ROLL UP OPERATOR.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SUBQUERIES: USING SUB "UERIES. TYPEOFSUB "UERIES. SINGLE ROW SUB"UERIES WITH COMPARISON OPERATORS. MULTI ROW SUB"UERIES. ANY. ALL. FINDING 2ND HIGHEST$)RD HIGHEST AND SO ON**.. E!SITS. NOT E!SITS. MULTI&COLUMNSUB"UERIES. SUB"UERIESINFROM CLAUSE. SUB"UERIES IN ORDER BY CLAUSE. HIERARCHICAL DATA ACCESS.START WITH CONNECT BY PRIOR. CORRELATED SUB "UERY. CUBE OPERATOR.

SQL*PLUS CO))ANDS: *IE+S: SEQUENCES: WHAT IS A SE"UENCE. CREATING SE"UENCES. NE!T VAL AN D CURR VAL STATEMENTS. VIEWING SE"UENCES. USING SE"UENCES FOR GENERATING UNI"UE NUMBER FOR COLUMNS. ALTER A SE"UENCES. REMOVING SE"UENCES. WHAT IS VIEW. USES OF VIEWS. CREATING SIMPLE VIEWS. DML THROUGH SIMPLE VIEW. MODIFYING VIEW. VIEWING VIEWS IN DATABASE. CREATING COMPLE! VIEW. RULES FOR DML THROUGH COMPLE! VIES. WITH CHEC' OPTION. WITH READ ONLY. IN LINE VIEWS. ROWNUM COLUMN. FINDING PARTICULAR HIGHEST USING ROWNUM. FINDING FROM ! TO Y USING ROWNUM. REMOVING VIEW. SUBSTITUTION VARIABLES. SET VERIFY ON/OFF. + AND ++SUBSTITUTIONVARIABLES. ACCEPT. DEFINE$UNDEFINE COMMANDS. SETCOMMANDVARIABLES. SAVING CUTOMIZATIONS IN LOGIN.S"L. S"L#PLUS EDITING COMMANDS. S"L#PLUS FILE COMMANDS. FORMAT COMMANDS. COLUMN COMMANDS. BREA' COMMAND. TTITLE$BTITLE COMMANDS. CREATING SAMPLE REPORT.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DATABASE TUNING: WHAT IS INDE!. CREATING INDE!. USES OF INDE!. OVER VIEW ROWID. WHEN TO CREATE AND WHEN NOT TO CREATE INDE!S. REMOVING INDE!ES. WHAT IS SYNONYMS. CREATING AND REMOVING SYNONYMS. CREATING AND MANAGING CLUSTERS. CREATING AND MANAGING SNAPSHOT. PARTITIONING.

TRANSACTIONS: COMMIT. ROLLBAC'. SAVEPOINT.

CONTROLLING USER ACCESS: CONTROLLING USER ACCESS. PRIVILEGES. OBJECT AND SYSTEM PRIVILEGS. HOW TO GRANT AND REVO'E PRIVILEGES. GRANTING OBJECT AND SYSTEM PRIVILEGES WITH GRANT AND ADMIN OPTIONS. WHAT IS ROLE. USES AND GRANTING PRIVILEGS TO ROLE.

PL ,SQL: (PROCEDURAL LANGUAGE AND STRUCTURED QUERY LANGUAGE): ABOUT PL/S"L. BENEFITS OF PL/S"L. PL/S"L BLOC'S. DECLARING PL/S"L VARIABLES. NAMING$ASSIGNING$VARIABLE INITIALIZTION OF VARIABLES. PL/S"L RECORD STRUCTURE. -TYPE$-ROWTYPE$LOBVARIABLES. BIND VARIABLES$ REFERENCING NON&PL/S"L VARIABLES. DBMS(OUTPUT.PUT(LINE. COMMENTING CODE. S"L$PL/S"L FUNCTIONS. PROGRAMMING GUIDE LINES. CODE NAMING CONVENTIONS. DETERMING VARIABLE SCOPE.

CONTROL STRUCTURES : IF&THEN&ELSE STATEMENTS. BASIC LOOP. FOR LOOP. WHILE LOOP CASE STATEMENTS.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CO)POSITE DATATYPES: PL/S"L RECORDS. -TYPE. -ROW TYPE. PL/S"L TABLES. +OR-ING +IT. I)PLICIT AND E/PLICIT CURSORS: ABOUT CURSORS. CURSOR ATTRIBUTES. S"L-ISOPEN$S"L-FOUND$S"L-NOTFOUND$S"L-ROWCOUNTFORIMPLICITCURSORS. -ISOPEN$-FOUND$-NOTFOUND$-ROWCOUNT FOR E!PLICIT CURSORS. VARIOUS LOOPS IN CURSORS. CURSOR VARIABLES. PARAMETERISED CURSORS. WHERE CURRENT OF CLAUSE. FOR UPDATE CLAUSE. REF CURSORS. CURSORS WITH SUB"UERY.

+OR-ING +IT. E/CEPTIONS: WHAT IS E!CEPTION. TYPES OF E!CEPTIONS. USER AND PREDEFINED E!CEPTIONS. HANDLING E!CEPTIONS. RAISE&APPLICATION&ERROR E!CEPTION(INIT. S"LCODE. S"LERRM.

PL0SQL SECURITY: ORACLE DEFAULT LOC'ING. TYPES OF LOC'S. LEVEL OF LOC'S. E!PLICIT LOC'ING. SELECT FOR UPDATE. READ CONSISTENCY.

STORED PROCEDURES: OVERVIEW OF PROCEDURES. IMPORTANCE OF STORED PROCEDURES. CREATING PROCEDURES. COMPILING PROCEDURES. CREATING PROCEDURES WITH PARAMETERS. IN$OUT$IN OUT PARAMETERS. DEFAULT OPTION FOR PARAMETERS. FORWARD DECLARATION. OVERLOADING OF PROCEDURE. REMOVING PROCEDURES.

STORED FUNCTIONS: OVERVIEW OF FUNCTIONS. IMPORTANCE OF STORED FUNCTIONS. CREATING FUNCTIONS. RETURN STATEMENT. COMPILING FUNCTIONS

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
PAC-AGES: OVERVIEW OF PAC'AGES. COMPONENTS OF PAC'AGE. IMPORTANCE OF PAC'AGES. CREATING PAC'AGE SPECIFICATION. CREATING PAC'AGE BODY. USER DEFINED PAC'AGES. REFERENCING PAC'AGE OBJECTS. ORACLE SUPPLIED PAC'AGES$ GLOBAL VARIABLES. PRAGMA RESTRICT(REFERENCES. E!ECUTE IMMEDIATE. ORACLE BUILT IN PAC'AGES. DBMS(PIPE. DBMS(S"L. DBMS(DDL. DBMS(JOB. DBMS(OUTPUT. REMOVING FUNCTIONS.. COMPARING PROCEDURES AND FUNCTIONS.

CREATING DATABASE TRIGGERS: OVER VIEW OF TRIGGERS. CREATING AND MANAGINGTRIGGERS. TRIGGER COMPONENTS. FIRING SE"UENCE. INSTEADOFTRIGGER. ENABLING AND DISABLING TRIGGERS$ AUDIT&TRAIL USING TRIGGERS. PROTECT DATA$REFERENTIAL INTEGRITY. MUTATING TABLE. GENERATION OF PRIMARY 'EY USING TRIGGER. REPLICATE A TABLE. COMPUTE DERIVED VALUES BENEFITS OF TRIGGERS.

)ANAGING SUBPROGRA)S AND TRIGGERS: USER(OBJECTS. USER(SOURCE. USER(ERRORS. USER(TRIGGERS. DEBUGGING USING DBMS(OUTPUT.

)ANAGING DEPENDENCIES: UNDERSTANDING DEPENDENCIES USER(DEPENDENCIES.

FILE INPUT0OUTPUT: PL/S"L FILE I/O USING UTL&FILE PAC'AGE.

OOPS IN ORACLE 9I:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CREATION OF OBJECTS. USER DEFINED TYPES. OBJECT TABLES. OBJECT VIEWS. DML THROUGH OBJECTS. )ANIPULATING LARGE OBJECTS: WHAT IS LOB. COLB. BLOB. NCOLB. BFILE. CREATING TABLES WITH LOBS. DBMS(LOB. CREATION OF E!TERNAL TABLES.

+OR-ING +IT. COLLECTIONS: VARRAYS. NESTED TABLES. INDE! BY TABLES. DML OPERATIONS ON NESTED TABLES.

DE*ELOP)ENT AND E/ECUTION EN*IRON)ENTS: APPLICATION MODELS IN PL/S"L. TWO&TIER$THREETIERMODEL. S"L#PLUS. RAPIDS"L. S"L NAVIGATOR. TOAD. PL/S"LDEVELOPER. S"L1PROGRAMMER. DBPARTNER DEBUGGER. IS"L # PLUS.

ORACLE DATABASE ARC.ITECTURE: OVER VIEW OF ORACLE DATABASE. LOGICAL AND PHYSICAL STRUCTURE.

INTRODUCTION TO INTERNET TEC.NOLOGIES: PROJECT: THE ABOVE TOPICS WILL BE COVERED USING DEFAULT TABLES EMP$DEPT$SALGRADE AND PROJECT BASED STUDY ON BUSSINESS MODEL FOR RETAIL BAN'ING AND SALES ORDER ENTRY SYSTEM. COMPLETE DATABASE OF ABOVE TWO PROJECTS WILL BE PROVIDED. IN GENERAL IF WE WANT TO STORE EMPLOYEE INFORMATION$WE STORE AS SHOWN BELOW% TWO 1TER ARCHITECTURE. THREE&TIER ARCHITECTURE. N&TIER ARCHITECTURE. JAVA OBJECTS IN ORACLE. S"LJ

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMPNO 133 131 132 13) ENAME PAVAN GAYATRI BALAJI SMITH JOB CHAIRMAN P.S MANAGER MANAGER 133 133 133 MGR HIREDATE 31&JAN&233. 31&JAN&233. 31&JAN&233. 31&JAN&233. SAL )3333 13333 13333 13333 COMM 13333 1333 1333 1333 DEPTNO 13 13 13 13 IN ORACLE WE USE TABLES TO STORE DATA. TABLE CONTAINS COLUMNS AND ROWS. OPENING SQL* PLUS IN ORACLE 1 : GO TO ALL PROGRAMS AND SELECT ORACLE FOR WINDOWS . AND CLIC' S"L#PLUS. YOU GET DIALOG BO!. TYPE SCOTT IN USERNAME AND TIGER IN PASSWORD AND PRESS ENTER. YOU GET S"L PROMPT.

OPENING SQL* PLUS IN ORACLE 9 : GO TO ALL PROGRAMS AND SELECT ORACLE&ORAHOME 3 SELECT APPLICATION DEVELOPMENT IN THERE CLIC' S"L PLUS AND TYPE SCOTT IN USER NAME TIGER IN PASSWORD BO!.

IN ORACLE 1 :USER CREATION: HERE IF YOU WANT TO CREATE YOUR OWN USER YOU GO TO ALL PROGRAMS$ THERE PERSONAL ORACLE FOR WINDOWS . AND ORACLE NAVIGATOR. CLIC' THAT YOU WILL GET WINDOW THERE DOUBLE CLIC' PERSONAL ORACLE 2 AND DOUBLE CLIC' ON LOCAL DATABASE. YOU SEE DROP DOWN LIST. THERE CLIC' ON USER AND RIGHT CLIC' ON USER AND NEW. YOU GET WINDOW TYPE USERNAME$PASSWORD(TWICE). YOUR USER CREATED.

THEN CLIC' S"L#PLUS AS SHOWN ABOVE AND TYPE YOUR USERNAME AND PASSWORD. IN THE ABOVE TABLE WE TA'E EMPNO$ ENAME$ JOB$MGR$HIREDATE$SAL$COMM$ DEPTNO AS COLUMNS IN CREATING TABLE IN ORACLE. CREATION OF TABLE: S"L4CREATE TABLE EMPLOYEE(INFO 2 (EMPNO NUMBER(13)$ ) ENAME VARCHAR2(13)$ , JOB VARCHAR2(13)$ . MGR NUMBER(13)$ / HIREDATE DATE$ 0 SAL NUMBER(13)$ 2 COMM NUMBER(13)$ # DEPTNO NUMBER(13))5 T6789 :;96<9=. IN S"L#PLUS$WE USE CL SCR TO CLEAR SCREEN. IN S"L#PLUS$WE TYPE ED AT S"L PROMPT TO GET EDITOR$WE EDIT S"L STATEMENTS THERE. DESCRIBE COMMAND WILL GIVE US WITH WHAT COLUMNS WE CREATED TABLE AND THEIR DATATYPE. S"L4 DESC EMPLOYEE(INFO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
N6>9 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO N?88@ TAB9 NUMBER(13) VARCHAR2(13) VARCHAR2(13) NUMBER(13) DATE NUMBER(13) NUMBER(13) NUMBER(13)

13

INSERTING *ALUES IN TO TABLE: S"L4 INSERT INTO EMPLOYEE(INFO 2 VALUES ) (133$CPAVANC$CCHAIRMANC$NULL$C31&JAN&233.C$)3333$13333$13)5 1 ;DE :;96<9=. +.EN E*ER +E +RITE *ALUES IN INSERT +E .A*E TO GI*E *ALUES FOR ALL COLU)NS( S"L4 INSERT INTO EMPLOYEE(INFO 2 VALUES ) (131$CGAYATRIC$CP.SC$133$C31&JAN&233.C$13333$1333$13)5 1 ;DE :;96<9=. S"L4 INSERT INTO EMPLOYEE(INFO 2 VALUES ) (132$C'UMARIC$CMANAGERC$133$C31&JAN&233.C$13333$1333$13)5 1 ;DE :;96<9=. S"L4 INSERT INTO EMPLOYEE(INFO 2 VALUES ) (13)$CSMITHC$CMANAGERC$133$C31&JAN&233.C$13333$1333$13)5 1 ;DE :;96<9=.

IF I +ANT TO INSERT INTO ONLY FE+ COLU)NS T.EN I +ILL +RITE LI-E T.IS: S"L4 INSERT INTO EMPLOYEE(INFO (EMPNO$ENAME$JOB$DEPTNO) 2 VALUES ) (13,$CSMITHC$CMANAGERC$13)5 1 ;DE :;96<9=. SELECTING *ALUES FRO) A TABLE: WHENEVER WE SELECT FROM THE TABLE WE GET COMPLETE INFORMATION IN A TABLE. S"L4 SELECT EMPNO$ENAME$JOB$MGR$HIREDATE$SAL$COMM$DEPTNO FROM EMPLOYEE(INFO5 EMPNO ENAME JOB MGR HIREDATE &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& 133 PAVAN CHAIRMAN 31&JAN&3. )3333 131 GAYATRI P.S 133 31&JAN&3. 13333 132 'UMARI MANAGER 133 31&JAN&3. 13333 13) SMITH MANAGER 133 31&JAN&3. 13333 , ;DEF F989:<9=. SAL 13333 1333 1333 1333 COMM DEPTNO 13 13 13 13

HERE INSTEAD OF TYPING ALL THE COLUMN NAMES WE TYPE G#H.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM EMPLOYEE(INFO5 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& 133 PAVAN CHAIRMAN 31&JAN&3. )3333 131 GAYATRI P.S 133 31&JAN&3. 13333 132 'UMARI MANAGER 133 31&JAN&3. 13333 13) SMITH MANAGER 133 31&JAN&3. 13333 , ;DEF F989:<9=. SELECTING WITH WHERE CLAUSE% WHEN EVER WE SELECT USING WHERE CLAUSE WE GET PARTICULAR INFORMATION DEPENDS ON THE COLUMN YOU SPECIFY IN WHERE CLAUSE. S"L4 SELECT # FROM EMPLOYEE(INFO 2 WHERE EMPNOI1335 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& 133 PAVAN CHAIRMAN 31&JAN&3. 1 ;DE F989:<9=. S"L4 SELECT # FROM EMPLOYEE(INFO 2 WHERE ENAMEICGAYATRIC5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& 131 GAYATRI P.S 133 31&JAN&3. 13333 1333 13 1 ;DE F989:<9=. UPDATE STATE)ENT: WHILE UPDATING A TABLE IF YOU DONT GIVE WHERE CLAUSE WHOLE TABLE WILL BE UPDATED. S"L4 UPDATE EMPLOYEE(INFO 2 SET SALI SALJ13335 , ;DEF ?B=6<9=. S"L4 SELECT # FROM EMPLOYEE(INFO5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& 133 PAVAN CHAIRMAN 31&JAN&3. )1333 13333 13 131 GAYATRI P.S 133 31&JAN&3. 11333 1333 13 132 'UMARI MANAGER 133 31&JAN&3. 11333 1333 13 13) SMITH MANAGER 133 31&JAN&3. 11333 1333 13 , ;DEF F989:<9=. UPDATE TABLE USING +.ERE CLAUSE: WHEN EVER WE GIVE WHERE CLAUSE IN UPDATION ONLY THAT COLUMN CORESSPONDING ROWS WILL BE UPDATED. S"L4 UPDATE EMPLOYEE(INFO 2 SET SALI SALJ1333 ) WHERE EMPNOI1335 1 ;DE ?B=6<9=. COMM DEPTNO )3333 13333 13 COMM DEPTNO 13333 1333 1333 1333 13 13 13 13

11

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM EMPLOYEE(INFO5 EMPNO ENAME JOB MGR &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& 133 PAVAN CHAIRMAN 131 GAYATRI P.S 133 132 'UMARI MANAGER 133 13) SMITH MANAGER 133 , ;DEF F989:<9=. S"L4 UPDATE EMPLOYEE(INFO 2 SET SALI SALJ1333 ) WHERE ENAMEICGAYATRIC5 1 ;DE ?B=6<9=. S"L4 SELECT # FROM EMPLOYEE(INFO5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& 133 PAVAN CHAIRMAN 31&JAN&3. )2333 13333 13 131 GAYATRI P.S 133 31&JAN&3. 12333 1333 13 132 'UMARI MANAGER 133 31&JAN&3. 11333 1333 13 13) SMITH MANAGER 133 31&JAN&3. 11333 1333 13 , ;DEF F989:<9=. HIREDATE 31&JAN&3. 31&JAN&3. 31&JAN&3. 31&JAN&3. SAL )2333 11333 11333 11333 COMM DEPTNO 13333 1333 1333 1333 13 13 13 13

12

DELETING DATA FRO) A TABLE: IF YOU WANT TO DELETE INFO FROM A TABLE$HERE IF YOU WONT SPECIFY THE WHERE CLAUSE WHOLE TABLE INFO WILL BE DELETED. S"L4 DELETE FROM EMPLOYEE(INFO 2 WHERE EMPNOI1325 1 ;DE =989<9=. S"L4 SELECT # FROM EMPLOYEE(INFO5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& 133 PAVAN CHAIRMAN 31&JAN&3. )2333 13333 13 131 GAYATRI P.S 133 31&JAN&3. 12333 1333 13 13) SMITH MANAGER 133 31&JAN&3. 11333 1333 13 ) ;DEF F989:<9=. S"L4 DELETE FROM EMPLOYEE(INFO 2 WHERE ENAMEICSMITHC5 1 ;DE =989<9=. S"L4 SELECT # FROM EMPLOYEE(INFO5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& 133 PAVAN CHAIRMAN 31&JAN&3. )2333 13333 13 131 GAYATRI P.S 133 31&JAN&3. 12333 1333 13 2 ;DEF F989:<9=. HERE IF YOU WANT TO DELETE ALL EMPLOYEES WE USE THIS STATEMENT. IF YOU DONT SPECIFY WHERE IN DELETE COMPLETE TABLE WILL BE DELETED.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 DELETE FROM EMPLOYEE(INFO5 2 ;DEF =989<9=. CREATING TABLE +IT. SELECT STATE)ENT: IF YOU +ANT TO CREATE SA)E TABLE AS E)PLOYEE2INFO +IT. DATA" +E USE BELO+ STATE)ENT: CREATE TABLE EMP AS SELECT # FROM EMPLOYEE(INFO5 HERE EMP TABLE HAS SAME COLUMNS AS THAT OF EMPLOYEE(INFO AND EMP HAS SAME DATA THAT OF EMPLOYEE(INFO.HERE BOTH ARE SAME TABLES.

1)

IF YOU +ANT TO CREATE TABLE +IT. SELETED COLU)NS T.AT OF E)PLOYEE2INFO +IT. DATA FOR T.AT COLU)NS"+E USE BELO+ STATE)ENT: CREATE TABLE EMP AS SELECT EMPNO$ENAME FROM EMPLOYEE(INFO5 HERE EMP TABLE CREATED WITH EMPNO$ENAME COLUMNS AND DATA FOR THAT COLUMNS FROM EMPLOYEE(INFO TABLE. IF YOU +ANT TO CREATE TABLE +IT. SELETED COLU)NS T.AT OF E)PLOYEE2INFO +IT. DATA FOR T.AT COLU)NS +IT. YOUR O+N NA)E FOR COLU)NS"+E USE BELO+ STATE)ENT: CREATE TABLE EMP (EMPLOYEE(NO$EMPLOYEE(NAME) AS SELECT EMPNO$ENAME FROM EMPLOYEE(INFO5 HERE EMP TABLE CREATED WITH COLUMNS EMPNO$ENAME BUT THEIR HEADINGS WILL BE EMPLOYEE(NO$EMPLOYEE(NAME.

INSERTING *ALUES +IT. SELECT STATE)ENT: INSERT INTO EMP SELECT # FROM EMPLOYEE(INFO5 HERE BOTH EMP$EMPLOYEE(INFO TABLES SHOULD HAVE SAME STRUCTURE. )OST I)PORTANT TABLES IN ORACLE DATABASE: IN USER SCOTT WE HAVE THREE IMPORTANT TABLES THOSE ARE EMP DEPT SALGRADE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DELETE *S TRUNCATE: S"L4 SELECT # FROM EMPLOYEE(INFO5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 133 PAVAN CHAIRMAN 31&JAN&3. )2333 13333 13 131 GAYATRI P.S 133 31&JAN&3. 12333 1333 13 S"L4 DELETE FROM EMPLOYEE(INFO5 2 ;DEF =989<9=. S"L4 SELECT # FROM EMPLOYEE(INFO5 KD ;DEF F989:<9= S"L4 ROLL BAC'5 RD8876:L :D>B89<9.

1,

S"L4 SELECT # FROM EMPLOYEE(INFO5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 133 PAVAN CHAIRMAN 31&JAN&3. )2333 13333 13 131 GAYATRI P.S 133 31&JAN&3. 12333 1333 13

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 DELETE FROM EMPLOYEE(INFO5 2 ROWS DELETED. S"L4 COMMIT5 COMMIT COMPLETE. S"L4 ROLL BAC'5 ROLLBAC' COMPLETE. S"L4 SELECT # FROM EMPLOYEE(INFO5 NO ROWS SELECTED S"L4 INSERT INTO EMPLOYEE(INFO 2 VALUES ) (133$CPAVANC$CCHAIRMANC$NULL$C31&JAN&3.C$)2333$13333$13)5 1 ROW CREATED. S"L4 COMMIT5 COMMIT COMPLETE. S"L4 SELECT # FROM EMPLOYEE(INFO5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& &&&&&&&&& 133 PAVAN CHAIRMAN 31&JAN&3. )2333 13333 13 S"L4 TRUNCATE TABLE EMPLOYEE(INFO5 TABLE TRUNCATED. S"L4 ROLL BAC'5 ROLLBAC' COMPLETE. S"L4 SELECT # FROM EMPLOYEE(INFO5 NO ROWS SELECTED IN TRUNCATE TABLE THE WHOLE INFORMATION WIIL BE DELETED PERMENENTLY. BUT IN CASE OF DELETE THE INFORMATION WILL BE GET BAC' AFTER ROLL BAC'. BUT AFTER DELETE IF YOU TYPE COMMIT. THEN INFORMATION WILL BE DELETED PERMENENTLY. DELETE JCOMMIT I TRUNCATE.

1.

ORDER BY CLAUSE: WE CAN RETRIVE DATA EITHER IN ASCENDING ORDER OR IN DESCENDING ORDER BY USING ORDER BY CLAUSE% FOR RETRI*ING DATA IN ASCENDING ORDER: SELECT ENAME $ SAL FROM EMP ORDER BY SAL ASC 5 SELECT ENAME $ SAL FROM EMP ORDER BY SAL 5 DEFAULT IS ASCENDING ORDER. FOR RETRI*ING DATA IN DESCENDING ORDER:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECT ENAME$SAL FROM EMP ORDER BY SAL DESC 5 +E CAN RETRI*E ONE PARTICULAR AND SPECIFIC TYPE OF DATA BY USING T.E -EY +ORD 3LI-E4: SELECT ENMAE $JOB$SAL FROM EMP WHERE DEPTNO LI'E 135 SELECT ENAME$SAL$DEPTNO FROM EMP WHERE JOB LI'E G CLER' G 5 +E CAN RETRI*E )ORE SPECIFIC DATA BY USING LI-E AND SY)BOLS 3 5 4 "4 2 4: M -H REPRESENTS GROUP OF CHARACTERS . M(M REPRESENTS SINGLE CHARACTER .

1/

TO GET E)PLOYEES +IT. S LETTER IN T.E FIRST OF T.EIR NA)E: SELECT # FROM EMP WHERE ENAME LI'E G S- 5 TO GET E)PLOYEES +IT. S LETTER IN T.E LAST OF T.EIR NA)E: SELECT # FROM EMP WHERE JOB LI'E G -S 5 TO GET E)PLOYEES +IT. S LETTER IN T.EIR NA)E: SELECT # FROM EMP WHERE ENAME LI'E G -S- G 5 TO GET E)PLOYEES +IT. FOUR LETTERS: SELECT # FROM EMP WHERE ENAME LI'E G(((( 5 TO GET E)PLOYEES +IT. SECOND LETTER 3A4: S"L4 SELECT # FROM EMP WHERE ENAME LI'E C(A(((C5 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 TO GET E)PLOYEES +IT. T.IRD LETTER 3I4: COMM )3 DEPTNO

S"L4 SELECT # FROM EMP WHERE ENAME LI'E C((I((C5 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 COMM 23 DEPTNO

TO GET E)PLOYEES +IT. T.IRD AND FOURT. LETTERS AS 3NE4: S"L4 SELECT # FROM EMP WHERE ENAME LI'E C((NE(C5 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0.// JONES MANAGER 02) 32&APR&21 2 0. COMM 23 DEPTNO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
TO GET EMPLOYEES WITH HIREDATE IN THE YEAR G21% 1# SELECT # FROM EMP WHERE HIREDATE LI'E C-21C S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 02) 'ING PRESIDENT 10&NOV&21 .333 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 13 ROWS SELECTED. TO GET E)PLOYEES +IT. .IREDATE IN T.E )ONT. 3FEB4: SELECT # FROM EMP WHERE HIREDATE LI'E C-FEB-C5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3

10

TO GET E)PLOYEES +IT. .IREDATE 3%3 IN T.EIR DATE: 1# SELECT # FROM EMP WHERE HIREDATE LI'E C-&-C S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 1, ROWS SELECTED. TO GET E)PLOYEES +IT. 3 14 IN LAST IN T.EIR E)PNO: 1# SELECT # FROM EMP WHERE EMPNO LI'E C-2C S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 COMM )3 DEPTNO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 DISTINCT: WE CAN SUPPRESS DUPLICATE ROWS WHILE SELECTING DATA BY USING THE 'EY WORD DISTINCT% SELECT DISTINCT (JOB) FROM EMP5 HERE WE GET JOBS WITHOUT DUPLICATES. S"L4 SELECT JOB FROM EMP5 JOB &&&&&&&&& CLER' SALESMAN SALESMAN MANAGER SALESMAN MANAGER MANAGER ANALYST PRESIDENT SALESMAN CLER' CLER' ANALYST CLER' 1, ;DEF F989:<9=. S"L4 SELECT DISTINCT(JOB) FROM EMP5 JOB &&&&&&&&& ANALYST CLER' MANAGER PRESIDENT SALESMAN CONSTRAINTS: CONSTRAINTS MEAN RESTRICTIONS. IN ORACLE CONSTRAINTS PREVENT INVALID DATA ENTRY INTO TABLES. FOLLOWING ARE THE DIFFERENT TYPES OF CONSTRAINTS%& NOT NULL: IT DOES NOT ALLOW NULL VALUES INTO COLUMNS. NOT NULL. UNI"UE. PRIMARY 'EY. FOREIGN 'EY. CHEC'.

12

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CONSTRAINT AT COLU)N LE*EL: CREATE TABLE EMP ( EMPNO NUMBER ( ) NOT NULL$ ENAME VARCHAR( )) 5 S"L4 CREATE TABLE EMPLOYEE 2 (EMPNO NUMBER(13)$ ) ENAME VARCHAR2(13))5 T6789 :;96<9=. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (1$CPAVANC)5 1 ;DE :;96<9=. 1 INSERT INTO EMPLOYEE 2 VALUES )# (NULL$C'UMARC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO EMPLOYEE 2 VALUES )# ()$NULL) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT # FROM EMPLOYEE5 EMPNO ENAME &&&&&&&&&& &&&&&&&&&& 1 PAVAN 'UMAR ) IN THE ABOVE OUTPUT ONCE EMPNO IS NULL FOR 'UMAR AND ONCE ENAME IS NULL FOR EMPNO ). THIS 'IND FOR DATA WRONG DATA WE HAVE TO STOP WHILE INSERTING DATA IN TO THE TABLE. FOR THIS WE USE NOT NULL CONSTRAINT ON COLUMNS WHERE U WANT STOP NULL VALUES. DROP TABLE EMPLOYEE5 T6789 =;DBB9=. S"L4 CREATE TABLE EMPLOYEE 2 (EMPNO NUMBER(13) NOT NULL$ ) ENAME VARCHAR2(13) NOT NULL)5 T6789 :;96<9=. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (NULL$C'UMARC)5 INSERT INTO EMPLOYEE # ERROR 6< 8NK9 1% ORA&31,33% :6KKD< NKF9;< NULL NK<D (OSCOTTO.OEMPLOYEEO.OEMPNOO) S"L4 INSERT INTO EMPLOYEE

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 VALUES ) ()$NULL)5 INSERT INTO EMPLOYEE # ERROR 6< 8NK9 1% ORA&31,33% :6KKD< NKF9;< NULL NK<D (OSCOTTO.OEMPLOYEEO.OENAMEO)

23

ABOVE WE 'EPT NOT NULL FOR BOTH EMPNO$ENAME AND TRIED TO INSERT NULL VALUES IN TO BOTH COLUMNS BUT IT HAS NOT ACCEPTED. IF YOU WANT TO MA'E ANY COLUMN TO ENTER VALUE FOR THAT COLUMN COMPLUSORY THEN WE HAVE TO 'EEP NOT NULL FOR THAT COLUMN. WE CANNOT 'EEP NOT NULL AT THE TIME OF TABLE CREATION AT TABLE LEVEL. WE CAN ADD CONSTRAINT NOT NULL AFTER CREATION OF TABLE.

UNIQUE: IT DOES NOT ALLOW DUPLICATE VALUES IN COLUMNS.

CONSTRAINT AT COLU)N LE*EL: CREATE TABLE EMP ( EMPNO NUMBER ( ) UNI"UE $ ENAME VARCHAR( )) 5 CONSTRAINT AT TABLE LEVEL% CREATE TABLE EMP EMPNO NUMBER ( ) $ ENAME VARCHAR2( )$ CONSTRAINT EMP(UNI UNI"UE ( EMPNO) 5 S"L4 DROP TABLE EMPLOYEE5 T6789 =;DBB9=. S"L4 CREATE TABLE EMPLOYEE 2 (EMPNO NUMBER(13)$ ) ENAME VARCHAR2(13))5 T6789 :;96<9=. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (1$CPAVANC)5 1 ;DE :;96<9=. 1 INSERT INTO EMPLOYEE 2 VALUES )# (1$CPAVANC)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO EMPLOYEE 2 VALUES )# (2$C'UMARC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO EMPLOYEE 2 VALUES )# ()$C'UMARC) S"L4 / 1 ;DE :;96<9=.

21

1 INSERT INTO EMPLOYEE 2 VALUES )# (1$CPAVANC) S"L4 / 1 ;DE :;96<9=.

1 INSERT INTO EMPLOYEE 2 VALUES )# (1$CPAVANC) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT # FROM EMPLOYEE5 EMPNO ENAME &&&&&&&&&& &&&&&&&&&& 1 PAVAN 1 PAVAN 2 'UMAR ) 'UMAR 1 PAVAN 1 PAVAN / ;DEF F989:<9=. HERE IF YOU WANT SELECT ONLY PAVANCS RECORD WE HAVE TO "UERY LI'E THIS S"L4 SELECT # FROM EMPLOYEE WHERE ENAMEICPAVANC5 EMPNO ENAME &&&&&&&&&& &&&&&&&&&& 1 PAVAN 1 PAVAN 1 PAVAN 1 PAVAN

BUT WE WANT PARTICULAR PAVANCS RECORD. HERE IT IS NOT POSSIBLE. THIS IS WRONG DATA ENTERED IN TO THE TABLE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
FOR DOING THAT WE USE UNI"UE CONSTRAINT. S"L4 DROP TABLE EMPLOYEE5 T6789 =;DBB9=. S"L4 CREATE TABLE EMPLOYEE 2 (EMPNO NUMBER(13) UNI"UE$ ) ENAME VARCHAR2(13))5 T6789 :;96<9=. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (1$CPAVANC)5 1 ;DE :;96<9=. HERE 1 IS ASSIGNED TO PAVAN$ IF FOR ANY EMPLOYEE IF U WANT TO GIVE EMPNO AS 1 IT WONCT ACCEPT. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (1$CPAVANC)5 INSERT INTO EMPLOYEE # ERROR 6< 8NK9 1% ORA&33331% ?KNP?9 :DKF<;6NK< (SCOTT.SYS(C3320.1) QND86<9=

22

IN REAL TIME WE HAVE SAME NAME EMPLOYEES IN AN ORAGANIZATION$ THEN WHAT WE SHOULD DO IS WE GIVE EACH ONE ONE UNI"UE NUMBER THAT IS EMPLOYEE ID. HERE ALSO WE MA'E EMPNO HAS UNI"UE$ THAT IS EMPNO COLUMN SHOLD NOT ALLOW US TO ENTER DUPLICATE VALUES.

HERE IF YOU TRIES TO ASSIGN SAME NUMBER FOR PAVAN THAT IS WRONG BECAUSE WE 'EPT UNI"UE CONSTRAINT ON EMPNO. IT ACCEPTS IF YOU GIVE 2 FOR NE!T PAVAN. 1 INSERT INTO EMPLOYEE 2 VALUES )# (2$CPAVANC) S"L4 / 1 ;DE :;96<9=. HERE UNI"UE CONSTRAINT HAS PROBLEM. THAT IS IT ALLOWS NULL VALUES.

S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (NULL$CPAVANC)5 1 ;DE :;96<9=. S"L4 SELECT # FROM EMPLOYEE5 EMPNO ENAME &&&&&&&&&& &&&&&&&&&& 1 PAVAN 2 PAVAN PAVAN S"L4 THIS IS WRONG WITH UNI"UE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
TO DO ABOVE PROBLEM CORRECTLY WE GO FOR ANOTHER CONSTRAINT CALLED PRIMARY 'EY. WHICH ACTS AS BOTH NOT NULL AND UNI"UE.

2)

PRI)ARY -EY: IT DOES NOT ALLOW EITHER NULL VALUES OR DUPLICATE VALUES IN TO THE COLUMNS ( IT SIMULTANEOUSLY FUNCTIONS BOTH AS M NOT NULL M AND M UNI"UE M ) CONSTRAINT AT COLUMN LEVEL% CREATE TABLE EMP ( EMPNO NUMBER ( ) PRIMARY 'EY$ ENAME VARCHAR2( )) 5 CONSTRAINT AT TABLE LEVEL% CREATE TABLE EMP (EMPNO NUMBER( )$ ENAME VARCHAR2( )$ DEPTNO NUMBER( )$ CONSTRAINT EMP(P' PRIMARY 'EY (EMPNO)) 5 S"L4 DROP TABLE EMPLOYEE5 T6789 =;DBB9=. S"L4 CREATE TABLE EMPLOYEE 2 (EMPNO NUMBER(13) PRIMARY 'EY$ ) ENAME VARCHAR2(13))5 T6789 :;96<9=. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (1$CPAVANC)5 1 ;DE :;96<9=. 1 INSERT INTO EMPLOYEE 2 VALUES )# (1$CPAVANC) S"L4 / INSERT INTO EMPLOYEE # ERROR 6< 8NK9 1% ORA&33331% ?KNP?9 :DKF<;6NK< (SCOTT.SYS(C3320.2) QND86<9= ABOVE IT ACTED AS UNI"UE CONSTRAINT THAT MEANS IT STOPPED DUPLICATE VALUES. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (NULL$CPAVANC)5 INSERT INTO EMPLOYEE # ERROR 6< 8NK9 1% ORA&31,33% :6KKD< NKF9;< NULL NK<D (OSCOTTO.OEMPLOYEEO.OEMPNOO) OUR PROBLEM SLOVED.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
HERE WE CAN GIVE NAME FOR CONSTRAINT$IF YOU DONCT GIVE NAME FOR CONSTRAINT SYSTEM WILL AUTOMATICALLY ASSIGNS A UNI"UE NUMBER CALLED SYS(UNI"UE NUMBER. INSERT INTO EMPLOYEE 2 VALUES ) (1$CPAVANC)5 INSERT INTO EMPLOYEE # ERROR 6< 8NK9 1% ORA&33331% ?KNP?9 :DKF<;6NK< (SCOTT.SYS(C3320.2) QND86<9= S"L4 DROP TABLE EMPLOYEE5 T6789 =;DBB9=. S"L4 CREATE TABLE EMPLOYEE 2 (EMPNO NUMBER(13) CONSTRAINT EMPLOYEE(P' PRIMARY 'EY$ ) ENAME VARCHAR2(13))5 T6789 :;96<9=. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (1$CPAVANC)5 1 ;DE :;96<9=. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (1$CPAVANC)5 INSERT INTO EMPLOYEE # ERROR 6< 8NK9 1% ORA&33331% ?KNP?9 :DKF<;6NK< (SCOTT.EMPLOYEE(P') QND86<9= +E CAN ALSO GI*E PRI)ARY -EY FOR 6 COLU)NS: CREATE TABLE EMP (EMPNO NUMBER( )$ ENAME VARCHAR2( )$ DEPTNO NUMBER( )$ CONSTRAINT EMP(P'1 PRIMARY 'EY (EMPNO$ENAME))5 C.EC- CONSTRAINT: IT IS ALSO CALLED BUSINESS RULE CONSTRAINT. CONSTRAINT AT COLOU)N LE*EL: CREATE TABLE BAN' (ACC(NO NUMBER( )$ NAME VARCHAR2( )$ BALANCE NUMBER( ) CHEC'(BALANCE 4I1333)$ ADDRESS VARCHAR2( ))5 CONSTRAINT AT TABLE LE*EL:

2,

CREATE TABLE BAN' (ACC(NO NUMBER( )$ NAME VARCHAR2( )$ BALANCE NUMBER( )$ ADDRESS VARCHAR2( )$

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CONSTRAINT BAN'(CHE' CHEC'(BALANCE 4I1333))5 S"L4 CREATE TABLE BAN' 2 (ACC(NO NUMBER(13)$ ) BALANCE NUMBER(13))5 T6789 :;96<9=. S"L4 INSERT INTO BAN' 2 VALUES ) (1$1333)5 1 ;DE :;96<9=. 1 INSERT INTO BAN' 2 VALUES )# (2$2333) S"L4 / 1 ;DE :;96<9=.

2.

1 INSERT INTO BAN' 2 VALUES )# ()$.33) S"L4 / 1 ;DE :;96<9=. HERE WE WANT STOP SOME ONE ENTERING BELOW 1333 IN BALANCE COLUMN$ FOR THAT WE 'EEP CHEC' CONSTRAINT ON COLUMN BALANCE. S"L4 DROP TABLE BAN'5 T6789 =;DBB9=. S"L4 CREATE TABLE BAN' 2 (ACC(NO NUMBER(13)$ ) BALANCE NUMBER(13) CHEC'(BALANCE 4 1333))5 T6789 :;96<9=. S"L4 INSERT INTO BAN' 2 VALUES ) (1$1333)5 INSERT INTO BAN' # ERROR 6< 8NK9 1% ORA&322 3% :R9:L :DKF<;6NK< (SCOTT.SYS(C3320.2) QND86<9=

S"L4 INSERT INTO BAN' 2 VALUES ) (2$2333)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 ;DE :;96<9=. S"L4 INSERT INTO BAN' 2 VALUES ) ()$.33)5 INSERT INTO BAN' # ERROR 6< 8NK9 1% ORA&322 3% :R9:L :DKF<;6NK< (SCOTT.SYS(C3320.2) QND86<9= HERE CHEC' CONSTRAINT STOPED US FROM ENTERING BELOW 1333. S"L4 DROP TABLE BAN'5 T6789 =;DBB9=. S"L4 CREATE TABLE BAN' 2 (ACC(NO NUMBER(13)$ ) BALANCE NUMBER(13)$ , CONSTRAINT BAN'(C' CHEC'(BALANCE 4 1333))5 T6789 :;96<9=. S"L4 DROP TABLE BAN'5 T6789 =;DBB9=. S"L4 CREATE TABLE BAN' 2 (ACC(NO NUMBER(13)$ ) BALANCE NUMBER(13))5 T6789 :;96<9=. S"L4 ALTER TABLE BAN' 2 ADD CONSTRAINT BAN'(C' CHEC'(BALANCE 4 1333)5 T6789 68<9;9=. FOREIGN -EY:

2/

FOREIGN 'EY ESTABLISHES RELATIONSHIPS BETWEEN TABLES. A FOREIGN 'EY IS A COLOUMN WHOSE VALUES ARE DERIVED FROM THE PRIMARY 'EY OR UNI"UE 'EY OF SOME OTHER TABLE.

CONSTRAINT AT COLOU)N LE*EL: CREATE TABLE EMP (EMPNO NUMBER( )$ ENAME VARCHAR2( )$ DEPTNO NUMBER( ) REFERENCES DEPT(DEPTNO))5 CONSTRAINT AT TABLE LE*EL: CREATE TABLE EMP (EMPNO NUMBER( )$ ENAME VARCHAR2( )$ DEPTNO NUMBER( )$ CONSTRAINT EMP(F' FOREIGN 'EY(DEPTNO) REFERENCES DEPT(DEPTNO))5 NOTE: T.E DEPTNO OF DEPT TABLE )UST .A*E PRI)ARY -EY OR UNIQUE -EY(

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 CREATE TABLE EMP1 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 CREATE TABLE DEPT1 2 AS ) SELECT # FROM DEPT5 T6789 :;96<9=. S"L4 SELECT # FROM EMP15 EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 1, ;DEF F989:<9=. HERE IF I ENTER IN TO EMP1 EMPLOYEES IN DEPTNO .3$/3$03 LI'E BELOW 1 INSERT INTO EMP1 2 VALUES )# (1$CPAVANC$CMANAGERC$0)/ $C31&DEC&21C$1333$1333$.3) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO EMP1 2 VALUES )# (2$C'UMARC$CMANAGERC$0)/ $C31&DEC&21C$1333$1333$/3) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO EMP1 2 VALUES )# ()$CGAYATRIC$CMANAGERC$0)/ $C31&DEC&21C$1333$1333$03) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT # FROM EMP15 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 DEPTNO 23 )3 )3 23 )3 )3 13 23 13 )3 23 )3 23 13

20

23

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0022 CLAR' 0022 SCOTT 02) 'ING 02,, TURNER 020/ ADAMS 0 33 JAMES 0 32 FORD 0 ), MILLER 1 PAVAN 2 'UMAR ) GAYATRI 10 ;DEF F989:<9=. HERE IF U OBSERVE DEPTNO COLUMN IN EMP1 TABLE$ IF ANY ONE AS'S WHAT IS THE NAME OF DEPARTMENT NUMBER 23$ U WILL "UERY DEPT1 TABLE LI'E THIS MANAGER 02) 3 &JUN&21 2,.3 ANALYST 0.// 1 &APR&20 )333 PRESIDENT 10&NOV&21 .333 SALESMAN 0/ 2 32&SEP&21 1.33 CLER' 0022 2)&MAY&20 1133 CLER' 0/ 2 3)&DEC&21 .3 ANALYST 0.// 3)&DEC&21 )333 CLER' 0022 2)&JAN&22 1)33 MANAGER 0)/ 31&DEC&21 1333 1333 MANAGER 0)/ 31&DEC&21 1333 1333 MANAGER 0)/ 31&DEC&21 1333 1333 13 23 13 3 23 13 .3 /3 03 )3 23 )3

22

S"L4 SELECT # FROM DEPT5 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 ACCOUNTING NEW YOR' 23 RESEARCH DALLAS )3 SALES CHICAGO ,3 OPERATIONS BOSTON AND SAYS RESEARCH IS NAME$ NOW U TELL ME WHAT IS THE NAME OF DEPARTMENT .3. HERE CLEALY U CAN SAY THERE IS NO DEPARTMENT NO .3 E!ISTING IN DEPT1 TABLE. THAT IS WE CANNOT FIND OUT THE DNAME FOR DEPTNO .3. THAT IS THIS IS WRONG INFO U ENTERED IN TO EMP1 TABLE. U HAVE TO STOP THIS BY USING FOREIGN 'EY. THAT IS YOU HAVE TO TELL ORACLE THAT BEFORE ACCEPTING A VALUE IN EMP1 TABLE DEPTNO COLUMNYOU PLEASE 'INDLY SEARCH DEPT1 TABLE DEPTNO COLUMN IF ENTERED NUMBER IS THERE IN DEPTNO COLUMN OF DEPT TABLE U ACCEPT THAT NUMBER TO ENTER IN TO EMP1 TABLE DEPTNO COLUMN OTHERWISE RAISE ERROR. HERE WE AS'ING ORACLE TO REFER DEPT1 TABLE DEPTNO THAT IS WHY DEPT1 TABLE IS PARENT TABLE AND EMP1 IS CHILD TABLE. FOR DOING ABOVE THING WE HAVE TO 'EEP FOREIGN 'EY FOR EMP1 TABLE DEPTNO AND PRIMARY 'EY FOR DEPT1 TABLE DEPTNO COLUMN. FIRST U HAVE TO 'EEP PRIMARY 'EY FOR DEPT1 TABLE DEPTNO AND THEN FOREIGN 'EY FOR EMP TABLEDEPTNO LI'E BELOW. S"L4 ALTER TABLE DEPT1 2 ADD CONSTRAINT DEPT1(P' PRIMARY 'EY(DEPTNO)5 T6789 68<9;9=. S"L4 ALTER TABLE EMP1 2 ADD CONSTRAINT EMP1(F' FOREIGN 'EY(DEPTNO) REFERENCES DEPT1(DEPTNO)5 T6789 68<9;9=. S"L4 INSERT INTO EMP1 2 (EMPNO$DEPTNO) ) VALUES , (1$.3)5 INSERT INTO EMP1 # ERROR 6< 8NK9 1% ORA&322 1% NK<9S;N<A :DKF<;6NK< (SCOTT.EMP1(F') QND86<9= & B6;9K< L9A KD< TD?K=

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 INSERT INTO EMP1 2 (EMPNO$DEPTNO) ) VALUES ,# (1$/3) S"L4 / INSERT INTO EMP1 # ERROR 6< 8NK9 1% ORA&322 1% NK<9S;N<A :DKF<;6NK< (SCOTT.EMP1(F') QND86<9= & B6;9K< L9A KD< TD?K=

HERE IF YOU ENTER OTHER THAN DEPTNO THAT IS E!ISTING IN DEPT TABLE WE GET ERROR.IT WONCT BE ENTERED IN TO EMP1 TABLE. 1 CREATE TABLE EMP1 2 (EMPNO NUMBER(13)$ ) ENAME VARCHAR2(13)$ ,# DEPTNO NUMBER(13) REFERENCES DEPT1(DEPTNO)) S"L4 / T6789 :;96<9=. 1 CREATE TABLE EMP11 2 (EMPNO NUMBER(13)$ ) ENAME VARCHAR2(13)$ , DEPTNO NUMBER(13)$ .# CONSTRAINT EMP2(F' FOREIGN 'EY(DEPTNO) REFERENCES DEPT1(DEPTNO)) S"L4 / T6789 :;96<9=. IF YOU DONT GIVE NAMES TO THE CONSTRAINTS SYSTEM WILL AUTOMATICALLY GIVE NAMES E!% SYS(UNI"UE NUMBER. IT IS ALWAYS GOOD PRACTICE TO GIVE NAMES TO CONSTRAINTS. +E CAN GI*E CONSTRAINTS AFTER T.E CREATION OF T.E TABLE ALSO( UNIQUE: ALTER TABLE EMP ADD CONSTRAINT EMP(U' UNI"UE(EMPNO)5 PRI)ARY -EY: ALTER TABLE EMP ADD CONSTRAINT EMP(P' PRIMARY 'EY(EMPNO)5

FOREIGN -EY: ALTER TABLE EMP ADD CONSTRAINT EMP(F' FOREIGN 'EY(DEPTNO) REFERENCES DEPT(DEPTNO)5 C.EC-: ALTER TABLE BAN' ADD CONSTRAINT BAN'(CH CHEC'(BALANCE 4I1333) 5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
*IE+ING CONSTRAINTS: YOU CAN SEE THE CONSTRAINTS THAT ARE CREATED ON TABLES IN THE ORACLE TABLE CALLED USER(CONSTRAINTS SELECT TABLE(NAME$CONSTRAINT(NAME$CONSTRAINT(TYPE FROM USER(CONSTRAINTS WHERE TABLE(NAMEIEMP5 IF YOU WANT TO SEE COLUMNS ASSOCIATED WITH CONSTRAINTS THEN YOU HAVE TO SEE IN USER(CONS(COLUMNS SELECT TABLE(NAME$CONSTRAINT(NAME$COLUMN(NAME FROM USER(CONS(COLUMNS WHERE TABLE(NAMEIEMP5 S"L4 CREATE TABLE EMPLOYEE 2 (EMPNO NUMBER(13) CONSTRAINT EMPLOYEE(NN NOT NULL$ ) ENAME VARCHAR2(13) CONSTRAINT EMPLOYEE(U' UNI"UE$ , JOB VARCHAR2(13) CONSTRAINT EMPLOYEE(P' PRIMARY 'EY$ . SAL NUMBER(13) CONSTRAINT EMPLOYEE(C' CHEC'(SAL 4 1333)$ / DEPTNO NUMBER(13) CONSTRAINT EMPLOYEE(F' REFERENCES DEPT(DEPTNO))5 T6789 :;96<9=. 1 SELECT CONSTRAINT(NAME$CONSTRAINT(TYPE$TABLE(NAME FROM USER(CONSTRAINTS 2# WHERE TABLE(NAMEICEMPLOYEEC S"L4 / CONSTRAINT(NAME C TABLE(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& & &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPLOYEE(NN C EMPLOYEE EMPLOYEE(C' C EMPLOYEE EMPLOYEE(P' P EMPLOYEE EMPLOYEE(U' U EMPLOYEE EMPLOYEE(F' R EMPLOYEE 1 SELECT CONSTRAINT(NAME$COLUMN(NAME$TABLE(NAME FROM USER(CONS(COLUMNS 2# WHERE TABLE(NAMEICEMPLOYEEC S"L4 / CONSTRAINT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& COLUMN(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TABLE(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPLOYEE(C' SAL EMPLOYEE EMPLOYEE(F' DEPTNO EMPLOYEE EMPLOYEE(NN EMPNO EMPLOYEE EMPLOYEE(P' JOB EMPLOYEE EMPLOYEE(U' ENAME

)3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMPLOYEE +E CAN ENABLE AND DISABLE CONSTRAINTS: ALTER TABLE EMP DISABLE CONSTRAINT EMP(P'5 ALTER TABLE EMP DISABLE CONSTRAINT EMP(U'5 ALTER TABLE EMP DISABLE CONSTRAINT EMP(F'5 ALTER TABLE BAN' DISABLE CONSTRAINT BAN'(CH5

)1

IF YOU ENTER CONSTRAINT AGAINST INFORMATION IN TO THE TABLE THEN YOU HAVE TO DELETE THAT INFORMATION THEN ONLY YOU CAN ENABLE THE CONSTRAINT. ALTER TABLE EMP ENABLE CONSTRAINT EMP(P'5 ALTER TABLE EMP ENABLE CONSTRAINT EMP(U'5 ALTER TABLE EMP ENABLE CONSTRAINT EMP(F'5 ALTER TABLE BAN' ENABLE CONSTRAINT BAN'(CH5 S"L4 CREATE TABLE EMPLOYEE 2 (EMPNO NUMBER(13)$ ) ENAME VARCHAR2(13))5 T6789 :;96<9=. S"L4 ALTER TABLE EMPLOYEE 2 ADD CONSTRAINT EMPLOYEE(P' PRIMARY 'EY(EMPNO)5 T6789 68<9;9=. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (1$CPAVANC)5 1 ;DE :;96<9=. 1 INSERT INTO EMPLOYEE 2 VALUES )# (1$C'UMARC) S"L4 / INSERT INTO EMPLOYEE # ERROR 6< 8NK9 1% ORA&33331% ?KNP?9 :DKF<;6NK< (SCOTT.EMPLOYEE(P') QND86<9= HERE CONSTRAINT STOPED US ENTERING IN TO TABLE 1 AGAIN FOR EMPNO COLUMN FOR 'UMAR. HERE TABLE HAS NOT ACCEPTED 1 AGAIN FOR EMPNO COLUMN WHICH IS ALREADY ASSIGNED TO PAVAN. NOW I WILL DISABLE PRIMARY 'EY.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ALTER TABLE EMPLOYEE DISABLE CONSTRAINT EMPLOYEE(P'5 T6789 68<9;9=. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (1$C'UMARC)5 1 ;DE :;96<9=. 1 INSERT INTO EMPLOYEE 2 VALUES )# (1$CGAYATRIC) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT # FROM EMPLOYEE5 EMPNO ENAME &&&&&&&&&& &&&&&&&&&& 1 PAVAN 1 'UMAR 1 GAYATRI HERE WHEN EVER I DISABLED CONSTRAINT PRIMARY 'EY ON TABLE IT ALLOWED WRONG INFO. HERE IF I WANT TO ENABLE PRIMARY NOW LI'E THIS S"L4 ALTER TABLE EMPLOYEE 2 ENABLE CONSTRAINT EMPLOYEE(P'5 ALTER TABLE EMPLOYEE # ERROR 6< 8NK9 1% ORA&32,)0% :6KKD< Q68N=6<9 (SCOTT.EMPLOYEE(P') & B;N>6;A L9A QND86<9=

)2

HERE WHAT HAPPENED IS THE TABLE CONTAINED WRONG INFO UNLESS YOU DELETE THAT IT WONCT ALLOW YOU TO ENABLE PRIMARY 'EY CONSTRAINT ON TABLE. S"L4 SELECT # FROM EMPLOYEE5 EMPNO ENAME &&&&&&&&&& &&&&&&&&&& 1 PAVAN 1 'UMAR 1 GAYATRI S"L4 DELETE FROM EMPLOYEE 2 WHERE ENAME IN (C'UMARC$CGAYATRIC)5 2 ;DEF =989<9=. S"L4 ALTER TABLE EMPLOYEE 2 ENABLE CONSTRAINT EMPLOYEE(P'5 T6789 68<9;9=. S"L4 SELECT # FROM EMPLOYEE5 EMPNO ENAME &&&&&&&&&& &&&&&&&&&& 1 PAVAN S"L4 INSERT INTO EMPLOYEE 2 VALUES

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) (1$CPAVANC)5 INSERT INTO EMPLOYEE # ERROR 6< 8NK9 1% ORA&33331% ?KNP?9 :DKF<;6NK< (SCOTT.EMPLOYEE(P') QND86<9=

))

DROPING CONSTRAINTS: ALTER TABLE EMP DROP CONSTRAINT EMP(P'5 ALTER TABLE EMP DROP CONSTRAINT EMP(U'5 ALTER TABLE EMP DROP CONSTRAINT EMP(F'5 ALTER TABLE BAN' DROP CONSTRAINT BAN'(CH5 FOREIGN -EY CONSTRAINT DEFINED +IT. ON DELETE CASCADE : GENRALLY IF CHILD TABLE HAS FOREIGN 'EY CONSTRAINT$THEN PARENT TABLE DOES NOT ALLOW US TO DELETE THE ROW. BUT IF F'C IS GIVEN WITH ODC$THEN IF WE DELETE THE ROWS IN PARENT TABLE SIMULTANESOLY RESPECTIVE RECORDS IN THE CHILD TABLE ALSO DELETED. ALTER TABLE EMP ADD CONSTRAINT EMP(F' FOREIGN 'EY( DEPTNO ) REFERENCES DEPT ( DEPTNO ) ON DELETE CASCADE 5 FOREIGN -EY CONSTRAINT DEFINED +IT. ON DELETE SET NULL : GENRALLY IF CHILD TABLE HAS FOREIGN 'EY CONSTRAINT$THEN PARENT TABLE DOES NOT ALLOW US TO DELETE THE ROW. BUT IF F'C IS GIVEN WITH ON DELETE SET NULL$ THEN IF WE DELETE THE ROWS IN PARENT TABLE SIMULTANESOLY RECORDS IN THE CHILD TABLE WILL NOT BE DELETED ONLY RESPECTIVE COLUMN WILL BE 'EPT NULL.

ALTER TABLE EMP ADD CONSTRAINT EMP(F' FOREIGN 'EY (DEPTNO) REFERENCES DEPT (DEPTNO) ON DELETE SET NULL5

S"L4 CREATE TABLE EMP133 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 CREATE TABLE DEPT133 2 AS ) SELECT # FROM DEPT5 T6789 :;96<9=. S"L4 ALTER TABLE DEPT133 2 ADD CONSTRAINT DEPT133(P' PRIMARY 'EY(DEPTNO)5 T6789 68<9;9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 ALTER TABLE EMP133 2 ADD CONSTRAINT EMP133(F' FOREIGN 'EY(DEPTNO) REFERENCES DEPT133(DEPTNO)5 T6789 68<9;9=.

),

NOW IF YOU WANT TO DELETE FROM DEPT133 TABLE IT WONCT ALLOW YOU TO DELETE THE INFO BCOZ WHENEVER YOU WANT TO DELETE FROM TABLE IF IT ACCEPTS THE DELETION THERE ARE SOME PEOPLE WHO ARE WOR'ING IN EMP133 TABLE IN THAT PARTICULAR DEPARTMENT. THEN FOR THOSE EMPLOYEE NO DEPARTMENT NAME.THE WHOLE CONCEPT OF FOREIGN 'EY GOES WRONG.IF YOU WANT TO DELETE ANY INFO FROM DEPT133 TABLE YOU HAVE TO ALTER FOREIGN 'EY ON EMP133 TABLE.

S"L4 ALTER TABLE EMP133 2 DROP CONSTRAINT EMP133(F'5 T6789 68<9;9=. S"L4 ALTER TABLE EMP133 2 ADD CONSTRAINT EMP(F' FOREIGN 'EY(DEPTNO) REFERENCES DEPT133(DEPTNO) ON DELETE CASCADE5 T6789 68<9;9=. NOW IF YOU DELETE 13 IN DEPT133 TABLE THE EMPLOYEES WRO'ING IN DEPARTMENT 13 IN EMP133 TABLE ALSO DELETED THEN THERE IS NO PROBLEM.

S"L4 SELECT # FROM DEPT1335 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 ACCOUNTING NEW YOR' 23 RESEARCH DALLAS )3 SALES CHICAGO ,3 OPERATIONS BOSTON S"L4 DELETE FROM DEPT133 2 WHERE DEPTNOI135 1 ;DE =989<9=. S"L4 SELECT # FROM DEPT1335 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 23 RESEARCH DALLAS )3 SALES CHICAGO ,3 OPERATIONS BOSTON S"L4 SELECT # FROM EMP1335 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 COMM )3 )3 23 )3 )3 23 )3 1133 )3 23 DEPTNO 23

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0 32 FORD 11 ;DEF F989:<9=. 1 ALTER TABLE EMP133 2# DROP CONSTRAINT EMP(F' S"L4 / T6789 68<9;9=. S"L4 ALTER TABLE EMP133 2 ADD CONSTRAINT EMP(F' FOREIGN 'EY(DEPTNO) REFERENCES DEPT133(DEPTNO) ON DELETE SET NULL5 T6789 68<9;9=. S"L4 SELECT # FROM DEPT1335 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 23 RESEARCH DALLAS )3 SALES CHICAGO ,3 OPERATIONS BOSTON S"L4 DELETE FROM DEPT133 2 WHERE DEPTNOI235 1 ;DE =989<9=. S"L4 SELECT # FROM DEPT1335 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& )3 SALES CHICAGO ,3 OPERATIONS BOSTON ANALYST 0.// 3)&DEC&21 )333 23

).

S"L4 SELECT # FROM EMP1335 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 11 ;DEF F989:<9=. HERE ALL THE INFO OF 23 DEPARTMENT WAS NOT DELETED ONLY DEPTNO 23 WAS SET TO NULL. ADDING NOT NULL AFTER CREATION OF T.E TABLE: ALTER TABLE EMP MODIFY EMPNO NUMBER(13) CONSTRAINT EMP(NTN NOT NULL5 COMM DEPTNO )3 )3 )3 )3 )3 )3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DROPING NOT NULL AFTER CREATION OF T.E TABLE: ALTER TABLE EMP MODIFY EMPNO NUMBER(13) CONSTRAINT EMP(NTN NULL5 ADDING COLU)NS AFTER CREATION OF TABLE: ALTER TABLE EMP ADD (ADDRESS VARCHAR2(13)$CITY VARCHAR2(13))5 S"L4 CREATE TABLE EMP1 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 DESC EMP1 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,) ENAME VARCHAR2(13) JOB VARCHAR2( ) MGR NUMBER(,) HIREDATE DATE SAL NUMBER(0$2) COMM NUMBER(0$2) DEPTNO NUMBER(2) S"L4 ALTER TABLE EMP1 2 ADD ADDRESS VARCHAR2(13)5 T6789 68<9;9=.

)/

S"L4 DESC EMP1 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,) ENAME VARCHAR2(13) JOB VARCHAR2( ) MGR NUMBER(,) HIREDATE DATE SAL NUMBER(0$2) COMM NUMBER(0$2) DEPTNO NUMBER(2) ADDRESS VARCHAR2(13) S"L4 ALTER TABLE EMP1 2 ADD (ADDRESS1 VARCHAR2(13)$ ADDRESS2 VARCHAR2(13))5 T6789 68<9;9=. S"L4 DESC EMP1 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,) ENAME VARCHAR2(13) JOB VARCHAR2( ) MGR NUMBER(,) HIREDATE DATE SAL NUMBER(0$2) COMM NUMBER(0$2) DEPTNO NUMBER(2) ADDRESS VARCHAR2(13) ADDRESS1 VARCHAR2(13)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ADDRESS2 VARCHAR2(13) )ODIFYING DATATYPES OF COLU)NS: ALTER TABLE EMP MODIFY EMPNO NUMBER()3)5 WE CANNOT DECREASE DATATYPE OF COLUMNS IF DATA E!SITS. ALTER TABLE EMP MODIFY EMPNO NUMBER(1)5 S"L4 ALTER TABLE EMP1 2 MODIFY EMPNO NUMBER(23)5 T6789 68<9;9=. S"L4 DESC EMP1 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(23) ENAME VARCHAR2(13) JOB VARCHAR2( ) MGR NUMBER(,) HIREDATE DATE SAL NUMBER(0$2) COMM NUMBER(0$2) DEPTNO NUMBER(2) 1 ALTER TABLE EMP1 2# MODIFY EMPNO NUMBER(,) S"L4 / MODIFY EMPNO NUMBER(,) # ERROR 6< 8NK9 2% ORA&31,,3% :D8?>K <D 79 >D=NTN9= >?F< 79 9>B<A <D =9:;96F9 B;9:NFNDK D; F:689

)0

DROPING COLU)NS: S"L4 ALTER TABLE EMP1 2 DROP COLUMN ADDRESS5 T6789 68<9;9=. S"L4 ALTER TABLE EMP1 2 DROP COLUMN ADDRESS15 T6789 68<9;9=. S"L4 ALTER TABLE EMP1 2 DROP COLUMN ADDRESS25 T6789 68<9;9=. S"L4 DESC EMP1 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,) ENAME VARCHAR2(13) JOB VARCHAR2( ) MGR NUMBER(,) HIREDATE DATE SAL NUMBER(0$2)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
COMM DEPTNO GROUP FUNCTIONS: SELECT MA!(SAL)$ MIN(SAL)$AVG(SAL)$SUM(SAL)$STDDEV(SAL)$VARIANCE(SAL) FROM EMP5 SELECT COUNT ( # ) FROM EMP5SELECT COUNT ( DISTINCT DEPTNO ) FROM EMP5 DUAL TABLE: DUAL IS A SYTEM TABLE. WHICH WILL HAVE ONE COLUMN AND ONE ROW. SELECT # FROM DUAL5 SELECT SYSDATE FROM DUAL5 SELECT 23#23 FROM DUAL5 SELECT USER FROM DUAL5 SELECT USERID FROM DUAL5 NUMBER(0$2) NUMBER(2)

)2

1# SELECT MA!(SAL)$ MIN(SAL)$ AVG(SAL) $ SUM(SAL) FROM EMP S"L4 / MA!(SAL) MIN(SAL) AVG(SAL) SUM(SAL) &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& .333 233 230).21,2 2 32. S"L4 SELECT JOB FROM EMP5 JOB &&&&&&&&& CLER' SALESMAN SALESMAN MANAGER SALESMAN MANAGER MANAGER ANALYST PRESIDENT SALESMAN CLER' CLER' ANALYST CLER' 1, ;DEF F989:<9=. S"L4 SELECT DISTINCT(JOB) FROM EMP5 JOB &&&&&&&&& ANALYST CLER' MANAGER PRESIDENT SALESMAN S"L4 SELECT COUNT(#) FROM EMP5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
COUNT(#) &&&&&&&&&& 1, S"L4 SELECT COUNT(DISTINCT(JOB)) FROM EMP5 COUNT(DISTINCT(JOB)) &&&&&&&&&&&&&&&&&&&& .

S"L4 SELECT SYSDATE FROM DUAL5 SYSDATE &&&&&&&&& 1 &JUL&3. S"L4 SELECT SYSTIMESTAMP FROM DUAL5 SYSTIMESTAMP &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 1 &JUL&3. 12.32.11.333331 AM J3.%)3 S"L4 SELECT USER FROM DUAL5 USER &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& SCOTT S"L4 SELECT UID FROM DUAL5 UID &&&&&&&&&& // S"L4 SELECT # FROM DUAL5 D & ! S"L4 DESC DUAL5 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DUMMY VARCHAR2(1) DUAL IS A SYSTEM TABLE. S"L4 SELECT 2)# 2) FROM DUAL5 2)#2) &&&&&&&&&& .2 S"L4 SELECT 2#2 FROM DUAL5 2#2 &&&&&&&&&& ,

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
GROUP FUNCTIONS: AVG $ MA! $ MIN $ SUM $ COUNT $ STDDEV( STANDERD DEVIATION ) $ VARIANCE . COLU)N .EADING DEFAULTS IN SQL* PLUS: DEFAULT JUSTIFICATION% &&&&LEFT % DATE AND CHARACTER DATA

,3

&&&&RIGHT % NUMERIC DATA. DEFAULT DISPLAY %UPPERCASE

ARIT.)ETIC E/PRESSIONS: J && # / ADD SUBTRACT MULTIPLY DIVIDE

SELECT ENAME$SAL$SALJ)33$SAL&)33$SAL#)33$SAL/)33 FROM EMP5 S"L4 SELECT SAL$SALJ)33$SAL&)33$SAL#)33$SAL/)33 FROM EMP5 SAL SALJ)33 SAL&)33 SAL#)33 SAL/)33 &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 233 1133 .33 2,3333 2.///////0 1/33 1 33 1)33 ,23333 ..)))))))) 12.3 1..3 .3 )0.333 ,.1//////0 2 0. )20. 2/0. 2 2.33 . 1/////0 12.3 1..3 .3 )0.333 ,.1//////0 22.3 )1.3 2..3 2..333 .. 2,.3 20.3 21.3 0).333 2.1//////0 )333 ))33 2033 33333 13 .333 .)33 ,033 1.33333 1/.//////0 1.33 1233 1233 ,.3333 . 1133 1,33 233 ))3333 ).///////0 .3 12.3 /.3 22.333 ).1//////0 )333 ))33 2033 33333 13 1)33 1/33 1333 ) 3333 ,.)))))))) 1, ;DEF F989:<9=.

OPERATOR PRECEDENCE: # / J &

MULTIPLICATION AND DIVISION TA'E PRIORITY OVER ADDITION AND SUBTRACTION. OPERATORS OF THE SAME PRIORITY ARE EVALUATED FROM LEFT TO RIGHT. PARENTHESESES ARE USED TO FORCE PRIORITIZED EVALUTION. NULL FUNCTION: A NULL IS A VALUE THIS IS UNAVAILABLE$UNASSIGNED$UN'NOWN OR INAPPLICABLE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
A NULL IS NOT THE SAME AS ZERO OR A BLAN'SPACE. ARITHMETIC E!PRESSIONS CONTAINING A NULL VALUE EVALUATE TO NULL5 S"L4 SELECT # FROM EMP WHERE MGR IS NULL5 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 02) 'ING PRESIDENT 10&NOV&21 .333 COMM 13 DEPTNO

,1

1# SELECT # FROM EMP WHERE MGR IS NOT NULL S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 1) ;DEF F989:<9=. DEPTNO 23 )3 )3 23 )3 )3 13 23 )3 23 )3 23 13

ANNAUAL SALARY: .ERE 76 IS FIRST )ULTIPLIED BY 788 T.EN IT IS ADDED TO SAL T.AT IS +RONG( S"L4 SELECT SAL$SALJ133 #12 FROM EMP5 SAL SALJ133#12 &&&&&&&&&& &&&&&&&&&& 233 2333 1/33 2233 12.3 2,.3 2 0. ,10. 12.3 2,.3 22.3 ,3.3 2,.3 )/.3 )333 ,233 .333 /233 1.33 2033 1133 2)33 .3 21.3 )333 ,233 1)33 2.33 1, ;DEF F989:<9=. HERE BY PUTTING PARANTHESIS THAT OUT IS CORRECT. 1# SELECT SAL$(SALJ133) #12 FROM EMP

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 / SAL (SALJ133)#12 &&&&&&&&&& &&&&&&&&&&&& 233 13233 1/33 23,33 12.3 1/233 2 0. )/ 33 12.3 1/233 22.3 ).,33 2,.3 )3/33 )333 )0233 .333 /1233 1.33 1 233 1133 1,,33 .3 12/33 )333 )0233 1)33 1/233 1, ;DEF F989:<9=.

,2

S"L4 SELECT ENAME$SAL$SALJCOMM FROM EMP5 ENAME SAL SALJCOMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& SMITH 233 ALLEN 1/33 1 33 WARD 12.3 10.3 JONES 2 0. MARTIN 12.3 2/.3 BLA'E 22.3 CLAR' 2,.3 SCOTT )333 'ING .333 TURNER 1.33 1.33 ADAMS 1133 JAMES .3 FORD )333 MILLER 1)33 1, ;DEF F989:<9=. HERE THE SAL J COMM IS NULL FOR THE EMPLOYEES WHO HAS COMM IS NULL. THAT MEANS WHEN EVER WE DO ANY ADDITION WITH NULL WHOLE RESULT IS NULL. TO AVOID THAT WE USE NULL. S"L4 SELECT ENAME$SAL$COMM$SALJCOMM FROM EMP5 ENAME SAL COMM SALJCOMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& SMITH 233 ALLEN 1/33 )33 1 33 WARD 12.3 .33 10.3 JONES 2 0. MARTIN 12.3 1,33 2/.3 BLA'E 22.3 CLAR' 2,.3 SCOTT )333 'ING .333 TURNER 1.33 3 1.33 ADAMS 1133 JAMES .3 FORD )333

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
MILLER 1)33 1, ;DEF F989:<9=. HERE WHENEVER WE USED NVL IT SUBSTITUED G3 IN PLACE OF NULL VALUES. THEN ADDTION WITH 3 RESULTS CORRECT VALUE. S"L4 SELECT ENAME$SAL$NVL(COMM$3)$SALJNVL(COMM$3) FROM EMP5 ENAME SAL NVL(COMM$3) SALJNVL(COMM$3) &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&& &&&&&&&&&&&&&&& SMITH 233 3 233 ALLEN 1/33 )33 1 33 WARD 12.3 .33 10.3 JONES 2 0. 3 2 0. MARTIN 12.3 1,33 2/.3 BLA'E 22.3 3 22.3 CLAR' 2,.3 3 2,.3 SCOTT )333 3 )333 'ING .333 3 .333 TURNER 1.33 3 1.33 ADAMS 1133 3 1133 JAMES .3 3 .3 FORD )333 3 )333 MILLER 1)33 3 1)33 1, ;DEF F989:<9=.

,)

HERE BECAUSE OF ORDER OF PRECEDENCE THE CONCEPT OF ANNUAL SALARY WAS CAME WRONG. HERE FIRST 12 IS MULTIPLIED BY COMM THAT IS WHY FOR FIRST RWO THE ANNUAL SALARY IS 233 ONLY. 1# SELECT ENAME$SAL$NVL(COMM$3)$SALJNVL(COMM$3)#12 FROM EMP S"L4 / ENAME SAL NVL(COMM$3) SALJNVL(COMM$3)#12 &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&& &&&&&&&&&&&&&&&&&& SMITH 233 3 233 ALLEN 1/33 )33 .233 WARD 12.3 .33 02.3 JONES 2 0. 3 2 0. MARTIN 12.3 1,33 123.3 BLA'E 22.3 3 22.3 CLAR' 2,.3 3 2,.3 SCOTT )333 3 )333 'ING .333 3 .333 TURNER 1.33 3 1.33 ADAMS 1133 3 1133 JAMES .3 3 .3 FORD )333 3 )333 MILLER 1)33 3 1)33 1, ;DEF F989:<9=. WE HAVE TO 'EEP PARANTHESIS FOR CORRECT ANNUAL SALARY.

1# SELECT ENAME$SAL$NVL(COMM$3)$(SALJNVL(COMM$3))#12 FROM EMP S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ENAME SAL NVL(COMM$3) (SALJNVL(COMM$3))#12 &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&& &&&&&&&&&&&&&&&&&&&& SMITH 233 3 /33 ALLEN 1/33 )33 22233 WARD 12.3 .33 21333 JONES 2 0. 3 ).033 MARTIN 12.3 1,33 )1233 BLA'E 22.3 3 ),233 CLAR' 2,.3 3 2 ,33 SCOTT )333 3 )/333 'ING .333 3 /3333 TURNER 1.33 3 12333 ADAMS 1133 3 1)233 JAMES .3 3 11,33 FORD )333 3 )/333 MILLER 1)33 3 1./33 1, ;DEF F989:<9=.

,,

IN THE ABOVE OUTPUT THE HEADING FOR ANNUAL SALARY COLUMN IS NOT MEANING FULL.TO ACHIVE COEERCT OUTPUT WE GO FOR COLUMN ALIASING. COLUMN ALIASES% SELECT ENAME AS NAME $SAL SALARY FROM EMP5 SELECT ENAME MNAMEH$ SAL#12 MANNUAL SALARYH FROM EMP5 SELECT ENAME NAME FROM EMP5 1# SELECT ENAME$SAL$NVL(COMM$3)$(SALJNVL(COMM$3))#12 OANNUAL SALARYO FROM EMP S"L4 / ENAME SAL NVL(COMM$3) ANNUAL SALARY &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&& &&&&&&&&&&&&& SMITH 233 3 /33 ALLEN 1/33 )33 22233 WARD 12.3 .33 21333 JONES 2 0. 3 MARTIN 12.3 1,33 )1233 BLA'E 22.3 3 CLAR' 2,.3 3 SCOTT )333 3 'ING .333 3 TURNER 1.33 3 12333 ADAMS 1133 3 JAMES .3 3 11,33 FORD )333 3 MILLER 1)33 3 1, ;DEF F989:<9=. S"L4 SELECT ENAME$SAL AS SALARY FROM EMP5 ENAME SALARY &&&&&&&&&& &&&&&&&&&& SMITH 233 ALLEN 1/33 WARD 12.3 JONES 2 0. MARTIN 12.3 BLA'E 22.3 CLAR' 2,.3 SCOTT )333 'ING .333 TURNER 1.33 ADAMS 1133 JAMES .3

).033 ),233 2 ,33 )/333 /3333 1)233 )/333 1./33

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
FORD MILLER 1, ;DEF F989:<9=. S"L4 SELECT ENAME$SAL SALARY FROM EMP5 ENAME SALARY &&&&&&&&&& &&&&&&&&&& SMITH 233 ALLEN 1/33 WARD 12.3 JONES 2 0. MARTIN 12.3 BLA'E 22.3 CLAR' 2,.3 SCOTT )333 'ING .333 TURNER 1.33 ADAMS 1133 JAMES .3 FORD )333 MILLER 1)33 1, ;DEF F989:<9=. HERE WE HAD GIVEN GAP FOR COLUMN ALIASING. THAT IS WRONG. FOR CORRECT OUTPUT WE HAVE TO GIVE M M FOR COLUMN ALIASING. S"L4 SELECT ENAME$SAL SALARY OF EMPLOYEE FROM EMP5 SELECT ENAME$SAL SALARY OF EMPLOYEE FROM EMP # ERROR 6< 8NK9 1% ORA&33 2)% FROM L9AED;= KD< TD?K= ER9;9 9UB9:<9= )333 1)33

,.

1# SELECT ENAME$SAL OSALARY OF EMPLOYEEO FROM EMP S"L4 / ENAME SALARY OF EMPLOYEE &&&&&&&&&& &&&&&&&&&&&&&&&&&& SMITH 233 ALLEN 1/33 WARD 12.3 JONES 2 0. MARTIN 12.3 BLA'E 22.3 CLAR' 2,.3 SCOTT )333 'ING .333 TURNER 1.33 ADAMS 1133 JAMES .3 FORD )333 MILLER 1)33 1, ;DEF F989:<9=. CONCATINATION OPERATOR: SELECT ENAMEVVJOB AS MEMPLOYEESH FROM EMP5 SELECT ENAME VV GIS A VV JOB AS MEMPLOYEE DETAILSH FROM EMP5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT ENAME$JOB FROM EMP5 ENAME JOB &&&&&&&&&& &&&&&&&&& SMITH CLER' ALLEN SALESMAN WARD SALESMAN JONES MANAGER MARTIN SALESMAN BLA'E MANAGER CLAR' MANAGER SCOTT ANALYST 'ING PRESIDENT TURNER SALESMAN ADAMS CLER' JAMES CLER' FORD ANALYST MILLER CLER' 1, ;DEF F989:<9=.

,/

S"L4 SELECT ENAMEVVJOB FROM EMP5 ENAMEVVJOB &&&&&&&&&&&&&&&&&&& SMITHCLER' ALLENSALESMAN WARDSALESMAN JONESMANAGER MARTINSALESMAN BLA'EMANAGER CLAR'MANAGER SCOTTANALYST 'INGPRESIDENT TURNERSALESMAN ADAMSCLER' JAMESCLER' FORDANALYST MILLERCLER' 1, ;DEF F989:<9=. 1# SELECT ENAMEVVC HAS A CVVJOB FROM EMP S"L4 / ENAMEVVCHASACVVJOB &&&&&&&&&&&&&&&&&&&&&&&&&& SMITH HAS A CLER' ALLEN HAS A SALESMAN WARD HAS A SALESMAN JONES HAS A MANAGER MARTIN HAS A SALESMAN BLA'E HAS A MANAGER CLAR' HAS A MANAGER SCOTT HAS A ANALYST 'ING HAS A PRESIDENT TURNER HAS A SALESMAN ADAMS HAS A CLER' JAMES HAS A CLER' FORD HAS A ANALYST MILLER HAS A CLER' 1, ;DEF F989:<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1# SELECT ENAMEVVC JOB NAME IS CVVJOB FROM EMP S"L4 / ENAMEVVCJOBNAMEISCVVJOB &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& SMITH JOB NAME IS CLER' ALLEN JOB NAME IS SALESMAN WARD JOB NAME IS SALESMAN JONES JOB NAME IS MANAGER MARTIN JOB NAME IS SALESMAN BLA'E JOB NAME IS MANAGER CLAR' JOB NAME IS MANAGER SCOTT JOB NAME IS ANALYST 'ING JOB NAME IS PRESIDENT TURNER JOB NAME IS SALESMAN ADAMS JOB NAME IS CLER' JAMES JOB NAME IS CLER' FORD JOB NAME IS ANALYST MILLER JOB NAME IS CLER' 1, ;DEF F989:<9=. CO)PARISON OPERATORS: I 4 4I W WI W4 E"UAL TO GREATER THAN GREATER THAN OR E"UAL TO LESS THAN LESS THAN OR E"UAL TO NOT E"UAL TO

,0

SELECT # FROM EMP WHERE SALWI23335 SELECT # FROM EMP WHERE SAL4I23335 SELECT # FROM EMP WHERE SAL W4 23335 SELECT ENAME$SAL FROM EMP WHERE SAL BETWEEN 1333 AND 1.335 S"L4 SELECT # FROM EMP WHERE SAL W 13335 EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 1# SELECT # FROM EMP WHERE SAL WI 1333 2 / EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 DEPTNO 23 )3 DEPTNO 23 )3

1# SELECT # FROM EMP WHERE SAL 4 1333 S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 12 ;DEF F989:<9=. 1# SELECT # FROM EMP WHERE SAL 4I 1333 S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 12 ;DEF F989:<9=. 1# SELECT # FROM EMP WHERE SAL W4 1333 S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 1, ;DEF F989:<9=. 1# SELECT # FROM EMP WHERE SAL I .3 S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& COMM DEPTNO )3 )3 )3 )3 13 23

,2

)3 )3 )3 )3 13 23

)3 )3 )3 )3 13 23

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 S"L4 SELECT # FROM EMP WHERE SAL BETWEEN 1333 AND 23335 EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 / ;DEF F989:<9=. HERE BOTH 1333 AND 2333 INCLUSIVE IN THE OUTPUT IF THEY E!IST IN THE OUPUT. DEPTNO )3 )3 )3 )3 23 13

IN OPERATOR: IF YOU WANT TO SELECT INFO FOR MORE THAN ONE EMPLOYEE YOU CANNOT USE THE FOLLOWING "UERY%

SELECT # FROM EMP WHERE EMPNOI0)/ $0022$0.//5 THE ABOVE "UERY WONT WOR'. TO SLOVE THE ABOVE PROBLEM WE HAVE TO WRITE "UERY LI'E BELOW% SELECT EMPNO$ENAME$SAL$MGR FROM EMP WHERE MGR IN (0 32$0.//$0022)5 THE ABOVE "UERY WILL GIVE THE INFO OF THREE EMPLOYEES.

S"L4 SELECT # FROM EMP WHERE EMPNOI00225 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 COMM 23 DEPTNO

1# SELECT # FROM EMP WHERE EMPNOI0022$0)/ $0.// 2 / SELECT # FROM EMP WHERE EMPNOI0022$0)/ $0.// # ERROR 6< 8NK9 1% ORA&33 ))% S"L :D>>6K= KD< B;DB9;8A 9K=9= 1# SELECT # FROM EMP WHERE EMPNO IN (0022$0)/ $0.//) 2 / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 NOT IN OPERATOR: IF YOU DONT WANT TO SEE THOSE EMPLOYEES INFO$YOU 'EEP THEM IN NOT IN CLAUSE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECT EMPNO$ENAME$SAL$MGR FROM EMP WHERE MGR NOT IN (0 32$0.//$0022)5 1# SELECT # FROM EMP WHERE EMPNO NOT IN (0022$0)/ $0.//) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 11 ;DEF F989:<9=. DEPTNO )3 )3 )3 )3 13 13 3 23 )3 23 13 )3

.3

AND OPERATOR: RE"UIRES BOTH CONDITIONS TO BE TRUE% IN ADD OPERATOR IF BOTH CONDITIONS ARE TRUE THEN ONLY RESULT COMES. HERE WE GET INFO ABOUT CLER'S AND WHOSE SALARY 4ITHAN 11335 SELECT EMPNO$ENAME$JOB$SAL FROM EMP WHERE SAL41133 AND JOBICLER'5 S"L4 SELECT # FROM EMP 2 WHERE SAL 4 1333 AND JOB I CCLER'C5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 AND TRUE FALSE OR OPERATOR% RE"UIRES EITHER CONDITION TO BE TRUE. IN OR OPERATOR IF ONE CONDITION IS TRUE THEN ALSO RESULT COMES. HERE WE GET INFO ABOUT CLER'S AND ALL THE INFO ABOUT EMPLOYEES WHOSE SALARY 4I1133. SELECT EMPNO$ENAME$JOB$SAL FROM EMP WHERE SAL4I1133 OR JOBICLER'5 1 SELECT # FROM EMP 2# WHERE SAL 4 1333 OR JOB I CCLER'C ) / EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 DEPTNO 23 )3 )3 23 )3 TRUE TRUE FALSE FALSE FALSE FALSE

23

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0/ 2 BLA'E 0022 CLAR' 0022 SCOTT 02) 'ING 02,, TURNER 020/ ADAMS 0 33 JAMES 0 32 FORD 0 ), MILLER 1, ;DEF F989:<9=. OR TRUE FALSE MANAGER 02) 31&MAY&21 22.3 MANAGER 02) 3 &JUN&21 2,.3 ANALYST 0.// 1 &APR&20 )333 PRESIDENT 10&NOV&21 .333 SALESMAN 0/ 2 32&SEP&21 CLER' 0022 2)&MAY&20 1133 CLER' 0/ 2 3)&DEC&21 .3 ANALYST 0.// 3)&DEC&21 )333 CLER' 0022 2)&JAN&22 1)33 TRUE TRUE TRUE FALSE TRUE FALSE )3 13 23 13 1.33 3 23 )3 23 13 )3

.1

SORTING BY COLU)N ALIAS: TILL NOW WE HAVE SORTED OUTPUT ASC OR DESC ACCORDING TO COLUMN THAT ARE PRESENT IN THE TABLE. NOW WE CAN SORT THE OUTPUT IN EITHER WAY ACCORDING TO COLUMN ALIASES. SELECT EMPNO$ENAME$SAL#12 ANNSAL FROM EMP ORDER BY ANNSAL5 S"L4 SELECT EMPNO$ENAME$JOB$SAL$(SALJNVL(COMM$3)#12) ANSAL FROM EMP5 EMPNO ENAME JOB SAL ANSAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 233 233 0, ALLEN SALESMAN 1/33 .233 0.21 WARD SALESMAN 12.3 02.3 0.// JONES MANAGER 2 0. 2 0. 0/., MARTIN SALESMAN 12.3 123.3 0/ 2 BLA'E MANAGER 22.3 22.3 0022 CLAR' MANAGER 2,.3 2,.3 0022 SCOTT ANALYST )333 )333 02) 'ING PRESIDENT .333 .333 02,, TURNER SALESMAN 1.33 020/ ADAMS CLER' 1133 1133 0 33 JAMES CLER' .3 .3 0 32 FORD ANALYST )333 )333 0 ), MILLER CLER' 1)33 1)33 1, ;DEF F989:<9=. 1# SELECT EMPNO$ENAME$JOB$SAL$(SALJNVL(COMM$3)#12) ANSAL FROM EMP ORDER BY ANSAL S"L4 / EMPNO ENAME JOB SAL ANSAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 233 233 0 33 JAMES CLER' .3 .3 020/ ADAMS CLER' 1133 1133 0 ), MILLER CLER' 1)33 1)33 02,, TURNER SALESMAN 1.33 1.33 0022 CLAR' MANAGER 2,.3 2,.3 0/ 2 BLA'E MANAGER 22.3 22.3 0.// JONES MANAGER 2 0. 2 0. 0022 SCOTT ANALYST )333 )333 0 32 FORD ANALYST )333 )333 02) 'ING PRESIDENT .333 .333 0, ALLEN SALESMAN 1/33 .233 0.21 WARD SALESMAN 12.3 02.3

1.33

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0/., MARTIN 1, ;DEF F989:<9=. 1# SELECT EMPNO$ENAME$JOB$SAL$(SALJNVL(COMM$3)#12) ANSAL FROM EMP ORDER BY ANSAL DESC S"L4 / EMPNO ENAME JOB SAL ANSAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0/., MARTIN SALESMAN 12.3 123.3 0.21 WARD SALESMAN 12.3 02.3 0, ALLEN SALESMAN 1/33 .233 02) 'ING PRESIDENT .333 .333 0022 SCOTT ANALYST )333 0 32 FORD ANALYST )333 0.// JONES MANAGER 2 0. 2 0. 0/ 2 BLA'E MANAGER 22.3 22.3 0022 CLAR' MANAGER 2,.3 2,.3 02,, TURNER SALESMAN 1.33 0 ), MILLER CLER' 1)33 020/ ADAMS CLER' 1133 0 33 JAMES CLER' .3 0)/ SMITH CLER' 233 1, ;DEF F989:<9=. +.EN E*ER IN INTER*IE+ +.EN T.EY AS- ABOUT JOINS U .A*E TO E/PLAIN ANS+ER +IT. E)P"DEPT"SALGRADE TABLES( IT IS *ERY DIFFICULT IF YOU TRY TO ANS+ER +IT. OT.ER TABLES( SALESMAN 12.3 123.3

.2

)333 )333

1.33 1)33 1133 .3 233

JOINS: USE A JOIN TO "UERY DATA FROM MORE THAN ONE TABLE.WRITE THE JOIN CONDITION IN THE WHERE CLAUSE.PREFI! THE COLUMN NAME WITH THE TABLE NAME WHEN THE SAME COLUMN NAME APPEARS IN MORE THAN ONE TABLE. THERE ARE FIVE TYPES OF JOINS E!ISTS IN ORACLE. CARTESIAN PRODUCT EQUI%JOIN NON%EQUI JOIN OUTER%JOIN( SELF%JOIN(

CARTESIAN PRODUCT:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
HERE FIRST TABLE EMP ROWS COMPLETELY MULTIPLIED BY FIRST ROW IN SECOND TABLE DEPT AND SO ON S"L4 SELECT EMPNO$ENAME$EMP.DEPTNO$DNAME$LOC FROM EMP$DEPT5 EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 ACCOUNTING NEW YOR' 0, ALLEN )3 ACCOUNTING NEW YOR' 0.21 WARD )3 ACCOUNTING NEW YOR' 0.// JONES 23 ACCOUNTING NEW YOR' 0/., MARTIN )3 ACCOUNTING NEW YOR' 0/ 2 BLA'E )3 ACCOUNTING NEW YOR' 0022 CLAR' 13 ACCOUNTING NEW YOR' 0022 SCOTT 23 ACCOUNTING NEW YOR' 02) 'ING 13 ACCOUNTING NEW YOR' 02,, TURNER )3 ACCOUNTING NEW YOR' 020/ ADAMS 23 ACCOUNTING NEW YOR' 0 33 JAMES )3 ACCOUNTING NEW YOR' 0 32 FORD 23 ACCOUNTING NEW YOR' 0 ), MILLER 13 ACCOUNTING NEW YOR' 0)/ SMITH 23 RESEARCH DALLAS 0, ALLEN )3 RESEARCH DALLAS 0.21 WARD )3 RESEARCH DALLAS 0.// JONES 23 RESEARCH DALLAS 0/., MARTIN )3 RESEARCH DALLAS 0/ 2 BLA'E )3 RESEARCH DALLAS 0022 CLAR' 13 RESEARCH DALLAS 0022 SCOTT 23 RESEARCH DALLAS 02) 'ING 13 RESEARCH DALLAS 02,, TURNER )3 RESEARCH DALLAS 020/ ADAMS 23 RESEARCH DALLAS 0 33 JAMES )3 RESEARCH DALLAS 0 32 FORD 23 RESEARCH DALLAS EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0 ), MILLER 13 RESEARCH DALLAS 0)/ SMITH 23 SALES CHICAGO 0, ALLEN )3 SALES CHICAGO 0.21 WARD )3 SALES CHICAGO 0.// JONES 23 SALES CHICAGO 0/., MARTIN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0022 CLAR' 13 SALES CHICAGO 0022 SCOTT 23 SALES CHICAGO 02) 'ING 13 SALES CHICAGO 02,, TURNER )3 SALES CHICAGO 020/ ADAMS 23 SALES CHICAGO 0 33 JAMES )3 SALES CHICAGO 0 32 FORD 23 SALES CHICAGO 0 ), MILLER 13 SALES CHICAGO 0)/ SMITH 23 OPERATIONS BOSTON 0, ALLEN )3 OPERATIONS BOSTON 0.21 WARD )3 OPERATIONS BOSTON 0.// JONES 23 OPERATIONS BOSTON 0/., MARTIN )3 OPERATIONS BOSTON 0/ 2 BLA'E )3 OPERATIONS BOSTON 0022 CLAR' 13 OPERATIONS BOSTON 0022 SCOTT 23 OPERATIONS BOSTON 02) 'ING 13 OPERATIONS BOSTON 02,, TURNER )3 OPERATIONS BOSTON 020/ ADAMS 23 OPERATIONS BOSTON 0 33 JAMES )3 OPERATIONS BOSTON EMPNO ENAME DEPTNO DNAME LOC

.)

CARTESIAN PRODUCT IS FORMED WHEN A JOIN CONDITION IS OMITTED.TO AVOID A CARTESIAN PRODUCT$ ALWAYS INCLUDE A VALID CONDITION IN A WHERE CLAUSE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0 32 FORD 23 OPERATIONS BOSTON 0 ), MILLER 13 OPERATIONS BOSTON ./ ;DEF F989:<9=. HERE WE GET NO OF ROWS IN FIRST TABLE # NO OF ROWS IN SECOND TABLE AS OUTPUT. WHEN EVER IN INTERVIEW IF THEY AS' ABOUT E!PLAIN OUTPUT U HAVE TO E!PLAIN LI'E THIS%

.,

HERE FIRST TABLE WHOLE ROWS ARE MULTIPLIED BY FIRST ROW N SECOND ROW AND AGAIN FIRST TABLE WHOLE ROWS ARE THEN MULTIPLIED BY SECOND TABLE SECOND ROW AND SO ON. EQUI%JOIN:SI)PLE JOINS OR INNER JOINS: THE RELATIONSHIP BETWEEN EMP AND DEPT TABLE IS A E"UI&JOIN.THAT IS VALUES IN DEPTNO COLUMN ON BOTH TABLES ARE E"UAL. HERE WE GET INFO THAT IS COMMON IN BOTH TABLES. S"L4 SELECT EMPNO$ENAME$DEPTNO$DNAME$LOC FROM EMP$DEPT 2 WHERE EMP.DEPTNOIDEPT.DEPTNO5 SELECT EMPNO$ENAME$DEPTNO$DNAME$LOC FROM EMP$DEPT # ERROR 6< 8NK9 1% ORA&33 12% :D8?>K 6>7NS?D?F8A =9TNK9= TO SLOVE THAT WE HAVE 'EEP DEPT OR EMP BEFORE DEPTNO$BCOZ BOTH TABLES HAVE DEPTNO COLUMN. S"L4 SELECT EMPNO$ENAME$EMP.DEPTNO$DNAME$LOC FROM EMP$DEPT 2 WHERE EMP.DEPTNOIDEPT.DEPTNO5 EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 RESEARCH DALLAS 0, ALLEN )3 SALES CHICAGO 0.21 WARD )3 SALES CHICAGO 0.// JONES 23 RESEARCH DALLAS 0/., MARTIN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0022 CLAR' 13 ACCOUNTING NEW YOR' 0022 SCOTT 23 RESEARCH DALLAS 02) 'ING 13 ACCOUNTING NEW YOR' 02,, TURNER )3 SALES CHICAGO 020/ ADAMS 23 RESEARCH DALLAS 0 33 JAMES )3 SALES CHICAGO 0 32 FORD 23 RESEARCH DALLAS 0 ), MILLER 13 ACCOUNTING NEW YOR' 1, ;DEF F989:<9=. TABLE NA)E ALIASING: SELECT EMPNO$ENAME$SAL$E.DEPTNO$DNAME$LOC FROM EMP E$DEPT D WHERE E.DEPTNOID.DEPTNO5

1 SELECT EMPNO$ENAME$E.DEPTNO$DNAME$LOC FROM EMP E$DEPT D 2# WHERE E.DEPTNOID.DEPTNO S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 RESEARCH DALLAS 0, ALLEN )3 SALES CHICAGO 0.21 WARD )3 SALES CHICAGO 0.// JONES 23 RESEARCH DALLAS 0/., MARTIN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0022 CLAR' 13 ACCOUNTING NEW YOR' 0022 SCOTT 23 RESEARCH DALLAS 02) 'ING 13 ACCOUNTING NEW YOR' 02,, TURNER )3 SALES CHICAGO 020/ ADAMS 23 RESEARCH DALLAS 0 33 JAMES )3 SALES CHICAGO 0 32 FORD 23 RESEARCH DALLAS 0 ), MILLER 13 ACCOUNTING NEW YOR' 1, ;DEF F989:<9=. NON%EQUI JOIN:

..

THE RELATIONSHIP BETWEEN THE EMP TABLE AND THE SALGRADE TABLE IS A NON&E"UIJOIN$MEANING THAT NO COLUMN IN THE EMP TABLE CORRESPONDS DIRECTLY TO A COLUMN IN THE SALGRADE TABLE. SELECT ENAME$SAL$GRADE FROM EMP$SALGRADE WHERE SAL BETWEEN LOSAL AND HISAL. SELECT ENAME$SAL$GRADE FROM EMP E $SALGRADE S WHERE E.SAL BETWEEN S.LOSAL AND S.HISAL5 S"L4 SELECT EMPNO$ENAME$SAL$GRADE FROM EMP$SALGRADE 2 WHERE SAL BETWEEN LOSAL AND HISAL5 EMPNO ENAME SAL GRADE &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH 233 1 020/ ADAMS 1133 1 0 33 JAMES .3 1 0.21 WARD 12.3 2 0/., MARTIN 12.3 2 0 ), MILLER 1)33 2 0, ALLEN 1/33 02,, TURNER 1.33 ) 0.// JONES 2 0. , 0/ 2 BLA'E 22.3 0022 CLAR' 2,.3 , 0022 SCOTT )333 , 0 32 FORD )333 02) 'ING .333 1, ;DEF F989:<9=. OUTER%JOIN: WE USE AN OUTER JOIN TO ALSO SEE ROWS THAT DO NOT USUALLY MEET THE JOIN CONDITION.THE OUTER JOIN OPERATOR IS THE PLUS SIGN(J). HERE WE GET E!TRA INFORMATION IN DEPT TABLE. T.IS IS RIG.T OUTER JOIN( SELECT E.EMPNO$E.ENAME$D.DEPTNO$D.DNAME

) , , .

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
FROM EMP E$DEPT D WHERE E.DEPTNO(J) I D.DEPTNO HERE WE GET E!TRA INFORMATION IN EMP TABLE. T.IS LEFT OUTER JOIN( SELECT E.EMPNO$E.ENAME$E.DEPTNO$D.DNAME FROM EMP E$DEPT D WHERE E.DEPTNO I D.DEPTNO(J) YOU CANNOT PLACE (9) SIGN ON BOT. SIDES(

./

T.IS IS RIG.T OUTER JOIN(

S"L4 SELECT EMPNO$ENAME$EMP.DEPTNO$DNAME$LOC FROM EMP$DEPT 2 WHERE EMP.DEPTNO(J) I DEPT.DEPTNO5 EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0022 CLAR' 13 ACCOUNTING NEW YOR' 02) 'ING 13 ACCOUNTING NEW YOR' 0 ), MILLER 13 ACCOUNTING NEW YOR' 0)/ SMITH 23 RESEARCH DALLAS 020/ ADAMS 23 RESEARCH DALLAS 0 32 FORD 23 RESEARCH DALLAS 0022 SCOTT 23 RESEARCH DALLAS 0.// JONES 23 RESEARCH DALLAS 0, ALLEN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0/., MARTIN )3 SALES CHICAGO 0 33 JAMES )3 SALES CHICAGO 02,, TURNER )3 SALES CHICAGO 0.21 WARD )3 SALES CHICAGO OPERATIONS BOSTON 1. ;DEF F989:<9=.

1 SELECT EMPNO$ENAME$DEPT.DEPTNO$DNAME$LOC FROM EMP$DEPT 2# WHERE EMP.DEPTNO(J) I DEPT.DEPTNO S"L4 / EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0022 CLAR' 13 ACCOUNTING NEW YOR' 02) 'ING 13 ACCOUNTING NEW YOR' 0 ), MILLER 13 ACCOUNTING NEW YOR' 0)/ SMITH 23 RESEARCH DALLAS 020/ ADAMS 23 RESEARCH DALLAS 0 32 FORD 23 RESEARCH DALLAS 0022 SCOTT 23 RESEARCH DALLAS 0.// JONES 23 RESEARCH DALLAS 0, ALLEN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0/., MARTIN )3 SALES CHICAGO 0 33 JAMES )3 SALES CHICAGO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
02,, TURNER 0.21 WARD 1. ;DEF F989:<9=. )3 SALES )3 SALES ,3 OPERATIONS CHICAGO CHICAGO BOSTON T.IS IS LEFT OUTER JOIN( 1 SELECT EMPNO$ENAME$DEPT.DEPTNO$DNAME$LOC FROM EMP$DEPT 2# WHERE EMP.DEPTNOIDEPT.DEPTNO(J) S"L4 / EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 RESEARCH DALLAS 0, ALLEN )3 SALES CHICAGO 0.21 WARD )3 SALES CHICAGO 0.// JONES 23 RESEARCH DALLAS 0/., MARTIN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0022 CLAR' 13 ACCOUNTING NEW YOR' 0022 SCOTT 23 RESEARCH DALLAS 02) 'ING 13 ACCOUNTING NEW YOR' 02,, TURNER )3 SALES CHICAGO 020/ ADAMS 23 RESEARCH DALLAS 0 33 JAMES )3 SALES CHICAGO 0 32 FORD 23 RESEARCH DALLAS 0 ), MILLER 13 ACCOUNTING NEW YOR' 1, ;DEF F989:<9=. HERE WE DONCT HAVE ANY E!TRA INFO IN EMP TABLE BECAUSE OF FOREIGN 'EY RELATION. THAT IS WE SHOULD NOT ENTER OTHER DEPARTMENT NUMBERS THAT ARE NOT PRESENT IN THE DEPT TABLE

.0

S"L4 CREATE TABLE EMP1 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 CREATE TABLE DEPT1 2 AS ) SELECT # FROM DEPT5 T6789 :;96<9=. HERE BOTH THE TABLES HAVE NO RELATION WITH FOREIGN 'EY AND PRIMARY 'EY. HERE I AM INSERTING IN TO EMP1 TABLE DEPARTMENT .3$/3$03 THAT ARE NOT THERE IN DEPT1 TABLE 1 INSERT INTO EMP1 2 VALUES )# (2$C'UMARC$CMANAGERC$0)/ $C31&JAN& 3C$1333$133$/3) S"L4 / 1 ;DE :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 INSERT INTO EMP1 2 VALUES )# ()$CGAYATRIC$CMANAGERC$0)/ $C31&JAN& 3C$1333$133$03) S"L4 / 1 ;DE :;96<9=. S"L4 COMMIT5 CD>>N< :D>B89<9. S"L4 SELECT EMPNO$ENAME$EMP1.DEPTNO$DNAME$LOC FROM EMP1$DEPT1 2 WHERE EMP1.DEPTNOIDEPT1.DEPTNO(J)5 EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0022 CLAR' 13 ACCOUNTING NEW YOR' 02) 'ING 13 ACCOUNTING NEW YOR' 0 ), MILLER 13 ACCOUNTING NEW YOR' 0)/ SMITH 23 RESEARCH DALLAS 020/ ADAMS 23 RESEARCH DALLAS 0 32 FORD 23 RESEARCH DALLAS 0022 SCOTT 23 RESEARCH DALLAS 0.// JONES 23 RESEARCH DALLAS 0, ALLEN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0/., MARTIN )3 SALES CHICAGO 0 33 JAMES )3 SALES CHICAGO 02,, TURNER )3 SALES CHICAGO 0.21 WARD )3 SALES CHICAGO 1 PAVAN .3 2 'UMAR /3 ) GAYATRI 03 10 ;DEF F989:<9=. 1 SELECT EMPNO$ENAME$EMP1.DEPTNO$DNAME$LOC FROM EMP1$DEPT1 2# WHERE EMP1.DEPTNO(J)IDEPT1.DEPTNO S"L4 / EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0022 CLAR' 13 ACCOUNTING NEW YOR' 02) 'ING 13 ACCOUNTING NEW YOR' 0 ), MILLER 13 ACCOUNTING NEW YOR' 0)/ SMITH 23 RESEARCH DALLAS 020/ ADAMS 23 RESEARCH DALLAS 0 32 FORD 23 RESEARCH DALLAS 0022 SCOTT 23 RESEARCH DALLAS 0.// JONES 23 RESEARCH DALLAS 0, ALLEN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0/., MARTIN )3 SALES CHICAGO 0 33 JAMES )3 SALES CHICAGO 02,, TURNER )3 SALES CHICAGO 0.21 WARD )3 SALES CHICAGO OPERATIONS BOSTON 1. ;DEF F989:<9=.

.2

1 SELECT EMPNO$ENAME$DEPT1.DEPTNO$DNAME$LOC FROM EMP1$DEPT1

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2# WHERE EMP1.DEPTNO(J)IDEPT1.DEPTNO S"L4 / EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0022 CLAR' 13 ACCOUNTING NEW YOR' 02) 'ING 13 ACCOUNTING NEW YOR' 0 ), MILLER 13 ACCOUNTING NEW YOR' 0)/ SMITH 23 RESEARCH DALLAS 020/ ADAMS 23 RESEARCH DALLAS 0 32 FORD 23 RESEARCH DALLAS 0022 SCOTT 23 RESEARCH DALLAS 0.// JONES 23 RESEARCH DALLAS 0, ALLEN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0/., MARTIN )3 SALES CHICAGO 0 33 JAMES )3 SALES CHICAGO 02,, TURNER )3 SALES CHICAGO 0.21 WARD )3 SALES CHICAGO ,3 OPERATIONS BOSTON 1. ;DEF F989:<9=. 1 SELECT EMPNO$ENAME$DEPT1.DEPTNO$DNAME$LOC FROM EMP1$DEPT1 2# WHERE EMP1.DEPTNO(J)IDEPT1.DEPTNO(J) S"L4 / WHERE EMP1.DEPTNO(J)IDEPT1.DEPTNO(J) # ERROR 6< 8NK9 2% ORA&31,/2% 6 B;9=N:6<9 >6A ;9T9;9K:9 DK8A DK9 D?<9;&XDNK9= <6789 YOU CAN NOT 'EEP J SIGN ON BOTH SIDES. UPDATING RO+S: UPDATE EMP SET SAL I SALJ133$DEPTNOI13$JOBICLER'5 UPDATE EMP SET SAL I SALJ133$DEPTNOI13$JOBICLER'5 WHERE WCONDITION4

YOU CAN UPDATE MORE THAN ONE COLUMN IN A TABLE AT A TIME. S"L4 CREATE TABLE EMPLOYEE 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 UPDATE EMPLOYEE 2 SET SAL I1333$ JOB I CMANAGERC5 1, ;DEF ?B=6<9=. THE ABOVE STATEMENT UPDATED WHOLE TABLE. S"L4 UPDATE EMPLOYEE

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 SET SAL I2333$ JOBICCLER'C ) WHERE DEPTNOI135 ) ;DEF ?B=6<9=. IN THE ABOVE TABLE THE ONLY DEPTNO 13 ROWS ARE UPDATED. +.AT NOT +IT. ALTER: WE CANNOT DECREASE COLUMN SIZE IF DATA E!ISTS. WE CANNOT CHANGE NAME OF TABLE USING ALTER. WE CANNOT CHANGE COLUMN NAME. RENA)ING T.E TABLE : RENAME EMP TO EMP1 5 S"L4 RENAME EMPLOYEE TO EMP(INFO5 T6789 ;9K6>9=. IN THE ABOVE STATEMENT EMPLOYEE WAS RENAMED TO EMP(INFO5 IF YOU "UERY EMPLOYEE NOW U WILL GET ERROR. S"L4 SELECT # FROM EMPLOYEE5 SELECT # FROM EMPLOYEE # ERROR 6< 8NK9 1% ORA&33 ,2% <6789 D; QN9E =D9F KD< 9UNF< SAL4 SELECT # FROM EMP(INFO5 THE ABOVE STATEMENT WILL WOR'. DEFAULT: S"L4 CREATE TABLE EMPLOYEE 2 (EMPNO NUMBER(13)$ ) ENAME VARCHAR2(13)$ , DEPTNO NUMBER(13) DEFAULT 13)5 T6789 :;96<9=. S"L4 INSERT INTO EMPLOYEE 2 VALUES ) (1$CPAVANC$13)5 1 ;DE :;96<9=. 1 INSERT INTO EMPLOYEE 2 VALUES )# (2$C'UMARC$23) S"L4 / 1 ;DE :;96<9=.

/3

HERE WE HAD NOT GIVEN VALUE FOR DEPTNO.THEN IT HAD TA'EN 23 FOR DEPTNO$ BCOZ WE HAD GIVEN DEFAULT 23 FOR DEPTNO. 1 INSERT INTO EMPLOYEE 2 (EMPNO$ENAME) ) VALUES ,# (2$C'UMARC)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
. / 1 ;DE :;96<9=. 1 INSERT INTO EMPLOYEE 2 VALUES )# (2$C'UMARC) , / INSERT INTO EMPLOYEE # ERROR 6< 8NK9 1% ORA&33 ,0% KD< 9KD?SR Q68?9F

/1

S"L4 SELECT # FROM EMPLOYEE5 EMPNO ENAME DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 1 PAVAN 13 2 'UMAR 23 2 'UMAR 13 IN THE ABOVE "UERY WHENEVER YOU DONCT GIVE VALUE FOR DEPTNO THERE DEFAULT VALUE WILL BE TA'EN.

ADDING CO))ENTS TO A TABLE ( YOU CAN ADD COMMENTS TO A TABLE USING THE COMMENT STATEMENT . COMMENT ON TABLE EMP IS G EMPLOYEE INFORMATION G 5 IN THE REALTIME ENVIRONMENT WE WILL CREATING SO MANY TABLES THERE IT IS VERY HARD TO FIND WHICH TABLE WILL HAVE WHAT INFO AT THAT TIME WE CREATE COMMENTS ON TABLES. NOW I AM CREATING COMMENTS ON THE TABLE EMP THAT IT SORES ALL THE EMPLOYEE INFO. COMMENT ON TABLE EMP IS C IT STORES EMPLOYEE INFO C S"L4 / CD>>9K< :;96<9=. *IE+ING CO))ENTS: ALL(TAB(COMMENTS$USER(TAB(COMMENTS 5 SELECT # FROM USER(TAB(COMMENTS5 1# SELECT # FROM USER(TAB(COMMENTS WHERE TABLE(NAMEICEMPC S"L4 / TABLE(NAME TABLE(TYPE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&& COMMENTS &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMP TABLE IT STORES EMPLOYEE INFO TO SEE WHAT TABLE HAVE WHAT COMMENT WE HAVE TO "UERY USER(TAB(COMMENTS.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DROP CO))ENTS: COMMENT ON TABLE EMP IS G G 5 TO DELETE THE COMMENT ON TABLE WE WRITE "UERY LI'E BELOW. COMMENT ON TABLE EMP IS C C 5 CD>>9K< :;96<9=. 1 SELECT # FROM USER(TAB(COMMENTS 2# WHERE TABLE(NAMEICEMPC S"L4 / TABLE(NAME TABLE(TYPE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&& COMMENTS &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMP TABLE RE)O*E T.E PRI)ARY -EY CONSTRAINT ON T.E DEPT TABLE AND DEPTNO T.E ASSOCIATED FOREIGN -EY CONSTRAINT ON T.E E)P(DEPTN8) COLU)N: WHEN EVER YOU RELATE BOTH EMP AND DEPT TABLES WITH FOREIGN 'EY THEN U PRETTY WELL 'NOW DEPT TABLE DEPTNO SHOULD HAVE PRIMARY 'EY. NOW IF YOU WANT TO DROP PRIMARY 'EY CONSTRAINT ON DEPT TABLE IT WONCT ALLOW YOU TO DROP BECAUSE IT IS CONNECTED WITH FOREIGN 'EY OF EMP TABLE DEPTNO COLUMN THEN IF YOU WANT TO DROP PRIMARY 'EY WHAT U SHOULD DO IS TYPE BELOW "UERY. ALTER TABLE DEPT1 DROP CONSTRAINT DEPT1(P' CASCADE5 S"L4 CREATE TABLE EMP1 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 CREATE TABLE DEPT1 2 AS ) SELECT # FROM DEPT5 T6789 :;96<9=. S"L4 ALTER TABLE DEPT1 2 ADD CONSTRAINT DEPT1(P' PRIMARY 'EY(DEPTNO)5 T6789 68<9;9=. S"L4 ALTER TABLE EMP1 2 ADD CONSTRAINT EMP1(F' FOREIGN 'EY(DEPTNO) REFERENCES DEPT1(DEPTNO)5 T6789 68<9;9=. S"L4 ALTER TABLE DEPT1 2 DROP CONSTRAINT DEPT1(P'5 DROP CONSTRAINT DEPT1(P' # ERROR 6< 8NK9 2% ORA&3220)% <RNF ?KNP?9/B;N>6;A L9A NF ;9T9;9K:9= 7A FD>9 TD;9NSK L9AF S"L4 ALTER TABLE DEPT1 2 DROP CONSTRAINT DEPT1(P' CASCADE5

/2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
T6789 68<9;9=. NOW BOTH PRIMARY 'EY FOR DEPT1 AND FOREIGN 'EY FOR EMP1 BOTH ARE DELETED. IF YOU +ANT TO SEE +.AT COUL)NS .A*E CONSTRAINTS"+E USE BELO+ TABLE( SELECT # FROM USER(CONS(COLUMNS WHERE TABLE(NAMEICDEPT1C5 SET OPERATORS: UNION ALL UNION INTERSECT )INUS

/)

SET OPERATORS ARE USED TO COMBINE INFORMATION OF SIMILAR TYPE FROM ONE OR MORE THAN ONE TABLE.DATATYPES OF CORRESPONDING COLUMNS MUST BE SAME. UNION: RO+S OF FIRST QUERY 9 RO+S OF SECOND QUERY LESS DUPLICATE RO+S LIST OF JOBS IN DEPTNOI13 AND 23 LESS DUPLICATION. SELECT JOB FROM EMP WHERE DEPTNOI13 UNION SELECT JOB FROM EMP WHERE DEPTNOI23 5 1 SELECT JOB FROM EMP WHERE DEPTNOI13 2 UNION )# SELECT JOB FROM EMP WHERE DEPTNOI23 S"L4 / JOB &&&&&&&&& ANALYST CLER' MANAGER PRESIDENT

UNION ALL: RO+S OF FIRST QUERY 9 RO+S OF SECOND QUERY +IT. DUPLICATE RO+S: LIST OF JOBS IN DEPTNOI13 AND 23. SELECT JOB FROM EMP WHERE DEPTNOI13 UNION ALL SELECT JOB FROM EMP WHERE DEPTNOI23 5 S"L4 SELECT JOB FROM EMP WHERE DEPTNOI13 2 UNION ALL ) SELECT JOB FROM EMP WHERE DEPTNOI235 JOB &&&&&&&&& MANAGER PRESIDENT

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CLER' CLER' MANAGER ANALYST CLER' ANALYST 2 ;DEF F989:<9=. INTERSECT : CO))ON RO+S FRO) 6 QUERIES( LIST OF JOBS COMMON IN DEPTNOI13 AND 23. SELECT JOB FROM EMP WHERE DEPTNOI13 INTERSECT SELECT JOB FROM EMP WHERE DEPTNOI23 5 1 SELECT JOB FROM EMP WHERE DEPTNOI13 2 INTERSECT )# SELECT JOB FROM EMP WHERE DEPTNOI23 S"L4 / JOB &&&&&&&&& CLER' MANAGER )INUS: +.IC. GI*ES UNIQUE RO+S: LIST OFJOBS UNI"UE IN DEPTNOI23 SELECT JOB FROM EMP WHERE DEPTNOI23 MINUS SELECT JOB FROM EMP WHERE DEPTNOI13 MINUS SELECT JOB FROM EMP WHERE DEPTNOI)35 +IT. IN OPERATOR: SELECT JOB FROM EMP WHERE DEPTNOI23 MINUS SELECT JOB FROM EMP WHERE DEPTNO IN(13$)3)5 1 SELECT JOB FROM EMP WHERE DEPTNOI13 2 MINUS )# SELECT JOB FROM EMP WHERE DEPTNOI23 S"L4 / JOB &&&&&&&&& PRESIDENT 1 SELECT JOB FROM EMP WHERE DEPTNOI13 2 MINUS ) SELECT JOB FROM EMP WHERE DEPTNOI23 , MINUS .# SELECT JOB FROM EMP WHERE DEPTNOI)3 S"L4 /

/,

JOB

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
&&&&&&&&& PRESIDENT 1 SELECT JOB FROM EMP WHERE DEPTNOI13 2 MINUS )# SELECT JOB FROM EMP WHERE DEPTNO IN (23$)3) S"L4 / JOB &&&&&&&&& PRESIDENT 1# SELECT JOB FROM EMP WHERE DEPTNO IN (13$23) 1 THIS IS UNION ALL S"L4 / JOB &&&&&&&&& CLER' MANAGER MANAGER ANALYST PRESIDENT CLER' ANALYST CLER' 2 ;DEF F989:<9=. S"L4 SELECT DISTINCT(JOB) FROM EMP WHERE DEPTNO IN (13$23)5 & THIS IS UNION. JOB &&&&&&&&& ANALYST CLER' MANAGER PRESIDENT

/.

CREATING GROUPS OF DATA: GROUP BY DIVIDE ROWS IN A TABLE INTO SMALLER GROUPS BY USING THE GROUP BY CLAUSE. T.E BELO+ STATE)ENTS DOES NOT +OR-: S"L4 SELECT DEPTNO$SUM(SAL) FROM EMP5 SELECT DEPTNO$SUM(SAL) FROM EMP # ERROR 6< 8NK9 1% ORA&33 )0% KD< 6 FNKS89&S;D?B S;D?B T?K:<NDK THE ABOVE "UERY DOES NOT WOR' BECAUSE DEPTNO WILL GIVES 1, ROWS AND SUM(SAL) WILL GIVES ONE ROW. THERE IS NO MATCHING OF ROWS. ALL COLUMNS IN THE SELECT LIST THAT ARE NOT IN GROUP FUNCTIONS MUST BE IN THE GROUP BY CLAUSE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
IF IT HAS TO WOR' WE HAVE TO GIVE LI'E THIS. S"L4 SELECT DEPTNO$SUM(SAL) FROM EMP 2 GROUP BY DEPTNO5 DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 13 20.3 23 1320. )3 ,33

//

ANY COLUMN OR E!PRESSION IN THE SELECT LIST THST IS NOT AN AGGREGATE FUNCTION MUST BE IN THE GROUP BY CLAUSE.

WHENEVER WE SEE NON AGGREGATE COLUMN IN SELECT LIST THAT HAS TO BE THERE AFTER GROUP BY CLAUSE LI-E ABO*E BELO+ QUERIES +ON4T +OR-: S"L4 SELECT DEPTNO$COUNT(DEPTNO) FROM EMP5 SELECT DEPTNO$COUNT(DEPTNO) FROM EMP # ERROR 6< 8NK9 1% ORA&33 )0% KD< 6 FNKS89&S;D?B S;D?B T?K:<NDK S"L4 SELECT DEPTNO$AVG(DEPTNO) FROM EMP 2 / SELECT DEPTNO$AVG(DEPTNO) FROM EMP # ERROR 6< 8NK9 1% ORA&33 )0% KD< 6 FNKS89&S;D?B S;D?B T?K:<NDK S"L4 SELECT DEPTNO$MA!(DEPTNO) FROM EMP5 SELECT DEPTNO$MA!(DEPTNO) FROM EMP # ERROR 6< 8NK9 1% ORA&33 )0% KD< 6 FNKS89&S;D?B S;D?B T?K:<NDK S"L4 SELECT DEPTNO$MIN(DEPTNO) FROM EMP5 SELECT DEPTNO$MIN(DEPTNO) FROM EMP # ERROR 6< 8NK9 1% ORA&33 )0% KD< 6 FNKS89&S;D?B S;D?B T?K:<NDK +E .A*E TO GI*E NON AGGREGATE COLU)NS T.AT ARE IN T.E SELECT LIST IN GROUP BY CLAUSE(

S"L4 SELECT DEPTNO$SUM(SAL) FROM EMP 2 GROUP BY DEPTNO5 DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 13 20.3 23 1320. )3 ,33 S"L4 SELECT DEPTNO$COUNT(ENAME) 2 FROM EMP ) GROUP BY DEPTNO5 DEPTNO COUNT(ENAME) &&&&&&&&&& &&&&&&&&&&&& 13 )

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
23 )3 . / S"L4 SELECT DEPTNO$AVG(SAL) 2 FROM EMP ) GROUP BY DEPTNO5 DEPTNO AVG(SAL) &&&&&&&&&& &&&&&&&&&& 13 2 1/.////0 23 210. )3 1.//.////0 S"L4 SELECT DEPTNO$SUM(SAL) 2 FROM EMP ) GROUP BY DEPTNO5 DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 13 20.3 23 1320. )3 ,33

/0

T.E GROUP BY COLU)N DOES NOT .A*E TO BE IN T.E SELECT LIST: SELECT AVG(SAL) FROM EMP GROUP BY DEPTNO5 S"L4 SELECT AVG(SAL) 2 FROM EMP ) GROUP BY DEPTNO5 AVG(SAL) &&&&&&&&&& 2 1/.////0 210. 1.//.////0 YOU CAN USE T.E GROUP FUCTIONS IN T.E ORDER BY CLAUSE: SELECT DEPTNO$AVG(SAL) FROM EMP GROUP BY DEPTNO ORDER BY AVG(SAL)5 S"L4 SELECT DEPTNO$AVG(SAL) 2 FROM EMP ) GROUP BY DEPTNO , ORDER BY AVG(SAL)5 DEPTNO AVG(SAL) &&&&&&&&&& &&&&&&&&&& )3 1.//.////0 23 210. 13 2 1/.////0

USING T.E GROUP BY CLAUSE ON )ULTIPLE COLU)NS:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECT DEPTNO$JOB$SUM(SAL) FROM EMP GROUP BY DEPTNO$JOB5

/2

S"L4 SELECT DEPTNO$JOB$SUM(SAL) 2 FROM EMP ) GROUP BY DEPTNO$JOB5 DEPTNO JOB &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 13 MANAGER 13 PRESIDENT 23 ANALYST 23 CLER' 23 MANAGER )3 CLER' )3 MANAGER )3 SALESMAN ;DEF F989:<9=. USING +.ERE CLAUSE FOR T.E QUERY: SUM(SAL) 1)33 2,.3 .333 /333 1 33 2 0. .3 22.3 ./33

SELECT DEPTNO$AVG(SAL) FROM EMP WHERE DEPTNOI13 GROUP BY DEPTNO HAVING AVG(SAL) 423335 S"L4 SELECT DEPTNO$SUM(SAL) FROM EMP 2 WHERE DEPTNOI13 ) GROUP BY DEPTNO , HAVING SUM(SAL) 4 3335 KD ;DEF F989:<9=

1 SELECT DEPTNO$SUM(SAL) FROM EMP 2 WHERE DEPTNOI13 ) GROUP BY DEPTNO ,# HAVING SUM(SAL) 4 2333 S"L4 / DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 13 20.3 REMEMBER ONE THING WHENEVER YOU SEE AGGREGATE COLUMN IN WHERE CLAUSE IT WONCT WOR'. BUT WHENEVER YOU SEE NON&AGGREGATE COLUMN IN WHERE CLAUSE IT WILL WOR'.

YOU CANNOT USE T.E +.ERE CLAUSE TO RESTRICT GROUPS:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECT DEPTNO$AVG(SAL) FROM EMP WHERE AVG(SAL) 42333 GROUP BY DEPTNO5 S"L4 SELECT DEPTNO$SUM(SAL) FROM EMP 2 WHERE SUM(SAL) 4 333 ) GROUP BY DEPTNO5 WHERE SUM(SAL) 4 333 # ERROR 6< 8NK9 2% ORA&33 ),% S;D?B T?K:<NDK NF KD< 688DE9= R9;9

HERE WHENEVER ORACLE E!ECUTES THIS "UERY IT E!ECUTES WHERE FIRST AND THEN GROUP BY HERE IT IS NOT POSSIBLE TO FIND SUM(SAL) FOR ALL DEPARTMENTS BEFORE GROUP BY CLAUSE. WHENEVER YOU SEE AGGREGATE COLUMN IN WHERE CLAUSE IT WONCT WOR'.

YOU USE T.E .A*ING CLAUSE TO RESTRICT GROUPS: SELECT DEPTNO$AVG(SAL) FROM EMP GROUP BY DEPTNO HAVING AVG(SAL) 423335

S"L4 SELECT DEPTNO$SUM(SAL) FROM EMP 2 GROUP BY DEPTNO ) HAVING SUM(SAL) 4 3335 DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 23 1320. )3 ,33 HERE WE HAVE TO USE HAVING CLAUSE. THE ORDER OF E!ECUTION FOR THE GROUP BY "UERIES IS LI'E THIS FIRST WHERE CLAUSE$GROUP BY$ HAVING CLAUSE.

T.E ORDER OF E*ALUATION OF T.E CLAUSES( WHERE$GROUP BY$HAVING CLAUSE. DISPLAY )A/I)U) A*AERAGE SALARY: SELECT MA!(AVG(SAL)) FROM EMP GROUP BY DEPTNO5 S"L4 SELECT MA!(AVG(SAL)) FROM EMP GROUP BY DEPTNO5 MA!(AVG(SAL)) &&&&&&&&&&&&& 2 1/.////0 C.ARACTER FUNCTIONS:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECT LOWER(GPAVAN) FROM DUAL5 SELECT UPPER(GB6Q6K) FROM DUAL5 SELECT INITCAP(GB6Q6K) FROM DUAL5 SELECT CONCAT(CGOODC$CBOYC) FROM DUAL5 SELECT SUBSTR(CPAVANC$1$)) FROM DUAL5 SELECT LENGTH(CPAVANC) FROM DUAL5 SELECT INSTR(CPAVANC$CVC) FROM DUAL5 S"L4 SELECT LOWER(CPAVANC) FROM DUAL5 LOWER &&&&& B6Q6K S"L4 SELECT UPPER(CB6Q6KC) FROM DUAL5 UPPER &&&&& PAVAN S"L4 SELECT INITCAP(CB6Q6KC) FROM DUAL5 INITC &&&&& P6Q6K S"L4 SELECT CONCAT(CGOODC$CBOYC) FROM DUAL5 CONCAT( &&&&&&& GOODBOY S"L4 SELECT SUBSTR(CPAVANC$1$)) FROM DUAL5 SUB &&& PAV S"L4 SELECT LENGTH(CPAVANC) FROM DUAL5 LENGTH(CPAVANC) &&&&&&&&&&&&&&& . S"L4 SELECT INSTR(CPAVANC$CVC) FROM DUAL5 INSTR(CPAVANC$CVC) &&&&&&&&&&&&&&&&&& ) DATE FUNCTIONS: MONTHS(BETWEEN NUMBER OF MONTHS BETWEEN DATES

03

SELECT MONTHS(BETWEEN(C31&SEP& .C$C11&JAN& ,C )FROM DUAL5 SELECT MONTHS(BETWEEN(C11&JAN& ,C $C31&SEP& .C)FROM DUAL5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT MONTHS(BETWEEN(C31&SEP& .C$C11&JAN& ,C )FROM DUAL5 MONTHS(BETWEEN(C31&SEP& .C$C11&JAN& ,C) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 1 ./00,1 , S"L4 SELECT MONTHS(BETWEEN(C11&JAN& ,C $C31&SEP& .C)FROM DUAL5 MONTHS(BETWEEN(C11&JAN& ,C$C31&SEP& .C) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &1 ./00,1 ADD(MONTHS ADD MONTHS TO DATE.

01

SELECT ADD(MONTHS(C11&JAN& ,C$/) FROM DUAL5 S"L4 SELECT ADD(MONTHS(C11&JAN& ,C$/) FROM DUAL5 ADD(MONTH &&&&&&&&& 11&JUL& , NE!T(DAY NE!T DAY OF THE DATE SPECIFIED.

SELECT NE!T(DAY(C31&SEP& /C$CFRIDAYC) FROM DUAL5 S"L4 SELECT NE!T(DAY(C31&SEP& /C$CFRIDAYC) FROM DUAL5 NE!T(DAY( &&&&&&&&& 3/&SEP& / LAST(DAY SELECT LAST(DAY(C31&SEP& /C) FROM DUAL5 S"L4 SELECT LAST(DAY(C31&SEP& /C) FROM DUAL5 LAST(DAY( &&&&&&&&& )3&SEP& / SQL *PLUS FILE CO))ANDS: SAVE FILENAME % SAVES CURRENT CONTENTS OF S"L BUFFER TO FILE$THE DEFAULT FILE E!TENSION IS .S"L GET FILENAME%WRITES THE CONTENTS OF THE FILE. STARTFILENAME%RUNS THE FILE. YFILENAME%RUNS THE FILE$ EDIT FILENAME%INVO'ES EDITOR TO EDIT CONTENTS OF A SAVED FILE. SPOOL C%ZPAVAN % IT IS USED FOR SAVING OUTPUT OF THE "UERY IN THE FILE.THE FILE E!TENSION IS .LST. E!IT%LEAVES THE S"L# PLUS. LAST DAY OF THE MONTH.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM EMP5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 1, ;DEF F989:<9=. S"L4 SAVE PAVAN C;96<9= TN89 PAVAN.FP8 IT SAVES THE "UERY WHICH IS THERE IN EDITOR. S"L4 GET PAVAN 1# SELECT # FROM EMP IT DISPLAYS THE "UERY IN THE FILE. S"L4 START PAVAN IT E!ECUTES THE "UERY THAT IS THERE IN FILE PAVAN. S"L4 SELECT # FROM EMP5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 1, ;DEF F989:<9=. S"L4 YPAVAN IT E!ECUTES THE "UERY THAT IS THERE IN FILE PAVAN. S"L4 SELECT # FROM EMP5 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 COMM 233 DEPTNO 23

02

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0, ALLEN 0.21 WARD 0.// JONES 0/., MARTIN 0/ 2 BLA'E 0022 CLAR' 0022 SCOTT 02) 'ING 02,, TURNER 020/ ADAMS 0 33 JAMES 0 32 FORD 0 ), MILLER SALESMAN 0/ 2 23&FEB&21 SALESMAN 0/ 2 22&FEB&21 12.3 MANAGER 02) 32&APR&21 2 0. SALESMAN 0/ 2 22&SEP&21 12.3 MANAGER 02) 31&MAY&21 22.3 MANAGER 02) 3 &JUN&21 2,.3 ANALYST 0.// 1 &APR&20 )333 PRESIDENT 10&NOV&21 .333 SALESMAN 0/ 2 32&SEP&21 1.33 CLER' 0022 2)&MAY&20 1133 CLER' 0/ 2 3)&DEC&21 .3 ANALYST 0.// 3)&DEC&21 )333 CLER' 0022 2)&JAN&22 1)33 1/33 .33 1,33 3 )33 )3 23 )3 )3 13 23 13 )3 23 )3 23 13 )3

0)

S"L4 RUN PAVAN IT E!ECUTES THE "UERY THAT IS THERE IN FILE PAVAN. 1# SELECT # FROM EMP S"L4 SELECT # FROM EMP5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 1, ;DEF F989:<9=.

S"L4 EDIT PAVAN IT OPENS THE FILE FOR EDITING. DIFFERENCE BET+EEN SQL AND SQL*PLUS: S"L % STRUCTURED "UERY LANGUAGE. S"L IS A LANGUAGE FOR COMMUNICATING WITH THE ORACLE SERVER TO ACCESS DATA. IS BASED ON AMERICAN NATIONAL STANDARDS INSTITUTE. MANIPULATES DATA AND TABLE DEFINITIONS IN THE DATABASE. OPERATORS PRECEDENCE% ORDER EVALUATED 1 OPERATOR ALL COMPARISON OPERATORS S"L#PLUS RECOGNIZES S"L STATEMENTS AND SENDS THEM TO THE SERVER. IS THE ORACLE PROPRIETARY INTERFACE FOR E!ECUTING S"L STATEMENTS. DOES NOT ALLOWMANIPULATION OF VALUES IN THE DATABASE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 ) , NOT AND OR OVERRIDE RULES OF PRECEDENCE BY USING PARENTHESES. USING T+O COLU)NS IN ORDER BY: SELECT ENAME$DEPTNO$SAL FROM EMP ORDER BY DEPTNO DESC$SAL DESC5 SELECT ENAME$DEPTNO$SAL FROM EMP ORDER BY DEPTNO$SAL5 SELECT ENAME$DEPTNO$SAL FROM EMP ORDER BY DEPTNO DESC$SAL5 S"L4 SELECT ENAME$DEPTNO$SAL FROM EMP 2 ORDER BY DEPTNO DESC$SAL DESC5 ENAME DEPTNO SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& BLA'E )3 22.3 ALLEN )3 1/33 TURNER )3 1.33 WARD )3 12.3 MARTIN )3 12.3 JAMES )3 .3 SCOTT 23 )333 FORD 23 )333 JONES 23 2 0. ADAMS 23 1133 SMITH 23 233 'ING 13 .333 CLAR' 13 2,.3 MILLER 13 1)33 1, ;DEF F989:<9=.

0,

S"L4 SELECT ENAME$DEPTNO$SAL FROM EMP 2 ORDER BY DEPTNO$SAL5 ENAME DEPTNO SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& MILLER 13 1)33 CLAR' 13 2,.3 'ING 13 .333 SMITH 23 233 ADAMS 23 1133 JONES 23 2 0. SCOTT 23 )333 FORD 23 )333 JAMES )3 .3 WARD )3 12.3 MARTIN )3 12.3 TURNER )3 1.33 ALLEN )3 1/33 BLA'E )3 22.3 1, ;DEF F989:<9=. S"L4 SELECT ENAME$DEPTNO$SAL FROM EMP 2 ORDER BY DEPTNO DESC$SAL5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ENAME DEPTNO SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& JAMES )3 .3 WARD )3 12.3 MARTIN )3 12.3 TURNER )3 1.33 ALLEN )3 1/33 BLA'E )3 22.3 SMITH 23 233 ADAMS 23 1133 JONES 23 2 0. SCOTT 23 )333 FORD 23 )333 MILLER 13 1)33 CLAR' 13 2,.3 'ING 13 .333 1, ;DEF F989:<9=. YOU CAN SORT BY A COLU)N T.AT IS NOT IN T.E SELECT LIST(

0.

USE A *ARIABLE PREFI/ED +IT. AN A)PERSAND (:) TO PRO)PT T.E USER FO A *ALUE:

SET VERIFY OFF SELECT EMPNO$ENAME$SAL$DEPTNO FROM EMP WHERE EMPNOI+EMPLOYEE(NUMBER5 SET VERIFY ON SELECT EMPNO$ENAME$SAL$DEPTNO FROM EMP WHERE EMPNOI+EMPLOYEE(NUMBER5 S"L4 SELECT EMPNO$ENAME$SAL$DEPTNO FROM EMP 2 WHERE EMPNOI+EMPLOYEE(NUMBER5 EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0022 D8= 2% WHERE EMPNOI+EMPLOYEE(NUMBER K9E 2% WHERE EMPNOI0022 EMPNO ENAME SAL DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 SCOTT )333 23 S"L4 SET VERIFY OFF S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0)/ EMPNO ENAME SAL DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH 233 23 S"L4 SET VERIFY ON S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0.// D8= 2% WHERE EMPNOI+EMPLOYEE(NUMBER K9E 2% WHERE EMPNOI0.// EMPNO ENAME SAL DEPTNO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0.// JONES 2 0. 23 USING SINGLE QUOTATION )AR-S FOR DATE AND C.ARACTER *ALUES: SELECT ENAME$DEPTNO$SAL#2 FROM EMP WHERE JOBIC+JOB(TITLEC SELECT ENAME$DEPTNO$SAL#2 FROM EMP WHERE JOBIUPPER(C+JOB(TITLEC) S"L4 SELECT ENAME$DEPTNO$SAL#2 FROM EMP 2 WHERE JOBIC+JOB(TITLEC ) / EK<9; Q68?9 TD; XD7(<N<89% MANAGER D8= 2% WHERE JOBIC+JOB(TITLEC K9E 2% WHERE JOBICMANAGERC ENAME DEPTNO SAL#2 &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& JONES 23 . .3 BLA'E )3 .033 CLAR' 13 , 33 S"L4 SELECT ENAME$DEPTNO$SAL#2 FROM EMP 2 WHERE JOBIUPPER(C+JOB(TITLEC) S"L4 / EK<9; Q68?9 TD; XD7(<N<89% :89;L D8= 2% WHERE JOBIUPPER(C+JOB(TITLEC) K9E 2% WHERE JOBIUPPER(C:89;LC) ENAME DEPTNO SAL#2 &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& SMITH 23 1/33 ADAMS 23 2233 JAMES )3 1 33 MILLER 13 2/33

0/

USE SUBSTITUTION *ARIABLES TO SUPPLE)ENT T.E FOLLO+ING: +.ERE CONDITION ORDER BY COLU)N E/PRESSION TABLE ENTIRE SELECT STATEMENT

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECT + REMENNING(SELECT(STATEMENT5 SELECT EMPNO$ENAME$+COLUMN(NAME FROM +TABLE(NAME WHERE +WHERE(CONDITIN ORDER BY + COL(NAME S"L4 SELECT + REMENNING(SELECT(STATEMENT5 EK<9; Q68?9 TD; ;9>9KKNKS(F989:<(F<6<9>9K<% # T;D> 9>B D8= 1% SELECT + REMENNING(SELECT(STATEMENT K9E 1% SELECT # T;D> 9>B EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 1, ;DEF F989:<9=. S"L4 SELECT EMPNO$ENAME$+COLUMN(NAME 2 FROM +TABLE(NAME ) WHERE +WHERE(CONDITIN , ORDER BY + COL(NAME . / EK<9; Q68?9 TD; :D8?>K(K6>9% SAL D8= 1% SELECT EMPNO$ENAME$+COLUMN(NAME K9E 1% SELECT EMPNO$ENAME$SAL EK<9; Q68?9 TD; <6789(K6>9% EMP D8= 2% FROM +TABLE(NAME K9E 2% FROM EMP EK<9; Q68?9 TD; ER9;9(:DK=N<NK% SAL 4 2333 D8= )% WHERE +WHERE(CONDITIN K9E )% WHERE SAL 4 2333 EK<9; Q68?9 TD; :D8(K6>9% SAL D8= ,% ORDER BY + COL(NAME K9E ,% ORDER BY SAL EMPNO ENAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 CLAR' 0/ 2 BLA'E 0.// JONES 0022 SCOTT 0 32 FORD 02) 'ING / ;DEF F989:<9=. SAL 2,.3 22.3 2 0. )333 )333 .333

00

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 CREATE TABLE DEPT(DUP 2 AS ) SELECT # FROM DEPT5 T6789 :;96<9=.

02

+E USE 3:4 FOR INSERTING *ALUES IN T.E TABLE: INSERT INTO DEPT VALUES (+DEPARTMENT(NO$+DEPARTMENT NAME$+LOCATION)5

1# INSERT INTO DEPT(DUP VALUES (+DEPARTMENT(NO$C+DEPARTMENT NAMEC$C+LOCATIONC) S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% .3 EK<9; Q68?9 TD; =9B6;<>9K<% COMPUTERS EK<9; Q68?9 TD; 8D:6<NDK% NEW YOR' D8= 1% INSERT INTO DEPT(DUP VALUES (+DEPARTMENT(NO$C+DEPARTMENT NAMEC$C+LOCATIONC) K9E 1% INSERT INTO DEPT(DUP VALUES (.3$CCOMPUTERS NAMEC$CNEW YOR'C) 1 ;DE :;96<9=.

SQL STATE)ENTS: SELECT INSERT UPDATE DELETE CREATE ALTER DROP RENA)E TRUNCATE CO))IT ROLLBACSA*EPOINT GRANT RE*O-E DATA RETRI*AL DATA )ANIPULATION LANGUAGE (D)L STATE)ENTS)

DATA DEFINITION LANGUAGE (DDL STATE)ENTS)

TRANSACTION CONTROL

DATA CONTROL LANGUAGE (DCL)

SYNONY)S: S"L4 CREATE SYNONYM D FOR DEPT5 SAKDKA> :;96<9=. S"L4 SELECT # FROM D5 S"L4 DROP SYNONYM D5 SAKDKA> =;DBB9=. S"L4 CREATE SYNONYM DEPARTMENT FOR DEPT5 SAKDKA> :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM DEPT5 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 ACCOUNTING NEW YOR' 23 RESEARCH DALLAS )3 SALES CHICAGO ,3 OPERATIONS BOSTON S"L4 SELECT # FROM DEPARTMENT5 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 ACCOUNTING NEW YOR' 23 RESEARCH DALLAS )3 SALES CHICAGO ,3 OPERATIONS BOSTON RENAME IS DIFFERENT FROM SYNONYM.

SUBQUERIES: "UERY INSIDE A "UERY IS CALLED SUB"UERY. THE SUB"UERY (INNER "UERY)E!ECUTES ONCE BEFORE THE MAIN "UERY. THE RESULT OF THE SUB"UERY IS USED BY THE MAIN "UERY(OUTER "UERY). SINGLE%RO+ SUBQUERIES: RETURN ONLY ONE ROW. USE SINGLE ROW COMPARISON OPERATORS I$4$4I$W$WI$W4 SELECT MINIMUM SALARY OF THE EMPLOYEE. SELECT ENAME$JOB$SAL FROM EMP WHERE SAL I (SELECT MIN(SAL) FROM EMP) SELECT MA!IMUM SALARY OF THE EMPLOYEE. SELECT ENAME$JOB$SAL FROM EMP WHERE SAL I (SELECT MA!(SAL) FROM EMP)

S"L4 SELECT MA!(SAL) FROM EMP5 MA!(SAL) &&&&&&&&&& .333 S"L4 SELECT # FROM EMP WHERE SAL I .3335 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 02) 'ING PRESIDENT 10&NOV&21 .333 COMM 13 DEPTNO

S"L4 SELECT # FROM EMP WHERE SAL I (SELECT MA!(SAL) FROM EMP)5 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& COMM DEPTNO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
02) 'ING PRESIDENT 10&NOV&21 .333 13 1# SELECT # FROM EMP WHERE SAL I (SELECT MIN(SAL) FROM EMP) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 NULL *ALUE SUBQUERY: S"L4 SELECT # FROM EMP WHERE JOBI(SELECT JOB FROM EMP WHERE ENAMEICSMYTHEC)5 KD ;DEF F989:<9= )ULTI%RO+ SUBQURIES: SELECT # FROM EMP WHERE SAL I(SELECT SAL FROM EMP)5 WHERE SAL I(SELECT SAL FROM EMP) # ERROR 6< 8NK9 2% ORA&31,20% FNKS89&;DE F?7 P?9;A ;9<?;KF >D;9 <R6K DK9 ;DE RETURN MORE THAN ONE ROW.USE MULTIPLE&ROW COMPARISON OPERATORS. IN " ANY " ALL OPERATORS( SELECT # FROM EMP WHERE SAL IN (SELECT SAL FROM EMP)5 WHICH DISPLAYS ALL THE ROWS OF EMP$ THAT IS IT IS SAME AS SELECT # FROM EMP5 ;ANY OPERATOR AND ; SO)E: SELECT # FROM EMP WHERE SAL I ANY (SELECT SAL FROM EMP)5 HERE GIN IS SAME AS GI ANY AND GI SOME. WHICH DISPLAYS ALL THE ROWS OF EMP. THAT IS GI ANY MEANS GIN S"L4 SELECT # FROM EMP 2 WHERE SAL IN (SELECT SAL FROM EMP)5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 COMM 23 DEPTNO

23

)3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
02) 'ING 1, ;DEF F989:<9=. 1 SELECT # FROM EMP 2# WHERE SAL I ANY (SELECT SAL FROM EMP) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 13 1, ;DEF F989:<9=. 1 SELECT # FROM EMP 2# WHERE SAL I SOME (SELECT SAL FROM EMP) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 13 1, ;DEF F989:<9=. <ANY OR < SO)E OPERATOR: SELECT # FROM EMP WHERE SAL W ANY (SELECT SAL FROM EMP)5 PRESIDENT 10&NOV&21 .333 13

21

)3

)3

< ANY )EANS LESS T.AN T.E )A/I)U)(.ERE )A/ SALARY IS &888( E/CEPT T.AT E*ERY SAL DISPALYED( 1 SELECT # FROM EMP 2# WHERE SAL W ANY (SELECT SAL FROM EMP) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 DEPTNO 23 )3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0.21 WARD 0.// JONES 0/., MARTIN 0/ 2 BLA'E 0022 CLAR' 0022 SCOTT 02,, TURNER 020/ ADAMS 0 33 JAMES 0 32 FORD 0 ), MILLER 1) ;DEF F989:<9=. SALESMAN MANAGER SALESMAN MANAGER MANAGER ANALYST SALESMAN CLER' CLER' ANALYST CLER' 0/ 2 22&FEB&21 02) 32&APR&21 0/ 2 22&SEP&21 02) 31&MAY&21 02) 3 &JUN&21 0.// 1 &APR&20 0/ 2 32&SEP&21 0022 2)&MAY&20 0/ 2 3)&DEC&21 0.// 3)&DEC&21 0022 2)&JAN&22 12.3 2 0. 12.3 22.3 2,.3 )333 1.33 1133 .3 )333 1)33 .33 1,33 )3 23 )3 )3 13 23 )3 23 )3 23 13 3

22

1 SELECT # FROM EMP 2# WHERE SAL W SOME (SELECT SAL FROM EMP) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 1) ;DEF F989:<9=. 6ND .IG.EST: DEPTNO 23 )3 )3 23 )3 )3 13 23 )3 23 )3 23 13

1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MA!(SAL) FROM EMP )# WHERE SAL W ANY (SELECT SAL FROM EMP)) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 =RD .IG.EST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MA!(SAL) FROM EMP ) WHERE SAL W ANY (SELECT SAL FROM EMP , WHERE SAL W ANY (SELECT SAL FROM EMP .# ))) COMM 23 23 DEPTNO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
/ / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0.// JONES MANAGER 02) 32&APR&21 2 0. COMM 23 DEPTNO

2)

'T. .IG.EST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MA!(SAL) FROM EMP ) WHERE SAL W ANY (SELECT SAL FROM EMP , WHERE SAL W ANY (SELECT SAL FROM EMP . WHERE SAL W ANY (SELECT SAL FROM EMP /# )))) 0 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 &T. .IG.EST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MA!(SAL) FROM EMP ) WHERE SAL W ANY (SELECT SAL FROM EMP , WHERE SAL W ANY (SELECT SAL FROM EMP . WHERE SAL W ANY (SELECT SAL FROM EMP / WHERE SAL W ANY (SELECT SAL FROM EMP 0# ))))) 2 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 AND SO ON************** 6ND .IG.EST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MA!(SAL) FROM EMP ) WHERE SAL W SOME (SELECT SAL FROM EMP ,# )) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 COMM 23 23 DEPTNO COMM 13 DEPTNO COMM )3 DEPTNO

=RD .IG.EST: 1 SELECT # FROM EMP

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 WHERE SAL I (SELECT MA!(SAL) FROM EMP ) WHERE SAL W SOME (SELECT SAL FROM EMP , WHERE SAL W SOME (SELECT SAL FROM EMP .# ))) / / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0.// JONES MANAGER 02) 32&APR&21 2 0. 'T. .IG.EST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MA!(SAL) FROM EMP ) WHERE SAL W SOME (SELECT SAL FROM EMP , WHERE SAL W SOME (SELECT SAL FROM EMP . WHERE SAL W SOME (SELECT SAL FROM EMP /# )))) 0 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 &T. .IG.EST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MA!(SAL) FROM EMP ) WHERE SAL W SOME (SELECT SAL FROM EMP , WHERE SAL W SOME (SELECT SAL FROM EMP . WHERE SAL W SOME (SELECT SAL FROM EMP / WHERE SAL W SOME (SELECT SAL FROM EMP 0# ))))) 2 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 >ANY OR > SO)E OPERATOR: SELECT # FROM EMP WHERE SAL 4 ANY (SELECT SAL FROM EMP) 5 4 ANY MEANS MORE THAN THE MINIMUM.HERE MIN SALARY IS 233. E!CEPT THAT EVERY SAL DISPALYED 1 SELECT # FROM EMP 2# WHERE SAL 4 ANY (SELECT SAL FROM EMP) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 DEPTNO )3 )3 23 )3 )3 13 23 13 )3 23 )3 23 13 COMM 13 DEPTNO COMM )3 DEPTNO COMM 23 DEPTNO

2,

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1) ;DEF F989:<9=. 1 SELECT # FROM EMP 2# WHERE SAL 4 SOME (SELECT SAL FROM EMP) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 1) ;DEF F989:<9=. 6ND LEAST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MIN(SAL) FROM EMP )# WHERE SAL 4 ANY (SELECT SAL FROM EMP)) , / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MIN(SAL) FROM EMP )# WHERE SAL 4 SOME (SELECT SAL FROM EMP)) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 =RD LEAST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MIN(SAL) FROM EMP ) WHERE SAL 4 ANY (SELECT SAL FROM EMP , WHERE SAL 4 ANY (SELECT SAL FROM EMP .# ))) / / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 020/ ADAMS CLER' 0022 2)&MAY&20 1133 1 2 ) , SELECT # FROM EMP WHERE SAL I (SELECT MIN(SAL) FROM EMP WHERE SAL 4 SOME (SELECT SAL FROM EMP WHERE SAL 4 SOME (SELECT SAL FROM EMP COMM 23 DEPTNO COMM )3 DEPTNO COMM )3 DEPTNO DEPTNO )3 )3 23 )3 )3 13 23 13 )3 23 )3 23 13

2.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
.# ))) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 020/ ADAMS CLER' 0022 2)&MAY&20 1133 'T. LEAST: COMM 23 DEPTNO

2/

1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MIN(SAL) FROM EMP ) WHERE SAL 4 ANY (SELECT SAL FROM EMP , WHERE SAL 4 ANY (SELECT SAL FROM EMP . WHERE SAL 4 ANY (SELECT SAL FROM EMP /# )))) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MIN(SAL) FROM EMP ) WHERE SAL 4 SOME (SELECT SAL FROM EMP , WHERE SAL 4 SOME (SELECT SAL FROM EMP . WHERE SAL 4 SOME (SELECT SAL FROM EMP /# )))) 0 / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 AND SO ON*************.

<ALL OPERATOR: W ALL MEANS LESS THAN MINIMUM. SELECT # FROM EMP WHERE SAL W ALL (SELECT SAL FROM EMP)5 KD ;DEF F989:<9= S"L4 SELECT # FROM EMP 2 WHERE SAL W ALL (SELECT SAL FROM EMP)5 KD ;DEF F989:<9= S"L4 SELECT # FROM EMP 2 WHERE SAL W ALL (SELECT MA!(SAL) FROM EMP)5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0.// JONES 0/., MARTIN 0/ 2 BLA'E 0022 CLAR' 0022 SCOTT 02,, TURNER 020/ ADAMS 0 33 JAMES 0 32 FORD 0 ), MILLER 1) ;DEF F989:<9=. 6ND .IG.EST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MA!(SAL) FROM EMP )# WHERE SAL W ALL (SELECT MA!(SAL) FROM EMP)) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 COMM 23 23 DEPTNO MANAGER 02) 32&APR&21 2 0. SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 MANAGER 02) 31&MAY&21 22.3 MANAGER 02) 3 &JUN&21 2,.3 ANALYST 0.// 1 &APR&20 )333 SALESMAN 0/ 2 32&SEP&21 1.33 3 CLER' 0022 2)&MAY&20 1133 23 CLER' 0/ 2 3)&DEC&21 .3 ANALYST 0.// 3)&DEC&21 )333 23 CLER' 0022 2)&JAN&22 1)33 23 )3 13 23 )3 )3 13

20

=RD .IG.EST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MA!(SAL) FROM EMP ) WHERE SAL W ALL (SELECT MA!(SAL) FROM EMP , WHERE SAL W ALL (SELECT MA!(SAL) FROM EMP .# ))) / / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0.// JONES MANAGER 02) 32&APR&21 2 0. 'T. .IG.EST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MA!(SAL) FROM EMP ) WHERE SAL W ALL (SELECT MA!(SAL) FROM EMP , WHERE SAL W ALL (SELECT MA!(SAL) FROM EMP . WHERE SAL W ALL (SELECT MA!(SAL) FROM EMP /# )))) 0 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 AND SO ON******* COMM )3 DEPTNO COMM 23 DEPTNO

>ALL OPERATOR: 4 ALL MEANS GREATER THAN MA!IMUM. SELECT # FROM EMP WHERE SAL 4 ALL (SELECT SAL FROM EMP)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
KD ;DEF F989:<9= SELECT # FROM EMP WHERE SAL 4 ALL (SELECT MIN(SAL) FROM EMP)5 HERE E!CEPT MIN SALARY ALL SALARIES DISPLAYS. S"L4 SELECT # FROM EMP 2 WHERE SAL 4 ALL (SELECT SAL FROM EMP)5 KD ;DEF F989:<9=

22

1 SELECT # FROM EMP 2# WHERE SAL 4 ALL (SELECT MIN(SAL) FROM EMP) ) / EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 1) ;DEF F989:<9=. DEPTNO )3 )3 23 )3 )3 13 23 13 )3 23 )3 23 13

6ND LEAST: 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MIN(SAL) FROM EMP )# WHERE SAL 4 ALL (SELECT MIN(SAL) FROM EMP)) S"L4 /

EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )RD LEAST% 1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MIN(SAL) FROM EMP ) WHERE SAL 4 ALL (SELECT MIN(SAL) FROM EMP , WHERE SAL 4 ALL (SELECT MIN(SAL) FROM EMP .# ))) / / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 020/ ADAMS CLER' 0022 2)&MAY&20 1133 'T. LEAST:

COMM )3

DEPTNO

COMM 23

DEPTNO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 SELECT # FROM EMP 2 WHERE SAL I (SELECT MIN(SAL) FROM EMP ) WHERE SAL 4 ALL (SELECT MIN(SAL) FROM EMP , WHERE SAL 4 ALL (SELECT MIN(SAL) FROM EMP . WHERE SAL 4 ALL (SELECT MIN(SAL) FROM EMP /# )))) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 AND SO ON*****. YOU CAN USE SUBQUERY IN FRO) CLAUSE: SELECT # FROM (SELECT # FORM SAL)5 SELECT # FROM (SELECT # FORM SAL ORDER BY SAL DESC )5 S"L4 SELECT # FROM (SELECT # FROM EMP)5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 1, ;DEF F989:<9=. 1# SELECT # FROM (SELECT # FROM EMP ORDER BY SAL DESC ) S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 02) 'ING PRESIDENT 10&NOV&21 .333 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 1, ;DEF F989:<9=.

)3

13

)3

)3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE

JOINS: ORACLE 9I: CARTESIAN PRODUCT: CATERSIAN PRODUCT WILL BE FORMED WHEN EVER WE OMIT THE JOIN CONDITION OR IF YOU DONT WRITE JOIN CONDITIONWHEN WE ARE RETRIVING INFO FROM TWO OR MORE TABLES. HERE WE GET OUTPUT LI'E THIS ALL THE ROWS IN THE FIRST TABLE WILL BE MULTIPLIED BY FIRST ROW IN THE SECOND TABLE$AND ONCE AGAIN ALL ROWS IN THE FIRST TABLE WILL BE MULTIPLIED BY SECOND ROW AND SO ON. WE GET FIRST TABLE NO OF ROWS MULTIPLIED BY SECOND TABLE NO OF ROWS AS OUTPUT. PRIOR TO ORACLE 9I: SELECT ENAME$DNAME FROM EMP$DEPT5 ORACLE 9I: SELECT ENAME$DNAME FROM EMP CROSS JOIN DEPT5 EQUI JOIN IN PRIOR TO ORACLE 9I: WHEN EVER WE DO E"UI JOIN WE GET COMMON INFO WHICH IS THERE IN TWO TABLES. PRIOR TO ORACLE 9I: SELECT EMPNO$ENAME$DEPT.DEPTNO$DNAME$LOC FROM EMP$DEPT WHERE EMP.DEPTNOIDEPT.DEPTNO5 EMPNO ENAME DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 0, ALLEN )3 0.21 WARD )3 0.// JONES 23 0/., MARTIN )3 0/ 2 BLA'E )3 0022 CLAR' 13 0022 SCOTT 23 02) 'ING 13 02,, TURNER )3 020/ ADAMS 23 0 33 JAMES )3 0 32 FORD 23 0 ), MILLER 13 1, ;DEF F989:<9=. DNAME LOC

RESEARCH DALLAS SALES CHICAGO SALES CHICAGO RESEARCH DALLAS SALES CHICAGO SALES CHICAGO ACCOUNTING NEW YOR' RESEARCH DALLAS ACCOUNTING NEW YOR' SALES CHICAGO RESEARCH DALLAS SALES CHICAGO RESEARCH DALLAS ACCOUNTING NEW YOR'

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ORACLE 9I: NATURAL JOIN: THIS IS ALSO E"UI JOIN HERE NO NEED GIVE JOIN CONDITION. S"L4 SELECT EMPNO$ENAME$DEPTNO$DNAME 2 FROM EMP NATURAL JOIN DEPT5 EMPNO ENAME DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& 0)/ SMITH 23 0, ALLEN )3 0.21 WARD )3 0.// JONES 23 0/., MARTIN )3 0/ 2 BLA'E )3 0022 CLAR' 13 0022 SCOTT 23 02) 'ING 13 02,, TURNER )3 020/ ADAMS 23 0 33 JAMES )3 0 32 FORD 23 0 ), MILLER 13 INNER JOIN IN ORACLE 9I SELECT EMPNO$ENAME$EMP.DEPTNO$DNAME$LOC FROM EMP INNER JOIN DEPT ON EMP.DEPTNOIDEPT.DEPTNO 5 EMPNO ENAME DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 0, ALLEN )3 0.21 WARD )3 0.// JONES 23 0/., MARTIN )3 0/ 2 BLA'E )3 0022 CLAR' 13 0022 SCOTT 23 02) 'ING 13 02,, TURNER )3 020/ ADAMS 23 0 33 JAMES )3 0 32 FORD 23 0 ), MILLER 13 1, ;DEF F989:<9=. DNAME LOC DNAME RESEARCH SALES SALES RESEARCH SALES SALES ACCOUNTING RESEARCH ACCOUNTING SALES RESEARCH SALES RESEARCH ACCOUNTING

RESEARCH DALLAS SALES CHICAGO SALES CHICAGO RESEARCH DALLAS SALES CHICAGO SALES CHICAGO ACCOUNTING NEW YOR' RESEARCH DALLAS ACCOUNTING NEW YOR' SALES CHICAGO RESEARCH DALLAS SALES CHICAGO RESEARCH DALLAS ACCOUNTING NEW YOR'

JOIN%USING: S"L4 SELECT E.EMPNO$E.ENAME$D.LOC FROM 2 EMP E JOIN DEPT D ) USING(DEPTNO)5 EMPNO ENAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0)/ SMITH 0, ALLEN 0.21 WARD 0.// JONES 0/., MARTIN 0/ 2 BLA'E 0022 CLAR' 0022 SCOTT 02) 'ING 02,, TURNER 020/ ADAMS 0 33 JAMES 0 32 FORD 0 ), MILLER DALLAS CHICAGO CHICAGO DALLAS CHICAGO CHICAGO NEW YOR' DALLAS NEW YOR' CHICAGO DALLAS CHICAGO DALLAS NEW YOR'

+IT.OUT ALIASING: 1 SELECT EMPNO$ENAME$LOC FROM 2 EMP JOIN DEPT )# USING(DEPTNO) , / EMPNO ENAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH DALLAS 0, ALLEN CHICAGO 0.21 WARD CHICAGO 0.// JONES DALLAS 0/., MARTIN CHICAGO 0/ 2 BLA'E CHICAGO 0022 CLAR' NEW YOR' 0022 SCOTT DALLAS 02) 'ING NEW YOR' 02,, TURNER CHICAGO 020/ ADAMS DALLAS 0 33 JAMES CHICAGO 0 32 FORD DALLAS 0 ), MILLER NEW YOR'

1 SELECT EMPNO$ENAME$DEPTNO$DNAME$LOC FROM 2 EMP JOIN DEPT )# USING(DEPTNO) S"L4 / EMPNO ENAME DEPTNO DNAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 RESEARCH 0, ALLEN )3 SALES 0.21 WARD )3 SALES 0.// JONES 23 RESEARCH 0/., MARTIN )3 SALES 0/ 2 BLA'E )3 SALES 0022 CLAR' 13 ACCOUNTING 0022 SCOTT 23 RESEARCH 02) 'ING 13 ACCOUNTING 02,, TURNER )3 SALES 020/ ADAMS 23 RESEARCH 0 33 JAMES )3 SALES 0 32 FORD 23 RESEARCH 0 ), MILLER 13 ACCOUNTING JOIN , ON: LOC DALLAS CHICAGO CHICAGO DALLAS CHICAGO CHICAGO NEW YOR' DALLAS NEW YOR' CHICAGO DALLAS CHICAGO DALLAS NEW YOR'

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECT EMPNO$ENAME$EMP.DEPTNO$DNAME$LOC FROM EMP JOIN DEPT ON EMP.DEPTNOIDEPT.DEPTNO S"L4 / EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 RESEARCH DALLAS 0, ALLEN )3 SALES CHICAGO 0.21 WARD )3 SALES CHICAGO 0.// JONES 23 RESEARCH DALLAS 0/., MARTIN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0022 CLAR' 13 ACCOUNTING NEW YOR' 0022 SCOTT 23 RESEARCH DALLAS 02) 'ING 13 ACCOUNTING NEW YOR' 02,, TURNER )3 SALES CHICAGO 020/ ADAMS 23 RESEARCH DALLAS 0 33 JAMES )3 SALES CHICAGO 0 32 FORD 23 RESEARCH DALLAS 0 ), MILLER 13 ACCOUNTING NEW YOR'

RIG.T OUTER JOIN: IN ORACLE 9I IN RIGHT OUTER JOIN WE GET THE E!TRA INFORMATION IN DEPT. THAT IS DEPTNOI,3.BECAUSE NO BODY WOR'ING IN DEPTNO ,3. WHEN EVER WE DO E"UI JOIN WE GET COMMON INFO WHICH IS THERE IN TWO TABLES. SELECT EMPNO$ENAME$EMP.DEPTNO$DNAME$LOC FROM EMP RIGHT OUTER JOIN DEPT ON EMP.DEPTNOIDEPT.DEPTNO5 EMPNO ENAME DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 0, ALLEN )3 0.21 WARD )3 0.// JONES 23 0/., MARTIN )3 0/ 2 BLA'E )3 0022 CLAR' 13 0022 SCOTT 23 02) 'ING 13 02,, TURNER )3 020/ ADAMS 23 0 33 JAMES )3 0 32 FORD 23 0 ), MILLER 13 1. ;DEF F989:<9=. DNAME LOC

RESEARCH DALLAS SALES CHICAGO SALES CHICAGO RESEARCH DALLAS SALES CHICAGO SALES CHICAGO ACCOUNTING NEW YOR' RESEARCH DALLAS ACCOUNTING NEW YOR' SALES CHICAGO RESEARCH DALLAS SALES CHICAGO RESEARCH DALLAS ACCOUNTING NEW YOR' OPERATIONS BOSTON

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECT EMPNO$ENAME$DEPT.DEPTNO$DNAME$LOC FROM EMP RIGHT OUTER JOIN DEPT ON EMP.DEPTNOIDEPT.DEPTNO5 EMPNO ENAME DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 0, ALLEN )3 0.21 WARD )3 0.// JONES 23 0/., MARTIN )3 0/ 2 BLA'E )3 0022 CLAR' 13 0022 SCOTT 23 02) 'ING 13 02,, TURNER )3 020/ ADAMS 23 0 33 JAMES )3 0 32 FORD 23 0 ), MILLER 13 ,3 1. ;DEF F989:<9=. RIG.T OUTER JOIN IN PRIOR TO ORACLE 9I SELECT EMPNO$ENAME$EMP2.DEPTNO$DNAME$LOC FROM EMP2$DEPT WHERE EMP2.DEPTNO(J)IDEPT.DEPTNO5 EMPNO ENAME DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 0, ALLEN )3 0.21 WARD )3 0.// JONES 23 0/., MARTIN )3 0/ 2 BLA'E )3 0022 CLAR' 13 0022 SCOTT 23 02) 'ING 13 02,, TURNER )3 020/ ADAMS 23 0 33 JAMES )3 0 32 FORD 23 0 ), MILLER 13 DNAME LOC DNAME LOC

RESEARCH DALLAS SALES CHICAGO SALES CHICAGO RESEARCH DALLAS SALES CHICAGO SALES CHICAGO ACCOUNTING NEW YOR' RESEARCH DALLAS ACCOUNTING NEW YOR' SALES CHICAGO RESEARCH DALLAS SALES CHICAGO RESEARCH DALLAS ACCOUNTING NEW YOR' OPERATIONS BOSTON

RESEARCH DALLAS SALES CHICAGO SALES CHICAGO RESEARCH DALLAS SALES CHICAGO SALES CHICAGO ACCOUNTING NEW YOR' RESEARCH DALLAS ACCOUNTING NEW YOR' SALES CHICAGO RESEARCH DALLAS SALES CHICAGO RESEARCH DALLAS ACCOUNTING NEW YOR'

OPERATIONS 1. ;DEF F989:<9=. 1 SELECT EMPNO$ENAME$DEPT.DEPTNO$DNAME$LOC 2 FROM EMP2$DEPT )# WHERE EMP2.DEPTNO(J)IDEPT.DEPTNO5 EMPNO ENAME DEPTNO DNAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 RESEARCH 0, ALLEN )3 SALES

BOSTON

LOC DALLAS CHICAGO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0.21 WARD 0.// JONES 0/., MARTIN 0/ 2 BLA'E 0022 CLAR' 0022 SCOTT 02) 'ING 02,, TURNER 020/ ADAMS 0 33 JAMES 0 32 FORD 0 ), MILLER )3 23 )3 )3 13 23 13 )3 23 )3 23 13 SALES CHICAGO RESEARCH DALLAS SALES CHICAGO SALES CHICAGO ACCOUNTING NEW YOR' RESEARCH DALLAS ACCOUNTING NEW YOR' SALES CHICAGO RESEARCH DALLAS SALES CHICAGO RESEARCH DALLAS ACCOUNTING NEW YOR'

,3 1. ;DEF F989:<9=. LEFT OUTER JOIN: IN ORACLE 9I

OPERATIONS

BOSTON

IN THE ABOVE "UERY NO E!TRA ROWS WERE SELECTED BECAUSE THERE NO BODY WHO IS WOR'ING OTHER THAN DEPTNOS WHICH ARE THERE IN DEPT TABLE. THAT IS BECAUSE OF FOREIGN 'EY. SELECT EMPNO$ENAME$DEPT.DEPTNO$DNAME$LOC FROM EMP LEFT OUTER JOIN DEPT ON EMP.DEPTNOIDEPT.DEPTNO5 EMPNO ENAME DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 0, ALLEN )3 0.21 WARD )3 0.// JONES 23 0/., MARTIN )3 0/ 2 BLA'E )3 0022 CLAR' 13 0022 SCOTT 23 02) 'ING 13 02,, TURNER )3 020/ ADAMS 23 0 33 JAMES )3 0 32 FORD 23 0 ), MILLER 13 1, ;DEF F989:<9=. DNAME LOC

RESEARCH DALLAS SALES CHICAGO SALES CHICAGO RESEARCH DALLAS SALES CHICAGO SALES CHICAGO ACCOUNTING NEW YOR' RESEARCH DALLAS ACCOUNTING NEW YOR' SALES CHICAGO RESEARCH DALLAS SALES CHICAGO RESEARCH DALLAS ACCOUNTING NEW YOR'

HERE WE CREATE EMP2 TABLE AND INSERT .3$/3$03 VALUES IN TO THE TABLE. S"L4 CREATE TABLE EMP2 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=.

S"L4 SELECT # FROM EMP25 EMPNO ENAMEJOB MGR HIREDATE SAL COMM DEPTNO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
&&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 1, ;DEF F989:<9=. S"L4 INSERT INTO EMP2 2 VALUES ) (1$CPAVANC$CMANAGERC$12)$C31&DEC&3.C$1333$133$.3)5 1 ;DE :;96<9=. 1 INSERT INTO EMP2 2 VALUES )# (2$C'UMARC$CMANAGERC$12)$C31&DEC&3.C$1333$133$/3)5 1 ;DE :;96<9=. 1 INSERT INTO EMP2 2 VALUES )# ()$CGAYATRIC$CMANAGERC$12)$C31&DEC&3.C$1333$133$03)5 1 ;DE :;96<9=. 23 )3 )3 23 )3 )3 13 23 13 )3 23 )3 23 13

SELECT EMPNO$ENAME$EMP2.DEPTNO$DNAME$LOC FROM EMP2 LEFT OUTER JOIN DEPT ON EMP2.DEPTNOIDEPT.DEPTNO5 EMPNO ENAME DEPTNO DNAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 0, ALLEN )3 0.21 WARD )3 0.// JONES 23 0/., MARTIN )3 0/ 2 BLA'E )3 0022 CLAR' 13 0022 SCOTT 23 02) 'ING 13 02,, TURNER )3 020/ ADAMS 23 0 33 JAMES )3 0 32 FORD 23 0 ), MILLER 13 1 PAVAN .3 2 'UMAR /3 ) GAYATRI 03 LOC RESEARCH DALLAS SALES CHICAGO SALES CHICAGO RESEARCH DALLAS SALES CHICAGO SALES CHICAGO ACCOUNTING NEW YOR' RESEARCH DALLAS ACCOUNTING NEW YOR' SALES CHICAGO RESEARCH DALLAS SALES CHICAGO RESEARCH DALLAS ACCOUNTING NEW YOR'

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
LEFT OUTER JOIN IN PRIOR TO ORACLE 9I 1 SELECT EMPNO$ENAME$EMP2.DEPTNO$DNAME$LOC 2 FROM EMP2$DEPT )# WHERE EMP2.DEPTNOIDEPT.DEPTNO(J) EMPNO ENAME DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 0, ALLEN )3 0.21 WARD )3 0.// JONES 23 0/., MARTIN )3 0/ 2 BLA'E )3 0022 CLAR' 13 0022 SCOTT 23 02) 'ING 13 02,, TURNER )3 020/ ADAMS 23 0 33 JAMES )3 0 32 FORD 23 0 ), MILLER 13 1 PAVAN 2 'UMAR ) GAYATRI 10 ;DEF F989:<9=. .3 /3 03 DNAME LOC

RESEARCH DALLAS SALES CHICAGO SALES CHICAGO RESEARCH DALLAS SALES CHICAGO SALES CHICAGO ACCOUNTING NEW YOR' RESEARCH DALLAS ACCOUNTING NEW YOR' SALES CHICAGO RESEARCH DALLAS SALES CHICAGO RESEARCH DALLAS ACCOUNTING NEW YOR'

FULL OUTER JOIN: IN ORACLE 9I SELECT EMPNO$ENAME$EMP2.DEPTNO$DNAME$LOC FROM EMP2 FULL OUTER JOIN DEPT ON EMP2.DEPTNOIDEPT.DEPTNO5 EMPNO ENAME DEPTNO DNAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 0, ALLEN )3 0.21 WARD )3 0.// JONES 23 0/., MARTIN )3 0/ 2 BLA'E )3 0022 CLAR' 13 0022 SCOTT 23 02) 'ING 13 02,, TURNER )3 020/ ADAMS 23 0 33 JAMES )3 0 32 FORD 23 0 ), MILLER 13 1 PAVAN .3 2 'UMAR /3 ) GAYATRI 03 LOC RESEARCH DALLAS SALES CHICAGO SALES CHICAGO RESEARCH DALLAS SALES CHICAGO SALES CHICAGO ACCOUNTING NEW YOR' RESEARCH DALLAS ACCOUNTING NEW YOR' SALES CHICAGO RESEARCH DALLAS SALES CHICAGO RESEARCH DALLAS ACCOUNTING NEW YOR'

OPERATIONS 12 ;DEF F989:<9=.

BOSTON

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECT EMPNO$ENAME$EMP2.DEPTNO$DEPT.DEPTNO$DNAME$LOC FROM EMP2 FULL OUTER JOIN DEPT ON EMP2.DEPTNOIDEPT.DEPTNO EMPNO ENAME DEPTNO DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0 ), MILLER 13 13 ACCOUNTING NEW YOR' 02) 'ING 13 13 ACCOUNTING NEW YOR' 0022 CLAR' 13 13 ACCOUNTING NEW YOR' 0 32 FORD 23 23 RESEARCH DALLAS 020/ ADAMS 23 23 RESEARCH DALLAS 0022 SCOTT 23 23 RESEARCH DALLAS 0.// JONES 23 23 RESEARCH DALLAS 0)/ SMITH 23 23 RESEARCH DALLAS 0 33 JAMES )3 )3 SALES CHICAGO 02,, TURNER )3 )3 SALES CHICAGO 0/ 2 BLA'E )3 )3 SALES CHICAGO 0/., MARTIN )3 )3 SALES CHICAGO 0.21 WARD )3 )3 SALES CHICAGO 0, ALLEN )3 )3 SALES CHICAGO 1 PAVAN .3 2 'UMAR /3 ) GAYATRI 03 ,3 OPERATIONS BOSTON 12 ;DEF F989:<9=. FULL OUTER JOIN IN PRIOR TO ORACLE 9I

S"L4 SELECT EMPNO$ENAME$DEPT.DEPTNO$DNAME$LOC 2 FROM EMP2$DEPT ) WHERE EMP2.DEPTNO(J)IDEPT.DEPTNO , UNION . SELECT EMPNO$ENAME$EMP2.DEPTNO$DNAME$LOC / FROM EMP2$DEPT 0 WHERE EMP2.DEPTNOIDEPT.DEPTNO(J)5 EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 1 PAVAN .3 2 'UMAR /3 ) GAYATRI 03 0)/ SMITH 23 RESEARCH DALLAS 0, ALLEN )3 SALES CHICAGO 0.21 WARD )3 SALES CHICAGO 0.// JONES 23 RESEARCH DALLAS 0/., MARTIN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0022 CLAR' 13 ACCOUNTING NEW YOR' 0022 SCOTT 23 RESEARCH DALLAS 02) 'ING 13 ACCOUNTING NEW YOR' 02,, TURNER )3 SALES CHICAGO 020/ ADAMS 23 RESEARCH DALLAS 0 33 JAMES )3 SALES CHICAGO 0 32 FORD 23 RESEARCH DALLAS 0 ), MILLER 13 ACCOUNTING NEW YOR'

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
,3 OPERATIONS 12 ;DEF F989:<9=. BOSTON 1 SELECT EMPNO$ENAME$DEPT.DEPTNO D(DEPTNO$EMP2.DEPTNO E(DEPTNO$ DNAME$LOC 2 FROM EMP2$DEPT ) WHERE EMP2.DEPTNO(J)IDEPT.DEPTNO , UNION . SELECT EMPNO$ENAME$DEPT.DEPTNO D(DEPTNO$ EMP2.DEPTNO E(DEPTNO$DNAME$LOC / FROM EMP2$DEPT 0 WHERE EMP2.DEPTNOIDEPT.DEPTNO(J) EMPNO ENAME D(DEPTNO E(DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 1 PAVAN .3 2 'UMAR /3 ) GAYATRI 03 0)/ SMITH 23 23 RESEARCH DALLAS 0, ALLEN )3 )3 SALES CHICAGO 0.21 WARD )3 )3 SALES CHICAGO 0.// JONES 23 23 RESEARCH DALLAS 0/., MARTIN )3 )3 SALES CHICAGO 0/ 2 BLA'E )3 )3 SALES CHICAGO 0022 CLAR' 13 13 ACCOUNTING NEW YOR' 0022 SCOTT 23 23 RESEARCH DALLAS 02) 'ING 13 13 ACCOUNTING NEW YOR' 02,, TURNER )3 )3 SALES CHICAGO 020/ ADAMS 23 23 RESEARCH DALLAS 0 33 JAMES )3 )3 SALES CHICAGO 0 32 FORD 23 23 RESEARCH DALLAS 0 ), MILLER 13 13 ACCOUNTING NEW YOR' ,3 12 ;DEF F989:<9=. OPERATIONS BOSTON

SELF JOIN: 1 SELECT W.EMPNO$W.ENAME$M.EMPNO$M.ENAME FROM 2 EMP W$ EMP M )# WHERE W.MGRIM.EMPNO S"L4 / EMPNO ENAME EMPNO ENAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH 0 32 FORD

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0, ALLEN 0.21 WARD 0.// JONES 0/., MARTIN 0/ 2 BLA'E 0022 CLAR' 0022 SCOTT 02,, TURNER 020/ ADAMS 0 33 JAMES 0 32 FORD 0 ), MILLER 0/ 2 BLA'E 0/ 2 BLA'E 02) 'ING 0/ 2 BLA'E 02) 'ING 02) 'ING 0.// JONES 0/ 2 BLA'E 0022 SCOTT 0/ 2 BLA'E 0.// JONES 0022 CLAR'

133

JOIN %ON 1 SELECT W.EMPNO$W.ENAME$M.EMPNO$M.ENAME FROM 2 EMP W JOIN EMP M )# ON W.MGRIM.EMPNO , / EMPNO ENAME EMPNO ENAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH 0 32 FORD 0, ALLEN 0/ 2 BLA'E 0.21 WARD 0/ 2 BLA'E 0.// JONES 02) 'ING 0/., MARTIN 0/ 2 BLA'E 0/ 2 BLA'E 02) 'ING 0022 CLAR' 02) 'ING 0022 SCOTT 0.// JONES 02,, TURNER 0/ 2 BLA'E 020/ ADAMS 0022 SCOTT 0 33 JAMES 0/ 2 BLA'E 0 32 FORD 0.// JONES 0 ), MILLER 0022 CLAR'

SEQUENCES:

DEFINE A SE"UENCE TO GENERATE SE"UENTIAL NUMBERS AUTOMATICALLY. WHAT IS A SE"UENCE@ A SEQUENCE:

AUTOMATICALLY GENERATES UNI"UE NUMBERS. IS A SHARABLE OBJECT.(MULTIPLE USERS CAN SHARE SE"UENCE BECAUSE SE"UENCE NUMBERS ARE STORED AND GENERATED INDEPENDENTLY OF TABLES.)

IT IS TYPICALLY USED TO CREATE A PRIMARY 'EY VALUE. REPLACES APPLICATION CODE.(THIS IS TIME SAVING OBJECT BECAUSE IT CAN REDUCE THE AMOUNT OF APPLICATION CODE NEEDED TO WRITE A SE"UENCE&GENERATING ROUTINE).

SPEEDS UP THE EFFICIENCY OF ACCESSING SE"UENCE VALUES WHEN CACHED IN MEMORY.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CREATE SE"UENCE SE"UENCE(NAME [INCREMENT BY N\ [START WITH N\ []MA!VALUE N V NOMA!VALUE^\ []MINVALUE N V NOMINVALUE^\ []CYCLE V NOCYCLE^\ []CACHE N V NOCACHE^\5

131

IN SYNTA/: SE"UENCE(NAME INCREMENT BY N STARTWITH N MA!VALUE N NOMA!VALUE MINVALUE N NOMINVALUE CYCLE V NOCYCLE CACHE N V NO CACHE SE"UENCE NAME SPECIFIES THE INTERVAL BETWEEN SE"UENCE NUMBERS WHERE N IS AN INTEGER.(IF THIS CLAUSE IS OMMITED $ THE SE"UENCE INCREMENTS BY 1.) SPECIFIES THE FIRST SE"UENCE NUMBER TO BE GENERATED. (IF THIS CLAUSE IS OMMITED $ THE SE"UENCE STARTS WITH 1.) SPECIFIES MA!VALUE THE SE"UENCE CAN GENERATE. SPECIFIES A MA!IMUM VALUE OF 13 _ 20 FOR ASENDING SE"UENCE AND &1 FOR DESENDING SE"UENCE.(THIS IS DEFAULT OPTION) SPECIFIES MINVALUE THE SE"UENCE CAN GENERATE. SPECIFIES A MA!IMUM VALUE OF 1 FOR AN ASCENDING SE"UENCE AND &1 FOR DESCENDING SE"UENCE.(THIS IS DEFAULT OPTION) SPECIFIES WHETHER THE SE"UENCE CONTINUES TO GENERATE VALUE AFTER REACHING ITS MA!IMUM OR MINIMUM VALUE(NO CYCLE IS DEFAULT OPTION) SPECIFIES HOW MANY VALUES THE ORACLE SERVER PREALLOCATES AND 'EEP IN MEMORY.(BY DEFAULT ORACLE SERVER CACHES 23 VALUES)

CREATION OF SEQUENCE:

S"L4 CREATE SE"UENCE DEPT(DUP(SE" 2 INCREMENT BY 13 ) START WITH 13 , MA!VALUE 133 . NOCACHE / NOCYCLE5 S9P?9K:9 :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM USER(SE"UENCES5 SE"UENCE(NAME MIN(VALUE MA!(VALUE INCREMENT(BY C O CACHE(SIZE LAST(NUMBER &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&& & & &&&&&&&&&& &&&&&&&&&&& DEPT(DUP(SE" 1 133 13 NN 3 13 NE/T*AL AND CURR*AL PSEUDOCOLU)NS?

132

1# SELECT DEPT(DUP(SE".CURRVAL FROM DUAL S"L4 / SELECT DEPT(DUP(SE".CURRVAL FROM DUAL # ERROR 6< 8NK9 1% ORA&32332% F9P?9K:9 DEPT(DUP(SE".CURRVAL NF KD< A9< =9TNK9= NK <RNF F9FFNDK INSERTING THE VALUES OF SE"UENCES IN TO THE TABLE% S"L4 INSERT INTO DEPT(DUP 2 VALUES ) (DEPT(DUP(SE".NE!TVAL$CCOMC$CNYC)5 1 ;DE :;96<9=. 1 INSERT INTO DEPT(DUP 2 VALUES )# (DEPT(DUP(SE".NE!TVAL$CSALESC$CNYC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO DEPT(DUP 2 VALUES )# (DEPT(DUP(SE".NE!TVAL$COPRC$CNYC) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT # FROM DEPT(DUP5 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 COM NY 23 SALES NY )3 OPR NY S"L4 SELECT DEPT(DUP(SE".CURRVAL FROM DUAL5 CURRVAL &&&&&&&&&& )3 *IE+ING SEQUENCES IN DATABASE:

S"L4 SELECT # FROM USER(SE"UENCES5 SE"UENCE(NAME MIN(VALUE MA!(VALUE INCREMENT(BY C O CACHE(SIZE LAST(NUMBER &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&& & & &&&&&&&&&& &&&&&&&&&&& DEPT(DUP(SE" 1 133 13 NN 3 ,3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
HERE IN LAST(NUMBER COLUMN WE CAN SEE NE!T AVALIABLE NUMBER. DONCT SEE NE!T AVALIABLE NUMBER BY SELECTING LI'E THIS SELECT DEPT(DUP(SE".NE!TVAL FROM DUAL5 NE!TVAL &&&&&&&&&& ,3 S"L4 INSERT INTO DEPT(DUP 2 VALUES ) (DEPT(DUP(SE".NE!TVAL$CAAC$CNYC)5 1 ;DE :;96<9=. S"L4 SELECT # FROM DEPT(DUP5 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 COM NY 23 SALES NY )3 OPR NY .3 AA NY

13)

HERE WE ARE SUPPOSED TO GET ,3 BUT WE GOT .3. THAT MEANS WHEN WE SAW NE!T AVALIABLE NUMBER BY USING SE"UENCE(NAME.NE!TVAL. IT GENERATED THAT NUMBER.IT CANNOT BE REVO'ED BAC'.IT IS ALWAYS ADVISED TO SEE NE!T AVALIABLE NUMBER IN USER(SE"UENCES TABLES LAST(NUMBER COLUMN. 1# SELECT DEPT(DUP(SE".NE!TVAL FROM DUAL S"L4 / NE!TVAL &&&&&&&&&& /3 S"L4 / NE!TVAL &&&&&&&&&& 03 S"L4 / NE!TVAL &&&&&&&&&& 23 S"L4 / NE!TVAL &&&&&&&&&& 3 S"L4 / NE!TVAL &&&&&&&&&& 133 S"L4 / SELECT DEPT(DUP(SE".NE!TVAL FROM DUAL # ERROR 6< 8NK9 1% ORA&3233,% F9P?9K:9 DEPT(DUP(SE".NE!TVAL 9U:99=F MA!VALUE 6K= :6KKD< 79 NKF<6K<N6<9=

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
HERE SE"UENCE REACHED MA!VALUE.IT CANNOT GENERATE NUMBER. WE CAN ALTER SE"UENCE ALTERING A SE"UENCE% S"L4 ALTER SE"UENCE DEPT(DUP(SE" 2 MA!VALUE 1.35 S9P?9K:9 68<9;9=. S"L4 SELECT DEPT(DUP(SE".NE!TVAL FROM DUAL5 NE!TVAL &&&&&&&&&& 113 S"L4 SELECT # FROM USER(SE"UENCES5 SE"UENCE(NAME MIN(VALUE MA!(VALUE INCREMENT(BY C O CACHE(SIZE LAST(NUMBER &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&& & & &&&&&&&&&& &&&&&&&&&&& DEPT(DUP(SE" 1 1.3 13 NN 3 A123 WE CAN CHANGE INCREMENT VALUE$MA!VALUE$MINVALUE$CYCLE$CACHE OPTIONS IN ALTER. WE CANNOT CHNAGE START WITH OPTION IN ALTER.TO START SE"UENCE WITH NEW NUMBER IT SHOULD BE DROPPED AND RECREATED. SOME VALIDATION IS IMPOSED WHEN ALTER A SE"UENCE. S"L4 ALTER SE"UENCE DEPT(DUP(SE" 2 MA!VALUE 1335 ALTER SE"UENCE DEPT(DUP(SE" # ERROR 6< 8NK9 1% ORA&3,33 % MA!VALUE :6KKD< 79 >6=9 <D 79 89FF <R6K <R9 :?;;9K< Q68?9 S"L4 ALTER SE"UENCE DEPT(DUP(SE" 2 CYCLE5 S9P?9K:9 68<9;9=. 1# SELECT DEPT(DUP(SE".NE!TVAL FROM DUAL S"L4 / NE!TVAL &&&&&&&&&& 123 S"L4 SELECT # FROM USER(SE"UENCES5 SE"UENCE(NAME MIN(VALUE MA!(VALUE INCREMENT(BY C O CACHE(SIZE LAST(NUMBER &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&& & & &&&&&&&&&& &&&&&&&&&&& DEPT(DUP(SE" 1 1.3 13 YN 3 1)3 S"L4 SELECT DEPT(DUP(SE".NE!TVAL FROM DUAL5 NE!TVAL &&&&&&&&&& 1)3 S"L4 / NE!TVAL

13,

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
&&&&&&&&&& 1,3 S"L4 / NE!TVAL &&&&&&&&&& 1.3 S"L4 / NE!TVAL &&&&&&&&&& 1 S"L4 / NE!TVAL &&&&&&&&&& 11 HERE BECAUSE OF CYCLE OPTION WE GOT NUMBER FROM MINVALUE OF THE SE"UENCE. S"L4 CREATE SE"UENCE DEPT(DUP(SE"1 2 INCREMENT BY 1 ) START WITH 133 , CACHE )35 S9P?9K:9 :;96<9=. S"L4 SELECT # FROM USER(SE"UENCES5 SE"UENCE(NAME MIN(VALUE MA!(VALUE INCREMENT(BY C O CACHE(SIZE LAST(NUMBER &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&& & & &&&&&&&&&& &&&&&&&&&&& DEPT(DUP(SE"1 1 1.3333EJ20 1 NN )3 133 1# SELECT DEPT(DUP(SE"1.NE!TVAL FROM DUAL 2 / NE!TVAL &&&&&&&&&& 133

13.

S"L4 SELECT # FROM USER(SE"UENCES5 SE"UENCE(NAME MIN(VALUE MA!(VALUE INCREMENT(BY C O CACHE(SIZE LAST(NUMBER &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&& & & &&&&&&&&&& &&&&&&&&&&& DEPT(DUP(SE"1 1 1.3333EJ20 1 NN )3 1)3 HERE U CANNOT DEPEND ON LAST(NUMBER COLUMN FOR NE!T NUMBER. DROPING SE"UENCES% S"L4 DROP SE"UENCE DEPT(DUP(SE"1 S9P?9K:9 =;DBB9=. HERE CACHE MEANS ORACLE 'EEPS )3 VALUES IN THE CACHE MEMORY.DEFAULT IS 23.CYCLE MEANS IF THE NUMBER GENERATES MA! NUMBER THEN ONCE AGAIN IT START FROM MIN VALUE. CREATING SEQUENCE +IT.OUT ANY PARA)ETERS:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 CREATE SE"UENCE DEPT(DEPT25 S9P?9K:9 :;96<9=. ORACLE FUNCTIONS: S"L4 SELECT ABS(&23) FROM DUAL5 ABS(&23) &&&&&&&&&& 23 S"L4 SELECT POWER()$2) FROM DUAL5 POWER()$2) &&&&&&&&&& S"L4 SELECT ROUND(1..1 $1) FROM DUAL5 ROUND(1..1 $1) &&&&&&&&&&&&&& 1..2 S"L4 SELECT S"RT(2.) FROM DUAL5 S"RT(2.) &&&&&&&&&& . 1 SELECT E!TRACT(YEAR FROM DATE C233,&30&32C) OYEARO$ 2# E!TRACT(MONTH FROM DATE C233,&30&32C)OMONTHO FROM DUAL S"L4 / YEAR MONTH &&&&&&&&&& &&&&&&&&&& 233, 0 S"L4 SELECT MOD(1.$0) OMOD1O$MOD(1..0$0) OMOD2O FROM DUAL5 MOD1 MOD2 &&&&&&&&&& &&&&&&&&&& 1 1.0 S"L4 SELECT FLOOR(2,.2)$FLOOR(1).1.) FROM DUAL5 FLOOR(2,.2) FLOOR(1).1.) &&&&&&&&&&& &&&&&&&&&&&& 2, 1) S"L4 SELECT CEIL(2,.2)$CEIL(1).1.) FROM DUAL5 CEIL(2,.2) CEIL(1).1.) &&&&&&&&&& &&&&&&&&&&& 2. 1, S"L4 SELECT TRANSLATE(C1PAVAV.2)C$C12)C$C0A C) FROM DUAL5 TRANSLATE &&&&&&&&& 0PAVAV.A S"L4 SELECT LENGTH(CPAVANC) FROM DUAL5

13/

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
LENGTH(CPAVANC) &&&&&&&&&&&&&&& . S"L4 SELECT LTRIM(CNISHAC$CNC) FROM DUAL5 LTRI &&&& ISHA S"L4 SELECT RTRIM(CNISHAC$CAC) FROM DUAL5 RTRI &&&& NISH S"L4 SELECT TRIM(C PAVAN C) FROM DUAL5 TRIM( &&&&& PAVAN S"L4 SELECT TRIM(LEADING C!C FROM C!!!HANSEL!!!C) FROM DUAL5 TRIM(LEAD &&&&&&&&& HANSEL!!! S"L4 SELECT TRIM(BOTH C!C FROM C!!!HANSEL!!!C) FROM DUAL5 TRIM(B &&&&&& HANSEL S"L4 SELECT TRIM(BOTH C1C FROM C12)HANSEL12111C) FROM DUAL5 TRIM(BOTHC &&&&&&&&&& 2)HANSEL12 S"L4 SELECT LPAD(CPAGE 1C$13$C#C) OLPADO FROM DUAL5 LPAD &&&&&&&&&& ####PAGE 1 S"L4 SELECT RPAD(ENAME$13$C!C) ORPADO FROM EMP WHERE ENAME I CSMITHC5 RPAD &&&&&&&&&& SMITH!!!!! S"L4 SELECT ROUND(,.. 2)$2)$ROUND(,.. 2)$3)$ROUND(,.. 2)$&1) FROM DUAL5 ROUND(,.. 2)$2) ROUND(,.. 2)$3) ROUND(,.. 2)$&1) &&&&&&&&&&&&&&& &&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& ,.. 2 ,/ .3 S"L4 SELECT TRUNC(,.. 2)$2)$TRUNC(,.. 2)$3)$TRUNC(,.. 2)$&1) FROM DUAL5 TRUNC(,.. 2)$2) TRUNC(,.. 2)$3) TRUNC(,.. 2)$&1) &&&&&&&&&&&&&&& &&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& ,.. 2 ,. ,3 S"L4 SELECT HIREDATE$ROUND(HIREDATE$CMONTHC)$TRUNC(HIREDATE$CMONTHC) FROM EMP5

130

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
HIREDATE ROUND(HIR TRUNC(HIR &&&&&&&&& &&&&&&&&& &&&&&&&&& 10&DEC&23 31&JAN&21 31&DEC&23 23&FEB&21 31&MAR&21 31&FEB&21 22&FEB&21 31&MAR&21 31&FEB&21 32&APR&21 31&APR&21 31&APR&21 22&SEP&21 31&OCT&21 31&SEP&21 31&MAY&21 31&MAY&21 31&MAY&21 3 &JUN&21 31&JUN&21 31&JUN&21 1 &APR&20 31&MAY&20 31&APR&20 10&NOV&21 31&DEC&21 31&NOV&21 32&SEP&21 31&SEP&21 31&SEP&21 2)&MAY&20 31&JUN&20 31&MAY&20 3)&DEC&21 31&DEC&21 31&DEC&21 3)&DEC&21 31&DEC&21 31&DEC&21 2)&JAN&22 31&FEB&22 31&JAN&22 1, ;DEF F989:<9=.

132

S"L4 SELECT HIREDATE$ROUND(HIREDATE$CYEARC)$TRUNC(HIREDATE$CYEARC) FROM EMP5 HIREDATE ROUND(HIR TRUNC(HIR &&&&&&&&& &&&&&&&&& &&&&&&&&& 10&DEC&23 31&JAN&21 31&JAN&23 23&FEB&21 31&JAN&21 31&JAN&21 22&FEB&21 31&JAN&21 31&JAN&21 32&APR&21 31&JAN&21 31&JAN&21 22&SEP&21 31&JAN&22 31&JAN&21 31&MAY&21 31&JAN&21 31&JAN&21 3 &JUN&21 31&JAN&21 31&JAN&21 1 &APR&20 31&JAN&20 31&JAN&20 10&NOV&21 31&JAN&22 31&JAN&21 32&SEP&21 31&JAN&22 31&JAN&21 2)&MAY&20 31&JAN&20 31&JAN&20 3)&DEC&21 31&JAN&22 31&JAN&21 3)&DEC&21 31&JAN&22 31&JAN&21 2)&JAN&22 31&JAN&22 31&JAN&22 1, ;DEF F989:<9=. TO2NU)BER: CONVERTS CHARACTER VALUE E!PRESSING A NUMBER TO A NUMBER DATA TYPE. SELECT TO(NUMBER(SUBSTR(C`133C$2$))) FROM DUAL5 S"L4 SELECT TO(NUMBER(SUBSTR(C`133C$2$))) FROM DUAL5 TO(NUMBER(SUBSTR(C`133C$2$))) &&&&&&&&&&&&&&&&&&&&&&&&&&&&& 133 TO2C.AR: CON*ERTS A *ALUE OF NU)BER DATATYPE TO A C.ARACTER DATA TYPE( S"L4 SELECT TO(CHAR(12),$C` $ TO(CHAR &&&&&&& `1$2), CON*ERTS A DATE DATATYPE TO A C.ARACTER DATA TYPE( C) FROM DUAL5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT TO(CHAR(SYSDATE$CMONTH DD$YYYYC) FROM DUAL5 TO(CHAR(SYSDATE$C &&&&&&&&&&&&&&&&& JULY 22$233. S"L4 SELECT TO(CHAR(SYSDATE$CMONTH DAY$YYYYC) FROM DUAL5 TO(CHAR(SYSDATE$CMONTHDA &&&&&&&&&&&&&&&&&&&&&&&& JULY THURSDAY $233. S"L4 SELECT TO(CHAR(SYSDATE$CMONTH DAY YEARC) FROM DUAL5 TO(CHAR(SYSDATE$CMONTHDAYYEARC) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& JULY THURSDAY TWO THOUSAND FIVE S"L4 SELECT TO(CHAR(SYSDATE$CMM DD YYC) FROM DUAL5 TO(CHAR( &&&&&&&& 30 22 3. S"L4 SELECT TO(CHAR(SYSDATE$CDD MM YYC) FROM DUAL5 TO(CHAR( &&&&&&&& 22 30 3. TO(DATE% CONVERTS A CHARACTER DATATYPE TO A DATE DATA TYPE. S"L4 SELECT TO(DATE(C3//30/32C$CDD/MM/YYC) FROM DUAL5 TO(DATE(C &&&&&&&&& 3/&JUL&32 SPECIAL DATE FOR)ATS USING TO2C.AR : S"L4 SELECT ENAME$TO(CHAR(HIREDATE$CDDTH&MON&YYC) FROM EMP5 ENAME TO(CHAR(HIR &&&&&&&&&& &&&&&&&&&&& SMITH 10TH&DEC&23 ALLEN 23TH&FEB&21 WARD 22ND&FEB&21 JONES 32ND&APR&21 MARTIN 22TH&SEP&21 BLA'E 31ST&MAY&21 CLAR' 3 TH&JUN&21 SCOTT 1 TH&APR&20 'ING 10TH&NOV&21 TURNER 32TH&SEP&21 ADAMS 2)RD&MAY&20 JAMES 3)RD&DEC&21 FORD 3)RD&DEC&21 MILLER 2)RD&JAN&22

13

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1, ;DEF F989:<9=. S"L4 SELECT ENAME$TO(CHAR(HIREDATE$CDDSP&MON&YYC) FROM EMP5 ENAME TO(CHAR(HIREDATE$CD &&&&&&&&&& &&&&&&&&&&&&&&&&&&& SMITH SEVENTEEN&DEC&23 ALLEN TWENTY&FEB&21 WARD TWENTY&TWO&FEB&21 JONES TWO&APR&21 MARTIN TWENTY&EIGHT&SEP&21 BLA'E ONE&MAY&21 CLAR' NINE&JUN&21 SCOTT NINETEEN&APR&20 'ING SEVENTEEN&NOV&21 TURNER EIGHT&SEP&21 ADAMS TWENTY&THREE&MAY&20 JAMES THREE&DEC&21 FORD THREE&DEC&21 MILLER TWENTY&THREE&JAN&22 1, ;DEF F989:<9=.

113

S"L4 SELECT ENAME$TO(CHAR(HIREDATE$CDDSPTH&MON&YYC) FROM EMP5 ENAME TO(CHAR(HIREDATE$CDDS &&&&&&&&&& &&&&&&&&&&&&&&&&&&&&& SMITH SEVENTEENTH&DEC&23 ALLEN TWENTIETH&FEB&21 WARD TWENTY&SECOND&FEB&21 JONES SECOND&APR&21 MARTIN TWENTY&EIGHTH&SEP&21 BLA'E FIRST&MAY&21 CLAR' NINTH&JUN&21 SCOTT NINETEENTH&APR&20 'ING SEVENTEENTH&NOV&21 TURNER EIGHTH&SEP&21 ADAMS TWENTY&THIRD&MAY&20 JAMES THIRD&DEC&21 FORD THIRD&DEC&21 MILLER TWENTY&THIRD&JAN&22 1, ;DEF F989:<9=. TURNING NU)ERICS TO ALP.ABETS: THERE ARE TIMES WHEN AMOUNTS IN AN APPLICATION HAVE TO BE REPRESENTED BY ALPHABETICALLY.THIS CAN BE DONE BY JULIAN DATE CONVERSIONS. S"L4 SELECT TO(CHAR(TO(DATE(),/.,$CJC)$CJSPC) FROM DUAL5 TO(CHAR(TO(DATE(),/.,$CJC)$CJSPC) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THIRTY&FOUR THOUSAND SI! HUNDRED FIFTY&FOUR S"L4 SELECT TO(CHAR(TO(DATE(),/.,$CJC)$CJFPC) FROM DUAL5 TO(CHAR(TO(DATE(),/.,$CJC)$CJSPC) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TRN;<A&FD?; TRD?F6K= SNU H?K=;9= FNT<A&FD?;

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT TO(CHAR(TO(DATE(),/.,$CJC)$CXSPC) FROM DUAL5 TO(CHAR(TO(DATE(),/.,$CJC)$CJSPC) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& <RN;<A&TD?; <RD?F6K= FNU R?K=;9= TNT<A&TD?; ADDING LINE FEEDS TO SELECT STATE)ENT OUTPUT:

111

S"L4 SELECT CEMPLOYEE NAME%C VVENAMEVVCHR(13) 2 VV CJOB%CVV JOB VV CHR(13) VV ) CJOINING DATE%C VV HIREDATE OEMPLOYEE DETAILSO FROM EMP5 EMPLOYEE DETAILS &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPLOYEE NAME%SMITH JOB%CLER' JOINING DATE%10&DEC&23 EMPLOYEE NAME%ALLEN JOB%SALESMAN JOINING DATE%23&FEB&21 EMPLOYEE NAME%WARD JOB%SALESMAN JOINING DATE%22&FEB&21 EMPLOYEE NAME%JONES JOB%MANAGER JOINING DATE%32&APR&21 EMPLOYEE NAME%MARTIN JOB%SALESMAN JOINING DATE%22&SEP&21 EMPLOYEE NAME%BLA'E JOB%MANAGER JOINING DATE%31&MAY&21 EMPLOYEE NAME%CLAR' JOB%MANAGER JOINING DATE%3 &JUN&21 EMPLOYEE NAME%SCOTT JOB%ANALYST JOINING DATE%1 &APR&20 EMPLOYEE NAME%'ING JOB%PRESIDENT JOINING DATE%10&NOV&21 EMPLOYEE NAME%TURNER EMPLOYEE DETAILS &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& JOB%SALESMAN JOINING DATE%32&SEP&21 EMPLOYEE NAME%ADAMS JOB%CLER' JOINING DATE%2)&MAY&20 EMPLOYEE NAME%JAMES JOB%CLER' JOINING DATE%3)&DEC&21

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMPLOYEE NAME%FORD JOB%ANALYST JOINING DATE%3)&DEC&21 EMPLOYEE NAME%MILLER JOB%CLER' JOINING DATE%2)&JAN&22 1, ;DEF F989:<9=. GROUP BY% S"L4 SELECT DEPTNO$JOB$SUM(SAL) 2 FROM EMP ) GROUP BY DEPTNO$JOB5 DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 13 ;DEF F989:<9=.

112

ROLL UP: 1 SELECT DEPTNO$JOB$SUM(SAL) 2 FROM EMP )# GROUP BY ROLLUP(DEPTNO$JOB) , / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 13 20.3 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. 23 1320. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 )3 ,33 2 32. 1. ;DEF F989:<9=.

T.E ABO*E QUERY IS CO)BINATION OF :

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
GROUP BY DEPTNO$JOB. GROUP BY DEPTNO. GROUP BY (). 1 SELECT DEPTNO$JOB$SUM(SAL) FROM 2 EMP )# GROUP BY DEPTNO$JOB , / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 ;DEF F989:<9=.

11)

1 SELECT DEPTNO$SUM(SAL) FROM 2 EMP )# GROUP BY (DEPTNO) S"L4 / DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 13 20.3 23 1320. )3 ,33 1 SELECT SUM(SAL) FROM 2 EMP )# GROUP BY () , / SUM(SAL) &&&&&&&&&& 2 32.

CUBE: CUBE RETURNS SAME AS ROLL UP J ALL INDIVIDUAL JOBS SUM SALARIES. 1 SELECT DEPTNO$JOB$SUM(SAL) 2 FROM EMP )# GROUP BY CUBE(DEPTNO$JOB)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 13 20.3 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. 23 1320. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 )3 ,33 ANALYST /333 CLER' ,1.3 MANAGER 220. PRESIDENT .333 SALESMAN ./33

11,

2 32. 21 ;DEF F989:<9=.

T.E ABO*E QUERY IS CO)BINATION OF : GROUP BY DEPTNO$JOB. GROUP BY DEPTNO. GROUP BY JOB. GROUP BY ().

1 SELECT DEPTNO$JOB$SUM(SAL) FROM 2 EMP )# GROUP BY DEPTNO$JOB , / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 ;DEF F989:<9=.

1 SELECT DEPTNO$SUM(SAL) FROM 2 EMP )# GROUP BY (DEPTNO) S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 13 20.3 23 1320. )3 ,33 1 SELECT SUM(SAL) FROM 2 EMP )# GROUP BY () , / SUM(SAL) &&&&&&&&&& 2 32. S"L4 SELECT JOB$SUM(SAL) FROM EMP 2 GROUP BY JOB5 JOB SUM(SAL) &&&&&&&&& &&&&&&&&&& ANALYST /333 CLER' ,1.3 MANAGER 220. PRESIDENT .333 SALESMAN ./33

11.

GROUPING FUNCTION: 1 SELECT DEPTNO$JOB$SUM(SAL)$ 2 GROUPING(DEPTNO) GR(DEPTNO$ ) GROUPING(JOB) GR(JOB , FROM EMP .# GROUP BY ROLLUP(DEPTNO$JOB) / / DEPTNO JOB SUM(SAL) GR(DEPTNO &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 13 20.3 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. 23 1320. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 )3 ,33 2 32. 1. ;DEF F989:<9=. 1 2 ) , SELECT DEPTNO$JOB$SUM(SAL)$ GROUPING(DEPTNO) GR(DEPTNO$ GROUPING(JOB) GR(JOB FROM EMP GR(JOB 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 1 3 1 1 3 3 3 3 3 1 3 3 3 1

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
.# GROUP BY CUBE(DEPTNO$JOB) S"L4 / DEPTNO JOB SUM(SAL) GR(DEPTNO &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 3 13 MANAGER 2,.3 3 13 PRESIDENT .333 3 13 20.3 3 23 ANALYST /333 3 23 CLER' 1 33 3 23 MANAGER 2 0. 3 23 1320. 3 )3 CLER' .3 3 )3 MANAGER 22.3 3 )3 SALESMAN ./33 3 )3 ,33 3 ANALYST /333 1 CLER' ,1.3 1 MANAGER 220. 1 PRESIDENT .333 1 SALESMAN ./33 1 3 3 1 1 3 2 32. 1 21 ;DEF F989:<9=. GR(JOB 3 3 3 1 3 3 3 1 3 3 3 1 3 3 3 3 3 3 1

11/

GROUPING SETS: 1 SELECT DEPTNO$JOB$MGR MANAGER(NO$AVG(SAL) 2 FROM EMP ) GROUP BY GROUPING SETS ,# ((DEPTNO$JOB)$(JOB$MGR)) S"L4 / DEPTNO JOB MANAGER(NO AVG(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST )333 23 CLER' .3 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN 1,33 ANALYST CLER' CLER' CLER' CLER' MANAGER PRESIDENT SALESMAN 1 ;DEF F989:<9=. 1 SELECT DEPTNO$JOB$MGR MANAGER(NO$SUM(SAL) 2 FROM EMP ) GROUP BY GROUPING SETS 0.// 0/ 2 0022 0022 0 32 02) 0/ 2 )333 .3 1)33 1133 233 20.2.))))) .333 1,33

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
,# ((DEPTNO$JOB)$(JOB$MGR)) S"L4 / DEPTNO JOB MANAGER(NO SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 ANALYST 0.// /333 CLER' 0/ 2 .3 CLER' 0022 1)33 CLER' 0022 1133 CLER' 0 32 233 MANAGER 02) 220. PRESIDENT .333 SALESMAN 0/ 2 ./33 10 ;DEF F989:<9=. T.E ABO*E IS CO)BINATION OF: GROUP BY DEPT$JOB. GROUP BY JOB$MGR.

110

1 SELECT DEPTNO$JOB$SUM(SAL) 2 FROM EMP )# GROUP BY(DEPTNO$JOB) S"L4 / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 ;DEF F989:<9=. 1 SELECT JOB$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY(JOB$MGR) S"L4 / JOB MGR SUM(SAL) &&&&&&&&& &&&&&&&&&& &&&&&&&&&& ANALYST 0.// /333 CLER' 0/ 2 .3 CLER' 0022 1)33 CLER' 0022 1133 CLER' 0 32 233 MANAGER 02) 220. PRESIDENT .333 SALESMAN 0/ 2 ./33 2 ;DEF F989:<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CO)POSITE COLU)NS: 1 SELECT DEPTNO$JOB$MGR MANAGER(NO$SUM(SAL) 2 FROM EMP )# GROUP BY ROLLUP(DEPTNO$(JOB$MGR)) S"L4 / DEPTNO JOB MANAGER(NO SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 0022 1)33 13 MANAGER 02) 2,.3 13 PRESIDENT .333 13 20.3 23 ANALYST 0.// /333 23 CLER' 0022 1133 23 CLER' 0 32 233 23 MANAGER 02) 2 0. 23 1320. )3 CLER' 0/ 2 .3 )3 MANAGER 02) 22.3 )3 SALESMAN 0/ 2 ./33 )3 ,33 2 32. 1, ;DEF F989:<9=.

112

T.E ABO*E IS CO)BINATION OF BELO+: GROUP BY DEPTNO$JOB$MGR. GROUP BY DEPTNO. GROUP BY.

T.E ABO*E QUERY DISPLAYS T.E FOLLO+ING: TOTAL SALARY FOR EVERY DEPARTMENT. TOTAL SALARY FOR EVERY DEPARTMENT$JOB$MGR. GRNAD TOTAL.

1 SELECT DEPTNO$JOB$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO$JOB$MGR S"L4 / DEPTNO JOB MGR SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 0022 1)33 13 MANAGER 02) 2,.3 13 PRESIDENT .333 23 ANALYST 0.// /333 23 CLER' 0022 1133 23 CLER' 0 32 233 23 MANAGER 02) 2 0. )3 CLER' 0/ 2 .3 )3 MANAGER 02) 22.3 )3 SALESMAN 0/ 2 ./33 13 ;DEF F989:<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 SELECT DEPTNO$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO , / DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 13 20.3 23 1320. )3 ,33 1 SELECT SUM(SAL) 2 FROM EMP )# GROUP BY() , / SUM(SAL) &&&&&&&&&& &&&&&&&&&& 2 32. 1 SELECT DEPTNO$JOB$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY CUBE(DEPTNO$(JOB$MGR)) S"L4 / DEPTNO JOB MGR SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 23 ANALYST 0.// /333 )3 CLER' 0/ 2 .3 13 CLER' 0022 1)33 23 CLER' 0022 1133 23 CLER' 0 32 233 13 MANAGER 02) 2,.3 23 MANAGER 02) 2 0. )3 MANAGER 02) 22.3 13 PRESIDENT .333 )3 SALESMAN 0/ 2 ./33 ANALYST 0.// /333 CLER' 0/ 2 .3 CLER' 0022 1)33 CLER' 0022 1133 CLER' 0 32 233 MANAGER 02) 220. PRESIDENT .333 SALESMAN 0/ 2 ./33 13 20.3 23 1320. )3 ,33 2 32. 22 ;DEF F989:<9=. CONCATENATED GROUPING: 1 SELECT DEPTNO$JOB$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO$ROLLUP(JOB)$CUBE(MGR) S"L4 / DEPTNO JOB MGR SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 0022 1)33 13 MANAGER 02) 2,.3 13 PRESIDENT .333 23 ANALYST 0.// /333 23 CLER' 0022 1133 23 MANAGER 02) 2 0. 23 CLER' 0 32 233

11

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
)3 CLER' )3 SALESMAN )3 MANAGER 13 13 13 23 23 23 23 )3 )3 13 CLER' 13 MANAGER 13 PRESIDENT 13 23 ANALYST 23 CLER' 23 MANAGER 23 )3 CLER' )3 MANAGER )3 SALESMAN )3 )1 ;DEF F989:<9=. 0/ 2 0/ 2 02) 0022 02) .3 ./33 22.3 1)33 2,.3 .333 0.// /333 0022 1133 02) 2 0. 0 32 233 0/ 2 /..3 02) 22.3 1)33 2,.3 .333 20.3 /333 1 33 2 0. 1320. .3 22.3 ./33 ,33

123

T.E ABO*E QUERY IS CO)BINATION OF BELO+ QUERIES: GROUP BY DEPTNO$JOB$MGR. GROUP BY DEPTNO$MGR. GROUP BY DEPTNO$JOB. GROUP BY DEPTNO.

T.E ABO*E QUERY DISPLAYS T.E FOLLO+ING: TOTAL SALARY FOR EVERY DEPARTEMENT NO$JOB$MGR. TOTAL SALARY FOR EVERY DEPARTEMENT NO$MGR. TOTAL SALARY FOR EVERY DEPARTEMENT NO$JOB. TOTAL SALARY FOR EVERY DEPARTEMENT NO.

1 SELECT DEPTNO$JOB$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO$JOB$MGR S"L4 / DEPTNO JOB MGR SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 0022 1)33 13 MANAGER 02) 2,.3 13 PRESIDENT .333 23 ANALYST 0.// /333 23 CLER' 0022 1133 23 CLER' 0 32 233 23 MANAGER 02) 2 0. )3 CLER' 0/ 2 .3 )3 MANAGER 02) 22.3 )3 SALESMAN 0/ 2 ./33

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
13 ;DEF F989:<9=. 1 SELECT DEPTNO$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO$MGR , / DEPTNO MGR SUM(SAL) &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 0022 13 02) 13 .333 23 0.// 23 0022 23 02) 23 0 32 )3 0/ 2 )3 02) ;DEF F989:<9=. 1 SELECT DEPTNO$JOB$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO$JOB S"L4 / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 ;DEF F989:<9=.

121

1)33 2,.3 /333 1133 2 0. 233 /..3 22.3

1 SELECT DEPTNO$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO S"L4 / DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 13 20.3 23 1320. )3 ,33

@TOP2N @ ANALYSIS: S"L4 SELECT ROWNUM AS RAN'$ENAME$SAL 2 FROM (SELECT ENAME$SAL FROM EMP ORDER BY SAL DESC) ) WHERE ROWNUM WI)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
RAN' ENAME SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 1 'ING .333 2 SCOTT )333 ) FORD )333 RETRIE*E ONLY RO+S / TO Y FRO) A TABLE:

122

1 SELECT # FROM (SELECT ROWNUM RN$ENAME FROM EMP) 2# WHERE RN BETWEEN , AND 0 ) / , RN ENAME &&&&&&&&&& &&&&&&&&&& , JONES . MARTIN / BLA'E 0 CLAR' S"L4 SELECT ROWNUM RN$ENAME FROM EMP GROUP BY ROWNUM$ENAME HAVING ROWNUM BETWEEN , AND 05 RN ENAME &&&&&&&&&& &&&&&&&&&& , JONES . MARTIN / BLA'E 0 CLAR' NU)BER OF RO+S:

RETRIVING EVEN AND ODD

S"L4 SELECT # FROM (SELECT ROWNUM RN$EMPNO$ENAME FROM EMP) E 2 WHERE MOD(E.RN$2)I35 RN EMPNO ENAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 2 0, ALLEN , 0.// JONES / 0/ 2 BLA'E 2 0022 SCOTT 13 02,, TURNER 12 0 33 JAMES 1, 0 ), MILLER 0 ;DEF F989:<9=. S"L4 SELECT # FROM (SELECT ROWNUM RN$EMPNO$ENAME FROM EMP) E 2 WHERE MOD(E.RN$2)I1 ) / RN EMPNO ENAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 1 0)/ SMITH ) 0.21 WARD . 0/., MARTIN 0 0022 CLAR' 02) 'ING 11 020/ ADAMS 1) 0 32 FORD 0 ;DEF F989:<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
AN AUTO)ATIC CO))IT OCCURS UNDER T.E FOLLO+ING CIRCU)STANCES: DDL STATEMENT ISSUED. DCL STATEMENT ISSUED. NORMAL E!IT FROM S"L#PLUS WITHOUT E!PLICITLY ISSUING COMMIT OR ROLLBAC'$ AN AUTOMATIC ROLLBAC' OCCURS UNDER AN ABNORMAL TERMINATION OF S"L#PLUS OR SYSTEM FAILURE. DROPING COLU)N:

12)

S"L4 CREATE TABLE EMP1 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 ALTER TABLE EMP1 2 SET UNUSED COLUMN MGR5 T6789 68<9;9=.

S"L4 DESC EMP1 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,) ENAME VARCHAR2(13) JOB VARCHAR2( ) HIREDATE DATE SAL NUMBER(0$2) COMM NUMBER(0$2) DEPTNO NUMBER(2) S"L4 ALTER TABLE EMP1 2 DROP UNUSED COLUMNS5 T6789 68<9;9=. S"L4 DESC EMP1 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,) ENAME VARCHAR2(13) JOB VARCHAR2( ) HIREDATE DATE SAL NUMBER(0$2) COMM NUMBER(0$2) DEPTNO NUMBER(2) SOUNDE!% S"L4 CREATE TABLE MYFRIENDS 2 (NAME VARCHAR2(13))5 T6789 :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 INSERT INTO MYFRIENDS 2 VALUES ) (CNEETAC)5 1 ;DE :;96<9=. 1 INSERT INTO MYFRIENDS 2 VALUES )# (CMITAC) S"L4 / 1 ;DE :;96<9=.

12,

1 INSERT INTO MYFRIENDS 2 VALUES )# (CDIPUC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO MYFRIENDS 2 VALUES )# (CDEEPUC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO MYFRIENDS 2 VALUES )# (CDIPAC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO MYFRIENDS 2 VALUES )# (CANILC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO MYFRIENDS 2 VALUES )# (CSUNILC) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT # FROM MYFRIENDS5 NAME &&&&&&&&&& NEETA MITA DIPU

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DEEPU DIPA ANIL SUNIL 0 ;DEF F989:<9=. S"L4 SELECT # FROM MYFRIENDS 2 WHERE SOUNDE!(NAME) I SOUNDE!(CDEEPC)5 NAME &&&&&&&&&& DIPU DEEPU DIPA S"L4 SELECT SOUNDE!(NAME)$NAME$SOUNDE!(CDEEPC) FROM MYFRIENDS5 SOUN &&&& &&&&&&&&&& &&&& N)33 M)33 D133 D133 D133 A.,3 S.,3 0 ;DEF F989:<9=. NAME NEETA MITA DIPU DEEPU DIPA ANIL SUNIL SOUN D133 D133 D133 D133 D133 D133 D133

12.

GENERATING PRI)ARY -EY NU)BERS USING RO+ NU) AND SEQUENCES: S"L4 CREATE TABLE CUSTOMERS1 2 (CUST(NO NUMBER(13)$ ) NAME VARCHAR2(13))5 T6789 :;96<9=. S"L4 INSERT INTO CUSTOMERS1 2 VALUES ) (3$CPAVANC)5 1 ;DE :;96<9=. 1 INSERT INTO CUSTOMERS1 2 VALUES )# (3$C'UMARC) S"L4 / 1 ;DE :;96<9=.

1 INSERT INTO CUSTOMERS1 2 VALUES )# (3$CGAYATRIC) S"L4 / 1 ;DE :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 INSERT INTO CUSTOMERS1 2 VALUES )# (3$CSRISHAC) S"L4 / 1 ;DE :;96<9=. 1 UPDATE CUSTOMERS1 2# SET CUST(NO I ROWNUM S"L4 / , ;DEF ?B=6<9=. S"L4 SELECT # FROM CUSTOMERS15 CUST(NO NAME &&&&&&&&&& &&&&&&&&&& 1 PAVAN 2 'UMAR ) GAYATRI , SRISHA S"L4 CREATE SE"UENCE CUSTOMERS1(SE" 2 INCREMENT BY 1 ) START WITH 135 S9P?9K:9 :;96<9=. S"L4 UPDATE CUSTOMERS1 2 SET CUST(NO I CUSTOMERS1(SE".NE!TVAL5 , ;DEF ?B=6<9=. S"L4 SELECT # FROM CUSTOMERS15 CUST(NO NAME &&&&&&&&&& &&&&&&&&&& 13 PAVAN 11 'UMAR 12 GAYATRI 1) SRISHA CONDITIONAL E/PRESSIONS: PROVIDE THE USE OF IF&THEN&ELSE LOGIC WITHIN A S"L STATEMENT. CASE: CASE E!PRESSION. DECODE FUNCTION.

12/

1 SELECT EMPNO$ENAME$SAL$ 2 CASE JOB ) , . ELSE WHEN CMANAGERC THEN 1.13 #SAL WHEN CCLER'C THEN 1.1. #SAL WHEN CSALESMANCTHEN 1.23 #SAL SAL END OREVISED(SALARYO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
/# FROM EMP S"L4 / EMPNO ENAME SAL REVISED(SALARY &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& 0)/ SMITH 233 23 0, ALLEN 1/33 1 23 0.21 WARD 12.3 1.33 0.// JONES 2 0. )202.. 0/., MARTIN 12.3 1.33 0/ 2 BLA'E 22.3 )1). 0022 CLAR' 2,.3 2/ . 0022 SCOTT )333 )333 02) 'ING .333 .333 02,, TURNER 1.33 1233 020/ ADAMS 1133 12/. 0 33 JAMES .3 13 2.. 0 32 FORD )333 )333 0 ), MILLER 1)33 1, . 1, ;DEF F989:<9=. DECODE: 1 SELECT EMPNO$ENAME$SAL$ 2 DECODE (JOB$CMANAGERC ) , . /# FROM EMP 0 / EMPNO ENAME SAL REVISED(SALARY &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& 0)/ SMITH 233 23 0, ALLEN 1/33 1 23 0.21 WARD 12.3 1.33 0.// JONES 2 0. )202.. 0/., MARTIN 12.3 1.33 0/ 2 BLA'E 22.3 )1). 0022 CLAR' 2,.3 2/ . 0022 SCOTT )333 )333 02) 'ING .333 .333 02,, TURNER 1.33 1233 020/ ADAMS 1133 12/. 0 33 JAMES .3 13 2.. 0 32 FORD )333 )333 0 ), MILLER 1)33 1, . 1, ;DEF F989:<9=. *IE+S: +.AT IS *IE+A AVIEW IS A LOGICAL TABLE BASED ON ONE OR MORE TABLES OR ANOTHER VIEW. A VIEW CONTAINS NO DATA OF ITS OWN BUT IS LI'E A WINDOW THROUGH WHICH DATA FROM TABLES CAN BE VIEWED OR CHANGED. $1.13 #SAL$

120

CCLER'C $1.1. #SAL$ CSALESMANC $1.23 #SAL$ SAL ) OREVISED(SALARYO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
THE TABLES ON WHICH A VIEW IS BASED ARE CALLED BASE TABLES. THE VIEW IS STORED AS SELECT STATEMENT IN THE DATA DICTIONARY. +.Y USE *IE+S: TO RESTRICT DATA ACCESS. TO MA'E COMPLE! "UERIES EASY. TO PROVIDE DATA INDEPENDENCE. TO PRESENT DIFFERENT VIEWS OF THE SAME DATA.

122

AD*ANTAGES OF *IE+S: VIEWS RESTRICT ACCESS TO THE DATA BECAUSE THE VIEW CAN DISPLAY SELECTIVE COLUMNS FROM THE TABLES. VIEWS ALLOW USERS TO MA'E SIMPLE "UERIES TO RETRIVE THE RESULTS FROM COMPLICATED "UERIES. FOR E!AMPLE$ VIEW ALLOWS USERS TO "UERY INFORMATION FROM MULTIPLE TABLES WITHOUT 'NOWING HOW TO WRITE JOIN STATEMENT. ONE VIEW CAN BE USED TO RETRIEVE DATA FROM SEVERAL TABLES. VIEWS PROVIDE GROUPS OF USERS ACCESS TO DATA ACCORDING TO THEIR PARTICULAR CRITERIA. SI)PLE *IE+S ONE NO NO YES CO)PLE/ *IE+S ONE OR )ORE YES YES NOT AL+AYS

FEATURE NU)BER OF TABLES CONTAINS FUNCTIONS CONTAINS GROUPS OF DATA D)L T.ROUG. *IE+

CREATION OF T.E *IE+: CREATE [ OR REPLACE [FORCEZNOFORCE\ VIEW VIEW(NAME [(ALIAS[$ALIAS*..)\ AS SUB"UERY [WITH CHEC' OPTION[CONSTRAINT CONSTRAINT(NAME\\ [WITH READ ONLY[CONSTRAINT CONSTRAINT(NAME\\ IN THE SYNTA!% OR REPLACE FORCE NOFORCE VIEW RECREATES THE VIEW IF ALREADY E!ISTS. CREATES THE VIEW REGARDLESS OF WHETHER OR NOT THE BASE TABLES E!IST. CREATES THE VIEW ONLY OF THE BASE TABLES E!IST.(THIS IS DEFAULT). NAME OF THE VIEW.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ALIAS SUB"UERY WITH CHEC' OPTION CONSTRAINT ALIAS NAME FOR COLUMNS SELECTED BY "UERY$ THEY SHOULD MATCH. SELECT SATETMENT. NAME OF CONSTRAINT.

12

SPECIFIES THAT ONLY ROWS ACCESSIBLE TO THE VIEW CAN BE INSERTED OR UPDATED.

WITH READ ONLY ENSURES THAT NO DML OPERATIONS CAN BE PERFORMED ON THIS VIEW. GUIDELINES FOR CREATING A *IE+:

THE SUB"UERY THAT DEFINES THE VIEW CANNOT CONTAIN AN ORDER BY CLAUSE. THE ORDER BY CLAUSE IS SPECIFIED WHEN YOU RETRIVE THE DATA FROM THE VIEW.

S"L4 CREATE TABLE EMP(DUP 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 CREATE VIEW EMPVU13 2 AS ) SELECT # FROM EMP(DUP WHERE DEPTNOI135 VN9E :;96<9=. S"L4 DESC EMPVU135 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,) ENAME VARCHAR2(13) JOB VARCHAR2( ) MGR NUMBER(,) HIREDATE DATE SAL NUMBER(0$2) COMM NUMBER(0$2) DEPTNO NUMBER(2) S"L4 SELECT # FROM EMPVU135 EMPNO ENAME JOB MGR HIREDATE &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 CLAR' MANAGER 02) 3 &JUN&21 02) 'ING PRESIDENT 10&NOV&21 .333 0 ), MILLER CLER' 0022 2)&JAN&22 SAL 2,.3 1)33 COMM 13 13 13 DEPTNO

THIS IS A SIMPLE VIEW.HERE WE CAN DO ALL DML OPERATIONS. S"L4 INSERT INTO EMPVU13 2 VALUES ) (1$CPAVANC$CMANAGERC$0)/ $C31&DEC& 1C$1333$133$13)5 1 ;DE :;96<9=. S"L4 SELECT # FROM EMPVU135 EMPNO ENAME JOB MGR HIREDATE &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& SAL COMM DEPTNO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0022 02) 0 ), 1 CLAR' 'ING MILLER MANAGER 02) 3 &JUN&21 2,.3 PRESIDENT 10&NOV&21 .333 CLER' 0022 2)&JAN&22 1)33 PAVAN MANAGER 0)/ 31&DEC& 1 1333 13 13 13 133 13 S"L4 SELECT # FROM EMP(DUP WHERE DEPTNOI135 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 02) 'ING PRESIDENT 10&NOV&21 .333 13 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 1 PAVAN MANAGER 0)/ 31&DEC& 1 1333 133 HERE DATA IS INSERTED INTO EMP(DUP TABLE.

1)3

13

IN THE SIMPLE VIEW WE CAN PERFORM INSERTION $DELETION$UPDATION.THE BASE TABLE WILL BE AFFECTED$BECAUSE VIEW DOES NOT CONTAIN ANY DATA. IF YOU WANT SEE THE VIEWS CREATED IN THE DATABASE% S"L4 DESC USER(VIEWS N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& VIEW(NAME NOT NULL VARCHAR2()3) TE!T(LENGTH NUMBER TE!T LONG TYPE(TE!T(LENGTH NUMBER TYPE(TE!T VARCHAR2(,333) OID(TE!T(LENGTH NUMBER OID(TE!T VARCHAR2(,333) VIEW(TYPE(OWNER VARCHAR2()3) VIEW(TYPE VARCHAR2()3) SUPERVIEW(NAME VARCHAR2()3)

S"L4 SELECT VIEW(NAME$TE!T FROM USER(VIEWS WHERE VIEW(NAMEICEMPVU13C5 VIEW(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TE!T &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPVU13 SELECT OEMPNOO$OENAMEO$OJOBO$OMGRO$OHIREDATEO$OSALO$OCOMMO$ODEPTNOO FROM EMP(DUP ORACLE SERVER USER(VIEWS. IT SEES THE SELECT STATEMENT HERE.

S"L # PLUS% SELECT # FROM VIEW5

BASE TABLE. IT E!ECUTES "UERY ON THIS TABLE AND SENDS OUTPUT TO S"L#PLUS.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 CREATE VIEW EMPVU1(13 2 AS ) SELECT EMPNO$ENAME FROM EMP(DUP , WHERE DEPTNOI135 VN9E :;96<9=. S"L4 DESC EMPVU1(13 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,) ENAME VARCHAR2(13) S"L4 SELECT VIEW(NAME$TE!T FROM USER(VIEWS WHERE VIEW(NAMEICEMPVU1(13C5 VIEW(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TE!T &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPVU1(13 SELECT EMPNO$ENAME FROM EMP(DUP WHERE DEPTNOI13 S"L4 UPDATE EMPVU13 2 SET SAL I 13335 , ;DEF ?B=6<9=. S"L4 SELECT # FROM EMP(DUP WHERE DEPTNOI135 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 CLAR' MANAGER 02) 3 &JUN&21 1333 02) 'ING PRESIDENT 10&NOV&21 1333 13 0 ), MILLER CLER' 0022 2)&JAN&22 1333 1 PAVAN MANAGER 0)/ 31&DEC& 1 S"L4 SELECT # FROM EMPVU135 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 CLAR' MANAGER 02) 3 &JUN&21 1333 02) 'ING PRESIDENT 10&NOV&21 1333 13 0 ), MILLER CLER' 0022 2)&JAN&22 1333 1 PAVAN MANAGER 0)/ 31&DEC& 1 1 DELETE FROM EMPVU13 2# WHERE JOBICMANAGERC S"L4 / 2 ;DEF =989<9=. S"L4 SELECT # FROM EMPVU135 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 02) 'ING PRESIDENT 10&NOV&21 1333 0 ), MILLER CLER' 0022 2)&JAN&22 1333 COMM 13 13 DEPTNO COMM 13 13 1333 133 13 DEPTNO COMM 13 13 1333 133 13 DEPTNO

1)1

WHEN EVER WE "UERY A VIEW$S"L#PLUS WILL GO TO USER(VIEWS AND PIC' THE SELECT STATEMENT FROM THE TABLE AND E!ECUTE THE "UERY ON THE BASE TABLE AND RESULT OF BASE TABLE INFO WILL BE DISPLAYED THROUGH VIEW.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 SELECT # FROM EMP(DUP 2# WHERE DEPTNOI13 S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 02) 'ING PRESIDENT 10&NOV&21 1333 0 ), MILLER CLER' 0022 2)&JAN&22 1333 COMM 13 13 DEPTNO

1)2

)ODIFYING *IE+: S"L4 CREATE VIEW EMPVU23 2 (EMPLOYEE(NO$EMPLOYEE(NAME) ) AS , SELECT EMPNO$ENAME FROM EMP(DUP . WHERE DEPTNOI235 VN9E :;96<9=. S"L4 DESC EMPVU23 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPLOYEE(NO NUMBER(,) EMPLOYEE(NAME VARCHAR2(13) S"L4 CREATE VIEW EMPVU23 2 AS ) SELECT # FROM EMP(DUP , WHERE DEPTNOI235 CREATE VIEW EMPVU23 # ERROR 6< 8NK9 1% ORA&33 ..% K6>9 NF 68;96=A ?F9= 7A 6K 9UNF<NKS D7X9:< 1 CREATE OR REPLACE VIEW EMPVU23 2 AS ) SELECT # FROM EMP(DUP ,# WHERE DEPTNOI23 S"L4 / VN9E :;96<9=. S"L4 DESC EMPVU23 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,) ENAME VARCHAR2(13) JOB VARCHAR2( ) MGR NUMBER(,) HIREDATE DATE SAL NUMBER(0$2) COMM NUMBER(0$2) DEPTNO NUMBER(2) HERE ORIGINAL DEFINITION OF THE VIEW REPLACED BY THE CURRENT DEFINITION. S"L4 CREATE VIEW EMPVU)3 2 AS ) SELECT EMPNO EMPLOYEE(NO$ENAME EMPLOYEE(NAME FROM EMP(DUP , WHERE DEPTNOI)35 VN9E :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 DESC EMPVU)3 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPLOYEE(NO NUMBER(,) EMPLOYEE(NAME VARCHAR2(13) RULES FOR PERFOR)ING D)L ON *IE+: YOU CAN PERFORM DML OPERATIONS ON SIMPLE VIEWS.

1))

THE CREATE OR REPLACE OPTION ALLOWS A VIEW TO BE CREATED EVEN IF ONE E!ISTS WITH THIS NAME ALREADY$ THUS REPLACING OLD VERSION OF THE VIEW.

YOU CANNOT RE)O*E A RO+ IF T.E *IE+ CONTAINS T.E FOLLO+ING:

GROUP FUNCTIONS. A GROUP BY CLAUSE. THE DISTINCT 'EYWORD. THE PSEUDOCOLUMN ROWNUM 'EYWORD.

YOU CANNOT )ODIFY DATA IN A *IE+ IF IT CONTAINS T.E FOLLO+ING: GROUP FUNCTIONS. A GROUP BY CLAUSE. THE DISTINCT 'EYWORD. THE PSEUDOCOLUMN ROWNUM 'EYWORD. COLUMNS DEFINED BY E!PRESSIONS.

YOU CANNOT ADD DATA IN A *IE+ IF IT CONTAINS T.E FOLLO+ING: GROUP FUNCTIONS. A GROUP BY CLAUSE. THE DISTINCT 'EYWORD. THE PSEUDOCOLUMN ROWNUM 'EYWORD. COLUMNS DEFINED BY E!PRESSIONS. NOT NULL COLUMNS IN THE BASE TABLES THAT ARE NOT SELECTED BY THE VIEW.

USING T.E +IT. C.EC- OPTION CLAUSE: THE WITH CHEC' OPTION CLAUSE SPECIFIES THAT INSERTS AND UPDATES PERFORMED THROUGH THE VIEW CANNOT CREATE ROWS WHICH THE VIEW CANNOT SELECT.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 CREATE TABLE EMP(DUP1 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 CREATE VIEW EMP(DUPVU23 2 AS ) SELECT EMPNO$ENAME$JOB$DEPTNO FROM EMP(DUP1 , WHERE DEPTNOI235 VN9E :;96<9=. S"L4 DESC EMP(DUPVU23 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,) ENAME VARCHAR2(13) JOB VARCHAR2( ) DEPTNO NUMBER(2) S"L4 SELECT # FROM EMP(DUPVU235 EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0.// JONES MANAGER 0022 SCOTT ANALYST 020/ ADAMS CLER' 0 32 FORD ANALYST S"L4 UPDATE EMP(DUPVU23 2 SET DEPTNOI15 . ;DEF ?B=6<9=. S"L4 SELECT # FROM EMP(DUPVU235 KD ;DEF F989:<9= HERE IF YOU WANT TO STOP ANY UPDATE OR INSERT ON THIS VIEW. S"L4 DROP TABLE EMP(DUP15 T6789 =;DBB9=. S"L4 CREATE TABLE EMP(DUP1 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 DROP VIEW EMP(DUPVU235 VN9E =;DBB9=. S"L4 CREATE VIEW EMP(DUPVU23 2 AS ) SELECT EMPNO$ENAME$JOB$DEPTNO FROM EMP(DUP1 , WHERE DEPTNOI23 . WITH CHEC' OPTION CONSTRAINT EMP(DUPVU23(VIEWCHEC'5 VN9E :;96<9=. S"L4 UPDATE EMP(DUPVU23 2 SET DEPTNOI15 DEPTNO 23 23 23 23 23

1),

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
UPDATE EMP(DUPVU23 # ERROR 6< 8NK9 1% ORA&31,32% QN9E WITH CHEC' OPTION ER9;9&:86?F9 QND86<NDK S"L4 INSERT INTO EMP(DUPVU23 2 VALUES ) (1$CPAVANC$CMANAGERC$13)5 INSERT INTO EMP(DUPVU23 # ERROR 6< 8NK9 1% ORA&31,32% QN9E WITH CHEC' OPTION ER9;9&:86?F9 QND86<NDK S"L4 SELECT CONSTRAINT(NAME$CONSTRAINT(TYPE FROM USER(CONSTRAINTS 2 WHERE TABLE(NAMEICEMP(DUPVU23C5 CONSTRAINT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& & EMP(DUPVU23(VIEWCHEC' C V

1).

NO ROWS ARE UPDATED BECAUSE IF THE DEPARTMENT NUMBER WAS CHANGE TO 1$ THE VIEW WOULD NO LONGER BE ABLE TO SEE THAT EMPLOYEES OF 23.THUS WE CANNOT CHANGE THE VIEW DEFINITION. HERE WE CAN UPDATE ANY OTHER COLUMNS WITHOUT AFFECTING VIEW DEFINITION.

READ ONLY *IE+S: DENYING DML OPERATIONS ON THE VIEW BY 'EEPING READ ONLY CONSTRAINT. S"L4 CREATE VIEW EMP(DUP)3VU 2 AS ) SELECT # FROM EMP(DUP1 , WITH READ ONLY CONSTRAINT EMP(DUP)3VU(READONLY5 VN9E :;96<9=. S"L4 UPDATE EMP(DUP)3VU 2 SET DEPTNOI)35 SET DEPTNOI)3 # ERROR 6< 8NK9 2% ORA&310))% QN;<?68 :D8?>K KD< 688DE9= R9;9 S"L4 INSERT INTO EMP(DUP)3VU 2 VALUES ) (1$CPAVANC$CMANAGERC$0)/ $C31&DEC& 2C$1333$133$)3)5 INSERT INTO EMP(DUP)3VU # ERROR 6< 8NK9 1% ORA&310))% QN;<?68 :D8?>K KD< 688DE9= R9;9 S"L4 DELETE FROM EMP(DUP)3VU5 DELETE FROM EMP(DUP)3VU # ERROR 6< 8NK9 1% ORA&310.2% :6KKD< =989<9 T;D> QN9E EN<RD?< 9U6:<8A DK9 L9A&B;9F9;Q9= <6789 S"L4 SELECT CONSTRAINT(NAME$CONSTRAINT(TYPE FROM USER(CONSTRAINTS 2 WHERE TABLE(NAMEICEMP(DUP)3VUC5 CONSTRAINT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& & C

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMP(DUP)3VU(READONLY O CO)PLE/ *IE+S: 1 CREATE VIEW DEPT(SUM(VU 2 (NAME$MINSAL$MA!SAL$AVGSAL) ) AS , SELECT D.DNAME$MIN(E.SAL)$MA!(E.SAL)$AVG(E.SAL) . FROM EMP E$ DEPT D / WHERE E.DEPTNOID.DEPTNO 0# GROUP BY D.DNAME 2 / VN9E :;96<9=.

1)/

HERE NO DELETION$NO UPDATION $NO INSERTION ON THE VIEW. ONLY READ. IN THE USER(CONSTRAINTS TABLE CONSTRAINT(TYPE IS GO.

S"L4 SELECT # FROM DEPT(SUM(VU5 NAME MINSAL MA!SAL AVGSAL &&&&&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& ACCOUNTING 1)33 .333 2 1/.////0 RESEARCH 233 )333 210. SALES .3 22.3 1.//.////0 S"L4 DESC DEPT(SUM(VU N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& NAME VARCHAR2(1,) MINSAL NUMBER MA!SAL NUMBER AVGSAL NUMBER S"L4 INSERT INTO DEPT(SUM(VU 2 VALUES ) (CCOMPUTERSC$111$111$111)5 INSERT INTO DEPT(SUM(VU # ERROR 6< 8NK9 1% ORA&310)2% =6<6 >6KNB?86<NDK DB9;6<NDK KD< 89S68 DK <RNF QN9E S"L4 UPDATE DEPT(SUM(VU 2 SET NAMEICCOMPUTERSC5 UPDATE DEPT(SUM(VU # ERROR 6< 8NK9 1% ORA&310)2% =6<6 >6KNB?86<NDK DB9;6<NDK KD< 89S68 DK <RNF QN9E S"L4 DELETE FROM DEPT(SUM(VU5 DELETE FROM DEPT(SUM(VU # ERROR 6< 8NK9 1% ORA&310)2% =6<6 >6KNB?86<NDK DB9;6<NDK KD< 89S68 DK <RNF QN9E S"L4 CREATE VIEW E"UI(JOINVU 2 AS ) SELECT EMPNO$ENAME$DEPTNO$DNAME$LOC FROM EMP NATURAL JOIN DEPT5 VN9E :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM E"UI(JOINVU5 EMPNO ENAME DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 0)/ SMITH 23 RESEARCH DALLAS 0, ALLEN )3 SALES CHICAGO 0.21 WARD )3 SALES CHICAGO 0.// JONES 23 RESEARCH DALLAS 0/., MARTIN )3 SALES CHICAGO 0/ 2 BLA'E )3 SALES CHICAGO 0022 CLAR' 13 ACCOUNTING NEW YOR' 0022 SCOTT 23 RESEARCH DALLAS 02) 'ING 13 ACCOUNTING NEW YOR' 02,, TURNER )3 SALES CHICAGO 020/ ADAMS 23 RESEARCH DALLAS 0 33 JAMES )3 SALES CHICAGO 0 32 FORD 23 RESEARCH DALLAS 0 ), MILLER 13 ACCOUNTING NEW YOR' 1, ;DEF F989:<9=. DROPING *IE+: S"L4 DROP VIEW EMPVU135 VN9E =;DBB9=. GROUP BY: S"L4 SELECT DEPTNO$JOB$SUM(SAL) 2 FROM EMP ) GROUP BY DEPTNO$JOB5 DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 13 ;DEF F989:<9=.

1)0

ROLL UP: 1 SELECT DEPTNO$JOB$SUM(SAL) 2 FROM EMP )# GROUP BY ROLLUP(DEPTNO$JOB) , / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 13 20.3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
23 ANALYST 23 CLER' 23 MANAGER 23 )3 CLER' )3 MANAGER )3 SALESMAN )3 /333 1 33 2 0. 1320. .3 22.3 ./33 ,33 2 32. 1. ;DEF F989:<9=. T.E ABO*E QUERY IS CO)BINATION OF : GROUP BY DEPTNO$JOB. GROUP BY DEPTNO. GROUP BY ().

1)2

1 SELECT DEPTNO$JOB$SUM(SAL) FROM 2 EMP )# GROUP BY DEPTNO$JOB , / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 ;DEF F989:<9=. 1 SELECT DEPTNO$SUM(SAL) FROM 2 EMP )# GROUP BY (DEPTNO) S"L4 / DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 13 20.3 23 1320. )3 ,33 1 SELECT SUM(SAL) FROM 2 EMP )# GROUP BY () , / SUM(SAL) &&&&&&&&&& 2 32. CUBE: CUBE RETURNS SAME AS ROLL UP J ALL INDIVIDUAL JOBS SUM SALARIES. 1 SELECT DEPTNO$JOB$SUM(SAL) 2 FROM EMP )# GROUP BY CUBE(DEPTNO$JOB)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 13 20.3 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. 23 1320. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 )3 ,33 ANALYST /333 CLER' ,1.3 MANAGER 220. PRESIDENT .333 SALESMAN ./33

1)

2 32. 21 ;DEF F989:<9=. T.E ABO*E QUERY IS CO)BINATION OF : GROUP BY DEPTNO$JOB. GROUP BY DEPTNO. GROUP BY JOB. GROUP BY ().

1 SELECT DEPTNO$JOB$SUM(SAL) FROM 2 EMP )# GROUP BY DEPTNO$JOB , / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 ;DEF F989:<9=.

1 SELECT DEPTNO$SUM(SAL) FROM 2 EMP )# GROUP BY (DEPTNO) S"L4 / DEPTNO SUM(SAL)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
&&&&&&&&&& &&&&&&&&&& 13 20.3 23 1320. )3 ,33 1 SELECT SUM(SAL) FROM 2 EMP )# GROUP BY () , / SUM(SAL) &&&&&&&&&& 2 32. S"L4 SELECT JOB$SUM(SAL) FROM EMP 2 GROUP BY JOB5 JOB SUM(SAL) &&&&&&&&& &&&&&&&&&& ANALYST /333 CLER' ,1.3 MANAGER 220. PRESIDENT .333 SALESMAN ./33

1,3

GROUPING FUNCTION: 1 SELECT DEPTNO$JOB$SUM(SAL)$ 2 GROUPING(DEPTNO) GR(DEPTNO$ ) GROUPING(JOB) GR(JOB , FROM EMP .# GROUP BY ROLLUP(DEPTNO$JOB) / / DEPTNO JOB SUM(SAL) GR(DEPTNO &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 13 20.3 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. 23 1320. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 )3 ,33 2 32. 1. ;DEF F989:<9=. 1 SELECT DEPTNO$JOB$SUM(SAL)$ 2 GROUPING(DEPTNO) GR(DEPTNO$ ) GROUPING(JOB) GR(JOB , FROM EMP .# GROUP BY CUBE(DEPTNO$JOB) S"L4 / DEPTNO JOB SUM(SAL) GR(DEPTNO GR(JOB &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 3 3 GR(JOB 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 1 3 1 1 3 3 3 3 3 1 3 3 3 1

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
13 MANAGER 13 PRESIDENT 13 23 ANALYST 23 CLER' 23 MANAGER 23 )3 CLER' )3 MANAGER )3 SALESMAN )3 ANALYST CLER' MANAGER PRESIDENT SALESMAN 2,.3 .333 20.3 /333 1 33 2 0. 1320. .3 22.3 ./33 ,33 /333 ,1.3 220. .333 ./33 3 1 2 32. 21 ;DEF F989:<9=. GROUPING SETS: 1 SELECT DEPTNO$JOB$MGR MANAGER(NO$AVG(SAL) 2 FROM EMP ) GROUP BY GROUPING SETS ,# ((DEPTNO$JOB)$(JOB$MGR)) S"L4 / DEPTNO JOB MANAGER(NO AVG(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST )333 23 CLER' .3 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN 1,33 ANALYST CLER' CLER' CLER' CLER' MANAGER PRESIDENT SALESMAN 1 ;DEF F989:<9=. 1 SELECT DEPTNO$JOB$MGR MANAGER(NO$SUM(SAL) 2 FROM EMP ) GROUP BY GROUPING SETS ,# ((DEPTNO$JOB)$(JOB$MGR)) S"L4 / DEPTNO JOB MANAGER(NO SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 0.// 0/ 2 0022 0022 0 32 02) 0/ 2 )333 .3 1)33 1133 233 20.2.))))) .333 1,33 1 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 3 1 3 1 3 3 1 3 3 3 1 3 3 3 1 3 3 3 3 3 3

1,1

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
23 CLER' 23 MANAGER )3 CLER' )3 MANAGER )3 SALESMAN ANALYST CLER' CLER' CLER' CLER' MANAGER PRESIDENT SALESMAN 10 ;DEF F989:<9=. T.E ABO*E IS CO)BINATION OF: GROUP BY DEPT$JOB. GROUP BY JOB$MGR. 1 33 2 0. .3 22.3 ./33 /333 .3 1)33 1133 233 220. .333 0/ 2 ./33 0.// 0/ 2 0022 0022 0 32 02)

1,2

1 SELECT DEPTNO$JOB$SUM(SAL) 2 FROM EMP )# GROUP BY(DEPTNO$JOB) S"L4 / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 ;DEF F989:<9=. 1 SELECT JOB$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY(JOB$MGR) S"L4 / JOB MGR SUM(SAL) &&&&&&&&& &&&&&&&&&& &&&&&&&&&& ANALYST 0.// /333 CLER' 0/ 2 .3 CLER' 0022 1)33 CLER' 0022 1133 CLER' 0 32 233 MANAGER 02) 220. PRESIDENT .333 SALESMAN 0/ 2 ./33 2 ;DEF F989:<9=.

CO)POSITE COLU)NS: 1 SELECT DEPTNO$JOB$MGR MANAGER(NO$SUM(SAL) 2 FROM EMP )# GROUP BY ROLLUP(DEPTNO$(JOB$MGR)) S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DEPTNO JOB MANAGER(NO SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 0022 1)33 13 MANAGER 02) 2,.3 13 PRESIDENT .333 13 20.3 23 ANALYST 0.// /333 23 CLER' 0022 1133 23 CLER' 0 32 233 23 MANAGER 02) 2 0. 23 1320. )3 CLER' 0/ 2 .3 )3 MANAGER 02) 22.3 )3 SALESMAN 0/ 2 ./33 )3 ,33 2 32. 1, ;DEF F989:<9=. T.E ABO*E IS CO)BINATION OF BELO+: GROUP BY DEPTNO$JOB$MGR. GROUP BY DEPTNO. GROUP BY.

1,)

T.E ABO*E QUERY DISPLAYS T.E FOLLO+ING: TOTAL SALARY FOR EVERY DEPARTMENT. TOTAL SALARY FOR EVERY DEPARTMENT$JOB$MGR. GRNAD TOTAL.

1 SELECT DEPTNO$JOB$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO$JOB$MGR S"L4 / DEPTNO JOB MGR SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 0022 1)33 13 MANAGER 02) 2,.3 13 PRESIDENT .333 23 ANALYST 0.// /333 23 CLER' 0022 1133 23 CLER' 0 32 233 23 MANAGER 02) 2 0. )3 CLER' 0/ 2 .3 )3 MANAGER 02) 22.3 )3 SALESMAN 0/ 2 ./33 13 ;DEF F989:<9=. 1 SELECT DEPTNO$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO , / DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 13 20.3 23 1320. )3 ,33

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 SELECT SUM(SAL) 2 FROM EMP )# GROUP BY() , / SUM(SAL) &&&&&&&&&& &&&&&&&&&& 2 32.

1,,

1 SELECT DEPTNO$JOB$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY CUBE(DEPTNO$(JOB$MGR)) S"L4 / DEPTNO JOB MGR SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 23 ANALYST 0.// /333 )3 CLER' 0/ 2 .3 13 CLER' 0022 1)33 23 CLER' 0022 1133 23 CLER' 0 32 233 13 MANAGER 02) 2,.3 23 MANAGER 02) 2 0. )3 MANAGER 02) 22.3 13 PRESIDENT .333 )3 SALESMAN 0/ 2 ./33 ANALYST 0.// /333 CLER' 0/ 2 .3 CLER' 0022 1)33 CLER' 0022 1133 CLER' 0 32 233 MANAGER 02) 220. PRESIDENT .333 SALESMAN 0/ 2 ./33 13 20.3 23 1320. )3 ,33 2 32. 22 ;DEF F989:<9=.

CONCATENATED GROUPING: 1 SELECT DEPTNO$JOB$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO$ROLLUP(JOB)$CUBE(MGR) S"L4 / DEPTNO JOB MGR SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 0022 1)33 13 MANAGER 02) 2,.3 13 PRESIDENT .333 23 ANALYST 0.// /333 23 CLER' 0022 1133 23 MANAGER 02) 2 0. 23 CLER' 0 32 233

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
)3 CLER' )3 SALESMAN )3 MANAGER 13 13 13 23 23 23 23 )3 )3 13 CLER' 13 MANAGER 13 PRESIDENT 13 23 ANALYST 23 CLER' 23 MANAGER 23 )3 CLER' )3 MANAGER )3 SALESMAN )3 )1 ;DEF F989:<9=. 0/ 2 0/ 2 02) 0022 02) .3 ./33 22.3 1)33 2,.3 .333 0.// /333 0022 1133 02) 2 0. 0 32 233 0/ 2 /..3 02) 22.3 1)33 2,.3 .333 20.3 /333 1 33 2 0. 1320. .3 22.3 ./33 ,33

1,.

T.E ABO*E QUERY IS CO)BINATION OF BELO+ QUERIES: GROUP BY DEPTNO$JOB$MGR. GROUP BY DEPTNO$MGR. GROUP BY DEPTNO$JOB. GROUP BY DEPTNO.

T.E ABO*E QUERY DISPLAYS T.E FOLLO+ING: TOTAL SALARY FOR EVERY DEPARTEMENT NO$JOB$MGR. TOTAL SALARY FOR EVERY DEPARTEMENT NO$MGR. TOTAL SALARY FOR EVERY DEPARTEMENT NO$JOB. TOTAL SALARY FOR EVERY DEPARTEMENT NO.

1 SELECT DEPTNO$JOB$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO$JOB$MGR S"L4 / DEPTNO JOB MGR SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 CLER' 0022 1)33 13 MANAGER 02) 2,.3 13 PRESIDENT .333 23 ANALYST 0.// /333 23 CLER' 0022 1133 23 CLER' 0 32 233 23 MANAGER 02) 2 0. )3 CLER' 0/ 2 .3 )3 MANAGER 02) 22.3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
)3 SALESMAN 13 ;DEF F989:<9=. 1 SELECT DEPTNO$MGR$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO$MGR , / DEPTNO MGR SUM(SAL) &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 13 0022 13 02) 13 .333 23 0.// 23 0022 23 02) 23 0 32 )3 0/ 2 )3 02) ;DEF F989:<9=. 1 SELECT DEPTNO$JOB$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO$JOB S"L4 / DEPTNO JOB SUM(SAL) &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 13 CLER' 1)33 13 MANAGER 2,.3 13 PRESIDENT .333 23 ANALYST /333 23 CLER' 1 33 23 MANAGER 2 0. )3 CLER' .3 )3 MANAGER 22.3 )3 SALESMAN ./33 ;DEF F989:<9=. 0/ 2 ./33

1,/

1)33 2,.3 /333 1133 2 0. 233 /..3 22.3

1 SELECT DEPTNO$SUM(SAL) 2 FROM EMP )# GROUP BY DEPTNO S"L4 / DEPTNO SUM(SAL) &&&&&&&&&& &&&&&&&&&& 13 20.3 23 1320. )3 ,33 TYPES OF )ULTIPLE INSERT STATE)ENTS: UNCONDITIONAL INSERT. CONDITIONAL ALL INSERT. CONDITIONAL FIRST. PIVOTING INSERT.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
UNCONDITIONAL INSERT ALL: S"L4 CREATE TABLE SAL(HISTORY 2 (EMPNO NUMBER(13)$ ) HIREDATE DATE$ , SAL NUMBER(13$2))5 T6789 :;96<9=. 1 CREATE TABLE MGR(HISTORY 2 (EMPNO NUMBER(13)$ ) MGR NUMBER(13)$ ,# SAL NUMBER(13$2)) . / T6789 :;96<9=. S"L4 INSERT ALL 2 INTO SAL(HISTORY VALUES(EMPNO$HIREDATE$SAL) ) INTO MGR(HISTORY VALUES(EMPNO$MGR$SAL) , SELECT EMPNO$HIREDATE$SAL$MGR FROM EMP5 22 ;DEF :;96<9=. S"L4 SELECT # FROM SAL(HISTORY5 EMPNO HIREDATE SAL &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 0)/ 10&DEC&23 233 0, 23&FEB&21 1/33 0.21 22&FEB&21 12.3 0.// 32&APR&21 2 0. 0/., 22&SEP&21 12.3 0/ 2 31&MAY&21 22.3 0022 3 &JUN&21 2,.3 0022 1 &APR&20 )333 02) 10&NOV&21 .333 02,, 32&SEP&21 1.33 020/ 2)&MAY&20 1133 0 33 3)&DEC&21 .3 0 32 3)&DEC&21 )333 0 ), 2)&JAN&22 1)33 1, ;DEF F989:<9=.

1,0

1# SELECT # FROM MGR(HISTORY S"L4 / EMPNO MGR SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ 0 32 233 0, 0/ 2 1/33 0.21 0/ 2 12.3 0.// 02) 2 0. 0/., 0/ 2 12.3 0/ 2 02) 22.3 0022 02) 2,.3 0022 0.// )333 02) .333 02,, 0/ 2 1.33 020/ 0022 1133 0 33 0/ 2 .3 0 32 0.// )333 0 ), 0022 1)33

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1, ;DEF F989:<9=. S"L4 DELETE FROM SAL(HISTORY5 1, ;DEF =989<9=. S"L4DELETE FROM MGR(HISTORY5 1, ;DEF =989<9=. S"L4 INSERT ALL 2 INTO SAL(HISTORY VALUES(EMPNO$HIREDATE$SAL) ) INTO MGR(HISTORY VALUES(EMPNO$MGR$SAL) , SELECT EMPNO$HIREDATE$SAL$MGR FROM EMP . WHERE DEPTNOI235 13 ;DEF :;96<9=. S"L4 SELECT # FROM SAL(HISTORY5 EMPNO HIREDATE SAL &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 0)/ 10&DEC&23 233 0.// 32&APR&21 2 0. 0022 1 &APR&20 )333 020/ 2)&MAY&20 1133 0 32 3)&DEC&21 )333 1# SELECT # FROM MGR(HISTORY S"L4 / EMPNO MGR SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ 0 32 233 0.// 02) 2 0. 0022 0.// )333 020/ 0022 1133 0 32 0.// )333 S"L4 DELETE FROM SAL(HISTORY5 . ;DEF =989<9=. 1# DELETE FROM MGR(HISTORY S"L4 / . ;DEF =989<9=. CONDITIONAL INSERT ALL: 1 INSERT ALL 2 WHEN SAL 4 2333 THEN ) INTO SAL(HISTORY VALUES(EMPNO$HIREDATE$SAL) , WHEN DEPTNO 4 13 THEN . INTO MGR(HISTORY VALUES(EMPNO$MGR$SAL) /# SELECT EMPNO$HIREDATE$SAL$MGR$DEPTNO FROM EMP 0 / 10 ;DEF :;96<9=. S"L4 SELECT # FROM SAL(HISTORY5

1,2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMPNO HIREDATE SAL &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 0.// 32&APR&21 2 0. 0/ 2 31&MAY&21 22.3 0022 3 &JUN&21 2,.3 0022 1 &APR&20 )333 02) 10&NOV&21 .333 0 32 3)&DEC&21 )333 / ;DEF F989:<9=. 1# SELECT # FROM MGR(HISTORY S"L4 / EMPNO MGR SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ 0 32 233 0, 0/ 2 1/33 0.21 0/ 2 12.3 0.// 02) 2 0. 0/., 0/ 2 12.3 0/ 2 02) 22.3 0022 0.// )333 02,, 0/ 2 1.33 020/ 0022 1133 0 33 0/ 2 .3 0 32 0.// )333 11 ;DEF F989:<9=.

1,

S"L4 DELETE FROM SAL(HISTORY5 / ;DEF =989<9=. S"L4 DELETE FROM MGR(HISTORY5 11 ;DEF =989<9=. S"L4 INSERT FIRST 2 WHEN SAL I .333 THEN ) INTO SAL(HISTORY VALUES(EMPNO$HIREDATE$SAL) , WHEN DEPTNO 4 13 THEN . INTO MGR(HISTORY VALUES(EMPNO$MGR$SAL) / WHEN DEPTNO 4 23 THEN 0 INTO MGR(HISTORY VALUES(EMPNO$MGR$SAL) 2 ELSE INTO MGR(HISTORY VALUES(EMPNO$MGR$SAL) 13 SELECT EMPNO$HIREDATE$SAL$MGR$DEPTNO FROM EMP5 1, ;DEF :;96<9=.

S"L4 SELECT # FROM SAL(HISTORY5 EMPNO HIREDATE SAL &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 02) 10&NOV&21 .333 S"L4 SELECT # FROM MGR(HISTORY5 EMPNO MGR SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0)/ 0, 0.21 0.// 0/., 0/ 2 0022 02,, 020/ 0 33 0 32 0022 0 ), 0 32 0/ 2 0/ 2 02) 0/ 2 02) 0.// 0/ 2 0022 0/ 2 0.// 02) 0022 233 1/33 12.3 2 0. 12.3 22.3 )333 1.33 1133 .3 )333 2,.3 1)33

1.3

1) ;DEF F989:<9=. CONDITIONAL FIRST INSERT: S"L4 CREATE TABLE SPECIAL(SAL 2 (DEPTNO NUMBER(13)$ ) SAL NUMBER(13))5 T6789 :;96<9=. S"L4 CREATE TABLE HIREDATE(HIS(21 2 (DEPTNO NUMBER(13)$ ) HIREDATE DATE)5 T6789 :;96<9=. 1 CREATE TABLE HIREDATE(HIS(20 2 (DEPTNO NUMBER(13)$ )# HIREDATE DATE) , / T6789 :;96<9=. 1 CREATE TABLE HIREDATE(HIS 2 (DEPTNO NUMBER(13)$ )# HIREDATE DATE) , / T6789 :;96<9=. INSERT FIRST WHEN SAL 4 2333 THEN INTO SPECIAL(SAL VALUES(DEPTNO$SAL) WHEN HIREDATE LI'E (C-21-C) THEN INTO HIREDATE(HIS(21 VALUES (DEPTNO$HIREDATE) WHEN HIREDATE LI'E (C-20-C) THEN INTO HIREDATE(HIS(20 VALUES (DEPTNO$HIREDATE) ELSE INTO HIREDATE(HIS VALUES (DEPTNO$HIREDATE) 13# SELECT DEPTNO$SAL$HIREDATE FROM EMP S"L4 / 1, ;DEF :;96<9=. S"L4 SELECT # FROM SPECIAL(SAL5 DEPTNOSAL &&&&&&&&&& &&&&&&&&&& 23 2 0. )3 22.3 13 2,.3 23 )333 1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
13 23 .333 )333 / ;DEF F989:<9=. S"L4 SELECT # FROM HIREDATE(HIS(215 DEPTNO HIREDATE &&&&&&&&&& &&&&&&&&& )3 23&FEB&21 )3 22&FEB&21 )3 22&SEP&21 )3 32&SEP&21 )3 3)&DEC&21 S"L4 SELECT # FROM HIREDATE(HIS(205 DEPTNO HIREDATE &&&&&&&&&& &&&&&&&&& 23 2)&MAY&20 S"L4 SELECT # FROM HIREDATE(HIS5 DEPTNO HIREDATE &&&&&&&&&& &&&&&&&&& 23 10&DEC&23 13 2)&JAN&22

1.1

1 CREATE TABLE SPECIAL(SAL1 2 (DEPTNO NUMBER(13)$ ) SAL NUMBER(13)$ ,# HIREDATE DATE) S"L4 / T6789 :;96<9=. 1 CREATE TABLE HIREDATE(HIS(21(1 2 (DEPTNO NUMBER(13)$ ) HIREDATE DATE$ ,# SAL NUMBER) S"L4 / T6789 :;96<9=. 1 CREATE TABLE HIREDATE(HIS(20(1 2 (DEPTNO NUMBER(13)$ ) HIREDATE DATE$ ,# SAL NUMBER) . / T6789 :;96<9=. 1 CREATE TABLE HIREDATE(HIS(1 2 (DEPTNO NUMBER(13)$ ) HIREDATE DATE$ ,# SAL NUMBER) . / T6789 :;96<9=. 1 INSERT FIRST 2 WHEN SAL 4 2333 THEN ) INTO SPECIAL(SAL1 VALUES(DEPTNO$SAL$HIREDATE)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
WHEN HIREDATE LI'E (C-21-C) THEN INTO HIREDATE(HIS(21(1 VALUES (DEPTNO$HIREDATE$SAL) WHEN HIREDATE LI'E (C-20-C) THEN INTO HIREDATE(HIS(20(1 VALUES (DEPTNO$HIREDATE$SAL) ELSE INTO HIREDATE(HIS(1 VALUES (DEPTNO$HIREDATE$SAL) 13# SELECT DEPTNO$SAL$HIREDATE FROM EMP S"L4 / 1, ;DEF :;96<9=. , . / 0 2

1.2

S"L4 SELECT # FROM SPECIAL(SAL15 DEPTNO SAL HIREDATE &&&&&&&&&& &&&&&&&&&& &&&&&&&&& 23 2 0. 32&APR&21 )3 22.3 31&MAY&21 13 2,.3 3 &JUN&21 23 )333 1 &APR&20 13 .333 10&NOV&21 23 )333 3)&DEC&21 / ;DEF F989:<9=. S"L4 SELECT # FROM HIREDATE(HIS(15 DEPTNO HIREDATE SAL &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 23 10&DEC&23 233 13 2)&JAN&22 1)33 1# SELECT # FROM HIREDATE(HIS(21(1 S"L4 / DEPTNO HIREDATE SAL &&&&&&&&&& &&&&&&&&& &&&&&&&&&& )3 23&FEB&21 1/33 )3 22&FEB&21 12.3 )3 22&SEP&21 12.3 )3 32&SEP&21 1.33 )3 3)&DEC&21 .3 1# SELECT # FROM HIREDATE(HIS(20(1 S"L4 / DEPTNO HIREDATE SAL &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 23 2)&MAY&20 1133 S"L4 DELETE FROM SPECIAL(SAL15 / ;DEF =989<9=. S"L4 DELETE FROM HIREDATE(HIS(15 2 ;DEF =989<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1# DELETE FROM HIREDATE(HIS(21(1 S"L4 / . ;DEF =989<9=. 1# DELETE FROM HIREDATE(HIS(20(1 S"L4 / 1 ;DE =989<9=. INSERT FIRST WHEN SAL 4 .333 THEN INTO SPECIAL(SAL1 VALUES(DEPTNO$SAL$HIREDATE) WHEN HIREDATE LI'E (C-21-C) THEN INTO HIREDATE(HIS(21(1 VALUES (DEPTNO$HIREDATE$SAL) WHEN HIREDATE LI'E (C-20-C) THEN INTO HIREDATE(HIS(20(1 VALUES (DEPTNO$HIREDATE$SAL) ELSE INTO HIREDATE(HIS(1 VALUES (DEPTNO$HIREDATE$SAL) 13# SELECT DEPTNO$SAL$HIREDATE FROM EMP 11 / 1, ;DEF :;96<9=. S"L4 SELECT # FROM SPECIAL(SAL15 KD ;DEF F989:<9= 1 2 ) , . / 0 2

1.)

S"L4 SELECT # FROM HIREDATE(HIS(21(15 DEPTNO HIREDATE SAL &&&&&&&&&& &&&&&&&&& &&&&&&&&&& )3 23&FEB&21 1/33 )3 22&FEB&21 12.3 23 32&APR&21 2 0. )3 22&SEP&21 12.3 )3 31&MAY&21 22.3 13 3 &JUN&21 2,.3 13 10&NOV&21 .333 )3 32&SEP&21 1.33 )3 3)&DEC&21 .3 23 3)&DEC&21 )333 13 ;DEF F989:<9=.

S"L4 SELECT # FROM HIREDATE(HIS(20(15 DEPTNO HIREDATE SAL &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 23 1 &APR&20 )333 23 2)&MAY&20 1133 S"L4 SELECT # FROM HIREDATE(HIS5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DEPTNO HIREDATE &&&&&&&&&& &&&&&&&&& 23 10&DEC&23 13 2)&JAN&22 PI*OTING INSERT: S"L4 CREATE TABLE SALES(SOURCE(DATA 2 (EMPLOYEE(ID NUMBER(13)$ ) WEE'(ID NUMBER(2)$ , SALES(MON NUMBER(13)$ . SALES(TUE NUMBER(13)$ / SALES(WED NUMBER(13)$ 0 SALES(THUR NUMBER(13)$ 2 SALES(FRI NUMBER(13))5 T6789 :;96<9=. S"L4 INSERT INTO SALES(SOURCE(DATA 2 VALUES ) (1$/$2333$)333$,333$.333$/333)5 1 ;DE :;96<9=. S"L4 CREATE TABLE SALES(INFO 2 (EMPLOYEE(ID NUMBER(13)$ ) WEE' NUMBER(13)$ , SALES NUMBER(13))5 T6789 :;96<9=. 1 INSERT ALL 2 INTO SALES(INFO VALUES(EMPLOYEE(ID$WEE'(ID$SALES(MON) ) INTO SALES(INFO VALUES(EMPLOYEE(ID$WEE'(ID$SALES(TUE) , INTO SALES(INFO VALUES(EMPLOYEE(ID$WEE'(ID$SALES(WED) . INTO SALES(INFO VALUES(EMPLOYEE(ID$WEE'(ID$SALES(THUR) / INTO SALES(INFO VALUES(EMPLOYEE(ID$WEE'(ID$SALES(FRI) 0 SELECT EMPLOYEE(ID$WEE'(ID$SALES(MON$SALES(TUE$SALES(WED$ 2# SALES(THUR$SALES(FRI FROM SALES(SOURCE(DATA S"L4 / . ;DEF :;96<9=. S"L4 SELECT # FROM SALES(INFO5 EMPLOYEE(ID WEE' &&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 1 / 2333 1 / )333 1 / ,333 1 / .333 1 / /333 SCALAR SUBQUERIES: A SCALAR THAT RETURNS E!ACTLY ONE COLUMN VALUE FROM ONE ROW IS REFERED AS A SCALAR SUB "UERY. SCALAR SUBQUERIES IN CASE: SALES

1.,

1 SELECT EMPNO$ENAME$DEPTNO$ 2 (CASE

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) WHEN DEPTNO I (SELECT DEPTNO FROM DEPT , WHERE LOC I CNEW YOR'C) . THEN CCANADAC ELSE CUSAC END) LOCATION /# FROM EMP S"L4 / EMPNO ENAME DEPTNO LOCATI &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&& 0)/ SMITH 23 USA 0, ALLEN )3 USA 0.21 WARD )3 USA 0.// JONES 23 USA 0/., MARTIN )3 USA 0/ 2 BLA'E )3 USA 0022 CLAR' 13 CANADA 0022 SCOTT 23 USA 02) 'ING 13 CANADA 02,, TURNER )3 USA 020/ ADAMS 23 USA 0 33 JAMES )3 USA 0 32 FORD 23 USA 0 ), MILLER 13 CANADA 1, ;DEF F989:<9=.

1..

S"L4 SELECT # FROM DEPT5 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 ACCOUNTING NEW YOR' 23 RESEARCH DALLAS )3 SALES CHICAGO ,3 OPERATIONS BOSTON S"L4 SELECT EMPNO$ENAME 2 FROM EMP E ) ORDER BY (SELECT , DNAME FROM DEPT D . WHERE E.DEPTNOID.DEPTNO)5 EMPNO ENAME &&&&&&&&&& &&&&&&&&&& 0022 CLAR' 02) 'ING 0 ), MILLER 0)/ SMITH 020/ ADAMS 0 32 FORD 0022 SCOTT 0.// JONES 0, ALLEN 0/ 2 BLA'E 0/., MARTIN 0 33 JAMES 02,, TURNER 0.21 WARD 1, ;DEF F989:<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CORRELATED SUBQUERY: FINDING EMPLOYEES WHOSE SAL IS GREATER THAN AVG(SAL) OF THEIR DEPARTMENT. S"L4 SELECT ENAME$SAL$DEPTNO FROM EMP E 2 WHERE SAL 4 (SELECT AVG(SAL) FROM EMP ) WHERE DEPTNOIE.DEPTNO)5 ENAME SAL DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& ALLEN 1/33 )3 JONES 2 0. 23 BLA'E 22.3 )3 SCOTT 'ING FORD )333 .333 )333 23 13 23

1./

/ ;DEF F989:<9=. FINDING EMPLOYEES WHOSE SAL IS GREATER THAN MIN(SAL) OF THEIR DEPARTMENT. 1 SELECT ENAME$SAL$DEPTNO FROM EMP E 2 WHERE SAL 4 (SELECT MIN(SAL) FROM EMP )# WHERE DEPTNOIE.DEPTNO) S"L4 / ENAME SAL DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& ALLEN 1/33 )3 WARD 12.3 )3 JONES 2 0. 23 MARTIN 12.3 )3 BLA'E 22.3 )3 CLAR' 2,.3 13 SCOTT )333 23 'ING .333 13 TURNER 1.33 )3 ADAMS 1133 23 FORD )333 23 11 ;DEF F989:<9=. E/ISTS: FIND E)PLOYEES +.O .A*E ATLEAT ONE PERSON REPORTING TO T.E)( 1 SELECT EMPNO$ENAME$JOB$DEPTNO FROM EMP E 2 WHERE E!ISTS )# (SELECT C!C FROM EMP WHERE MGRIE.EMPNO) S"L4 / EMPNO ENAME JOB DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 0.// JONES MANAGER 23 0/ 2 BLA'E MANAGER )3 0022 CLAR' MANAGER 13 0022 SCOTT ANALYST 23 02) 'ING PRESIDENT 13 0 32 FORD ANALYST 23 / ;DEF F989:<9=. T.E SA)E QUERY +IT. IN: 1 SELECT EMPNO$ENAME$JOB$DEPTNO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 FROM EMP ) WHERE EMPNO IN (SELECT MGR FROM EMP ,# WHERE MGR IS NOT NULL) S"L4 / EMPNO ENAME JOB DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& 0.// JONES MANAGER 23 0/ 2 BLA'E MANAGER )3 0022 CLAR' MANAGER 13 0022 SCOTT ANALYST 23 02) 'ING PRESIDENT 13 0 32 FORD ANALYST 23 / ;DEF F989:<9=.

1.0

NOT E/ISTS: FIND ALL T.E DEPART)ENTS T.AT DO NOT .A*E ANY E)PLOYEES: S"L4 SELECT DEPTNO$DNAME 2 FROM DEPT D ) WHERE NOT E!ISTS , (SELECT C!C FROM EMP . WHERE DEPTNOID.DEPTNO)5 DEPTNO DNAME &&&&&&&&&& &&&&&&&&&&&&&& ,3 OPERATIONS SA)E QUERY +IT. NOT IN: S"L4 SELECT DEPTNO$DNAME FROM DEPT 2 WHERE DEPTNO NOT IN ) (SELECT DEPTNO FROM EMP)5 DEPTNO DNAME &&&&&&&&&& &&&&&&&&&&&&&& ,3 OPERATIONS INSERT +IT. SUBQUERY: 1 INSERT INTO 2 (SELECT EMPNO$ENAME$JOB$DEPTNO FROM EMP) ) VALUES ,# (133$CPAVANC$CMANAGERC$13) S"L4 / 1 ;DE :;96<9=.

INSERT +IT. SUBQUERY +IT. C.EC- OPTION: 1 INSERT INTO 2 (SELECT EMPNO$ENAME$JOB$DEPTNO ) FROM EMP WHERE DEPTNOI)3 WITH CHEC' OPTION) , VALUES

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
.# (133$CPAVANC$CMANAGERC$13) S"L4 / INSERT INTO # ERROR 6< 8NK9 1% ORA&31,32% QN9E WITH CHEC' OPTION ER9;9&:86?F9 QND86<NDK 1 INSERT INTO 2 (SELECT EMPNO$ENAME$JOB ) FROM EMP WHERE DEPTNOI)3 WITH CHEC' OPTION) , VALUES .# (133$CPAVANC$CMANAGERC) S"L4 / INSERT INTO # ERROR 6< 8NK9 1% ORA&31,32% QN9E WITH CHEC' OPTION ER9;9&:86?F9 QND86<NDK

1.2

1 INSERT INTO 2 (SELECT EMPNO$ENAME$JOB$DEPTNO ) FROM EMP WHERE DEPTNOI)3 WITH CHEC' OPTION) , VALUES .# (131$CPAVANC$CMANAGERC$)3) S"L4 / 1 ;DE :;96<9=. DEFAULT: S"L4 CREATE TABLE SAMPLE 2 (EMPNO NUMBER(13)$ ) ENAME VARCHAR2(13)$ , SAL NUMBER(13) DEFAULT 1333)5 T6789 :;96<9=. S"L4 INSERT INTO SAMPLE 2 VALUES ) (1$CPAVANC$133)5 1 ;DE :;96<9=. 1 INSERT INTO SAMPLE 2 VALUES )# (1$CPAVANC$DEFAULT) S"L4 / 1 ;DE :;96<9=. S"L4 UPDATE SAMPLE 2 SET SAL I DEFAULT ) WHERE EMPNOI15 2 ;DEF ?B=6<9=. S"L4 SELECT # FROM SAMPLE5 EMPNO ENAME SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 1 PAVAN 1333 1 PAVAN 1333

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE

1.

INTRODUCTION TO PL0SQL: TILL NOW WE USED S"L TO "UERY DATABASE FOR DATA.S"L IS A FOUTH GENERATION LANGUAGE.THIS MEANS THAT THE LANGUAGE DESCRIBES WHAT SHOULD BE DONE$ BUT NOT HOW TO DO IT. FOR E!AMPLE % DELETE FROM EMP WHERE JOBICLER'5 HERE WE DONT 'NOW HOW THE DATABASE ACTUALLY DETERMINES WHICH EMPLOYEES ARE CLER'S. PROBABLY THE SERVER WILL LOOP THROUGH ALL THE RECORDS IN SOME ORDERTO DETERMINE THE PROPER ENTRIES TO DELETE.BUT THE DETAILS ARE HIDEN FROM US. THIRD GENERATION LANGUAGES SUCH AS C OR COBOL$ ARE MORE PROCEDURAL IN NATURE. A PROGRAM IN A THIRD GENERATION LANGUAGE IMPLEMENTS STEP BY STEP ALGORITHM TO SLOVE THE PROBLEM.FOR E!AMPLE WE ACCOMPLISH ABOVE DELETE OPERATION LI'E THIS IN THIS ) GL. LOOP OVER EACH STUDENT RECORD IF THIS RECORD HAS JOB I CLER' THEN DELETE THIS RECORD5 END IF5 END LOOP5 OBJECT ORIENTED LANGUAGES SUCH AS CJJ OR JAVA ARE ALSO THIRD GENERATION LANGUAGES DO THE SAME AS GC. FOURTH GENERATION LANGUAGES SUCH AS S"L ARE FAIRLY SIMPLE COMPARED TO THE ) RD GENARATION LANGUAGES AND HAVE FEWER COMMANDS. HOW EVER IN SOME CASES PROCEDURAL CONSTRUCTS SUCH AS VARIABLES$ CONTROL STRUCTURES SUCH AS IF THEN ELSE STATEMENTS AND LOOPS AND PROCEDURES AND FUCTIONS ETC ARE MORE USEFUL FOR DESIRED PROGRAM.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
THE BASIC UNIT IN ANY PL/S"L PROGRAM IS A BLOC'. THERE ARE TWO DIFFERENT 'INDS OF BLOC'S% ANONYMOUS BLOC' NAMED BLOC'.

1/3

THIS IS WHERE PL/S"L COMES IN TO THE PICTURE. PL/S"L IS COMBINATION OF POWER AND THE FLE!IBILITY OF S"L WITH THE PROCEDURAL CONSTRUCTS OF )RD GENERATION LANGUAGES.

ANONYMOUS BLOC'S ARE GENERALLY CONSTRUCTED ONCE AND E!CECUTED ONLY ONCE.THIS TYPE OF BLOC' IS OFTEN ISSUED FROM A CLIENT PROGRAM TO CALL A SUBPROGRAM STORED IN THE DATABASE. NAMED BLOC'S ARE BLOC'S THAT HAVE NAME ASSOCIATED WITH THEM.NAMED BLOC'S FURTHER CLASSIFIED IN TO ) TYPES LABELED BLOC'S. SUBPROGRAMS(STOREDPROCEDURE AND FUNCTION). TRIGGERS.

LABELED BLOC'S ARE ANONYMOUS BLOC'S ARE GENERALLY CONSTRUCTED ONCE AND E!CECUTED ONLY ONCE.ARE USED SAME AS ANONYMOUS BLOC'S. SUBPROGRAMS CONSISTS OF PROCEDURES AND FUNCTIONS. THEY CAN BE STORED IN THE DATABASE AS STANDALONE OBJECTS.THEY GENERALLY DONT CHANGE ONCE CONSTRUCTED.THEYCAN E!ECUTED MANY TIMES.SUBPROGRAMS E!ECUTED E!PLICITLY VIA CALL TO PROCEDURE OR FUNCTION. TRIGGERS CONSIST OF PL/S"L BLOC'.THEY ARE GENERALLY DONT CHANGE ONCE THEY CONSTRUCTED AND E!ECUTED MANY TIMES.TRIGGERS E!ECUTED IMPLICTLY WHENEVER TRIGGERING EVENT OCCURS.THE TRIGGERING EVENT MAY BE DML STATEMENT OR DDL STATEMENT(CREATE OR DROP) OR DATABASE EVENT SUCH AS START UP OR SHUTDOWN. BASIC PL0SQL BLOC-: DECLARE DECLARATIVE SECTION IS HERE.WE DECLARE ALL VARIABLES ETC. BEGIN E!ECUTABLE SECTION IS HERE.ALL S"L STATEMENTS AND PROCEDURAL CONSTRUCTS. E!CEPTION E!CEPTION SECTION HERE.ERRORS HANDLING STATEMENTS GOES HERE. END5 DECLARE AND E!CEPTION IS OPTIONAL.THAT IS EVERY PL/S"L BLOC' SHOULD HAVE BEGIN AND END.

DECLARING PL0SQL *ARIABLES:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DECLARE V(HIREDATE V(DEPTNO V(LOC V(COMM V(SAL DATE5 NUMBER(13) NOT NULL %I 135 VARCHAR2(13) %I GNEW YOR'5 CONSTANT NUMBER %I1,335

1/1

NUMBER(13) DEFAULT 13335

ASSIGNING *ALUES TO *ARIABLES: V(DEPTNO V(LOC NUMBER(13) NOT NULL %I 135 VARCHAR2(13) %I GNEW YOR'5

BASE SCALAR DATATYPES: VARCHAR2(MA!(LEN) NUMBER(P$S)5 DATE CHAR(MA!(LEN) LONG LONG RAW BOOLEAN BINARY(INTEGER PLS(INTEGER DECLARE V(JOB V(COUNT V(VALID VARCHAR2(13)5 NUMBER(2) %I35 BOOLEAN NOT NULL %I TRUE5

DECLARING *ARIABLES +IT. 5TYPE ATTRIBUTES: V(ENAME V(JOB VARCHAR2(13)5 EMP.JOB-TYPE5

THE ADVANTAGE OF DECLARING THIS TYPE IS FOR US NO NEED WORRY ABOUT THE LENGH OF THE VARIABLES.V(JOB WILL BE DECLARED AS SAME SIZE OF EMP TABLE JOB COLUMN. ONLY THEVALUES TRUE$FALSE$NULL CAN BE ASSIGNED TO THE BOOLEAN VARIABLE. DBMS(OUTPUT.PUT(LINE IS USED TO PRINT OUTPUT. IN S"L#PLUS WE HAVE TO TYPE SET SERVEROUTPUT ON. : T.E BELO+ PL0SQL BLOC- IS ANONY)OUS BLOC-

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 DECLARE 2 V(DEPTNO NUMBER(13)5 ) V(LOC , BEGIN . SELECT DEPTNO$LOC / INTO 0 V(DEPTNO$V(LOC 2 FROM DEPT WHERE DNAMEICSALESC5 13 END5 11 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L41 DECLARE 2 V(DEPTNO NUMBER(13)5 ) V(LOC , BEGIN . SELECT DEPTNO$LOC / INTO 0 V(DEPTNO$V(LOC 2 FROM DEPT WHERE DNAMEICSALESC5 13 DBMS(OUTPUT.PUT(LINE(V(DEPTNO VV C 11# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON C VV V(LOC)5 VARCHAR2(13)5 VARCHAR2(13)5

1/2

S"L4 / )3 CHICAGO

PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. T.E BELO+ PL0SQL BLOC- IS LABELLED BLOC-: WWLABELLED BLOC'44 S"L4 1 DECLARE 2 V(DEPTNO DEPT.DEPTNO-TYPE5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) V(LOC , BEGIN . SELECT DEPTNO$LOC / INTO 0 V(DEPTNO$V(LOC 2 FROM DEPT WHERE DNAMEICSALESC5 13 DBMS(OUTPUT.PUT(LINE(V(DEPTNO VV C 11# END5WWLABELLED BLOC'44 S"L4 / )3 CHICAGO PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. C VV V(LOC)5 DEPT.LOC-TYPE5

1/)

S"L4 1 DECLARE 2 V(DEPTNO EMP.DEPTNO-TYPE%I135 ) V(SUM(SAL , BEGIN . SELECT SUM(SAL) / INTO 0 V(SUM(SAL 2 FROM EMP WHERE DEPTNOIV(DEPTNO5 13 DBMS(OUTPUT.PUT(LINE(V(SUM(SAL)5 11# END5 S"L4 / 20.3 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. INSERTING DATA: BEGIN INSERT INTO DEPT VALUES(.3$COMPUTERS$MIAMI)5 END5 UPDATING DATA: BEGIN V(SAL(INCREASE BEGIN EMP.SAL-TYPE%I23335 EMP.SAL-TYPE5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
UPDATE EMP SET SAL I SALJV(SAL(INCREASE WHERE JOB I GANALYST END5

1/,

DELETING DATA: DECLARE V(DEPTNO BEGIN DELETE FROM EMP WHERE DEPTNOIV(DEPTNO5 END5 CONTROLLING PL0SQL FLO+ E/ECUTION: CONDITIONAL IF STATE)ENTS: IF BOOLEAN(E!PRESSION1 THEN SE"UENCE(STATEMENTS5 ELSIF BOOLEAN(E!PRESSION1 THEN SE"UENCE(STATEMENTS5 ELSE SE"UENCE(STATEMENTS5 END IF5 WHERE BOOLEAN(E!PRESSION IS ANY E!PRESSION THAT EVALUATES TO A BOOLEAN VALUE. THE ELSIF AND ELSE CLAUSES ARE OPTIONAL AND THERE CAN BE AS MANY ELSIF CLAUSES ARE DESIRED. E/A)PLE: 1 DECLARE 2 V(JOB EMP.JOB-TYPE5 ) BEGIN , SELECT JOB INTO V(JOB FROM EMP . WHERE EMPNO I + EMPLOYEE(NUMBER5 / IF V(JOB I CCLER'C THEN 0 DBMS(OUTPUT.PUT(LINE(V(JOB)5 2 DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES 13-C)5 ELSIF V(JOB I CMANAGERC THEN EMP.DEPTNO-TYPE %I135

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
13 DBMS(OUTPUT.PUT(LINE(V(JOB)5 11 DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES )3-C)5 12 ELSIF V(JOB I CSALESMANC THEN 1) DBMS(OUTPUT.PUT(LINE(V(JOB)5 1, DBMS(OUTPUT.PUT(LINE (CHIS SALARY INCREASES 23-C)5 1. ELSE 1/ DBMS(OUTPUT.PUT(LINE (V(JOB)5 10 DBMS(OUTPUT.PUT(LINE (CHIS SALARY INCREASES 3-C)5 12 END IF5 1 # END5 23 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0)/ CLER' HIS SALARY INCREASES 13PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0, SALESMAN HIS SALARY INCREASES 23PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0.// MANAGER HIS SALARY INCREASES )3PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0022 ANALYST HIS SALARY INCREASES 3PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

1/.

CASE STATE)ENT: 1 2 ) , DECLARE V(JOB EMP.JOB-TYPE5 BEGIN SELECT JOB INTO V(JOB FROM EMP

. WHERE EMPNO I + EMPLOYEE(NUMBER5 / CASE V(JOB 0 WHEN CCLER'C THEN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 DBMS(OUTPUT.PUT(LINE(V(JOB)5 DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES 13-C)5 13 WHEN CMANAGERC THEN 11 DBMS(OUTPUT.PUT(LINE(V(JOB)5 12 DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES )3-C)5 1) WHEN CSALESMANC THEN 1, DBMS(OUTPUT.PUT(LINE(V(JOB)5 1. DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES 23-C)5 1/ ELSE 10 DBMS(OUTPUT.PUT(LINE(V(JOB)5 12 DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES 3-C)5 1 END CASE5

1//

23# END5 S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0)/ CLER' HIS SALARY INCREASES 13PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0,// DECLARE # ERROR 6< 8NK9 1% ORA&31,3)% KD =6<6 TD?K= ORA&3/.12% 6< 8NK9 , S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0, SALESMAN HIS SALARY INCREASES 23PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0.// MANAGER HIS SALARY INCREASES )3PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0022 ANALYST HIS SALARY INCREASES 3PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. CASE STATE)ENT +IT. NO ELSE STATE)ENT: 1 DECLARE 2 V(JOB EMP.JOB-TYPE5 ) BEGIN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
, SELECT JOB INTO V(JOB FROM EMP . WHERE EMPNO I + EMPLOYEE(NUMBER5 / CASE V(JOB 0 WHEN CCLER'C THEN 2 DBMS(OUTPUT.PUT(LINE(V(JOB)5 DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES 13-C)5 13 WHEN CMANAGERC THEN 11 DBMS(OUTPUT.PUT(LINE(V(JOB)5 12 DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES )3-C)5 1) WHEN CSALESMANC THEN 1, DBMS(OUTPUT.PUT(LINE(V(JOB)5 1. DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES 23-C)5(HERE NO ELSE STATEMENT).

1/0

1/ END CASE5 10# END5 S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0022 DECLARE # ERROR 6< 8NK9 1% ORA&3/. 2% CASE KD< TD?K= ERN89 9U9:?<NKS CASE F<6<9>9K< ORA&3/.12% 6< 8NK9 / S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0)/ CLER' HIS SALARY INCREASES 13PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. CASE STATEMENT WITH LABEL% 1 DECLARE 2 V(JOB EMP.JOB-TYPE5 ) BEGIN , SELECT JOB INTO V(JOB FROM EMP . WHERE EMPNO I + EMPLOYEE(NUMBER5 / WWMYCASE44 0 CASE V(JOB 2 WHEN CCLER'C THEN DBMS(OUTPUT.PUT(LINE(V(JOB)5 13 DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES 13-C)5 11 WHEN CMANAGERC THEN 12 DBMS(OUTPUT.PUT(LINE(V(JOB)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1) DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES )3-C)5 1, WHEN CSALESMANC THEN 1. DBMS(OUTPUT.PUT(LINE(V(JOB)5 1/ DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES 23-C)5 10 END CASE MYCASE5 12# END5 S"L4 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0)/ CLER' HIS SALARY INCREASES 13PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. CASESTATE)ENT +IT. NO TEST E/PRESSION: 1 DECLARE 2 V(JOB EMP.JOB-TYPE5 ) BEGIN , SELECT JOB INTO V(JOB FROM EMP . WHERE EMPNO I + EMPLOYEE(NUMBER5 / CASE 0 WHEN V(JOBICCLER'C THEN 2 DBMS(OUTPUT.PUT(LINE(V(JOB)5 DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES 13-C)5 13 WHEN V(JOBICMANAGERC THEN 11 DBMS(OUTPUT.PUT(LINE(V(JOB)5 12 DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES )3-C)5 1) WHEN V(JOBICSALESMANC THEN 1, DBMS(OUTPUT.PUT(LINE(V(JOB)5 1. DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES 23-C)5 1/ ELSE 10 DBMS(OUTPUT.PUT(LINE(V(JOB)5 12 DBMS(OUTPUT.PUT(LINE(CHIS SALARY INCREASES 3-C)5 1 END CASE 5

1/2

23# END5 21 / EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0)/ CLER' HIS SALARY INCREASES 13PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EK<9; Q68?9 TD; 9>B8DA99(K?>79;% 0022 ANALYST HIS SALARY INCREASES 3PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. LOGIC TABLES: AND% AND TRUE FALSE NULL OR% OR TRUE FALSE NULL NOT% NOT TRUE FALSE NULL TRUE TRUE FALSE NULL FALSE FALSE FALSE FALSE NULL NULL FALSE NULL

1/

TRUE TRUE TRUE TRUE

FALSE TRUE FALSE NULL

NULL TRUE NULL NULL

FALSE TRUE NULL

ITERATIVECONTROL%

LOOP STATEMENTS LOOPS REPEAT A STATE)ENT OR SEQUENCE OF STATE)ENTS )ULTIPLE TI)ES( T.ERE ARE T.REE LOOPS TYPES: BASIC LOOP FOR LOOP WHILE LOOP

BASIC LOOP: 1 DECLARE 2 V(COUNTER NUMBER(13)%I35 ) BEGIN , LOOP . DBMS(OUTPUT.PUT(LINE(V(COUNTER)5 / V(COUNTER %I V(COUNTERJ15 0 IF V(COUNTER 4 13 THEN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 E!IT5 END IF5 13 END LOOP5 11# END5 S"L4 / 3 1 2 ) , . / 0 2 13 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 V(COUNTER NUMBER(13)%I35 ) BEGIN , LOOP . DBMS(OUTPUT.PUT(LINE(V(COUNTER)5 / V(COUNTER %I V(COUNTERJ15 0 E!IT WHEN V(COUNTER 4 135 2 END LOOP5 # END5 S"L4 / 3 1 2 ) , . / 0 2 13 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. FOR LOOP: 1 BEGIN 2 FOR I IN 1 .. 13 LOOP ) DBMS(OUTPUT.PUT(LINE(I)5 , END LOOP5

103

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
.# END5 S"L4 / 1 2 ) , . / 0 2 13 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 1 BEGIN 2 FOR I IN REVERSE 1 .. 13 LOOP ) DBMS(OUTPUT.PUT(LINE(I)5 , END LOOP5 .# END5 S"L4 / 13 2 0 / . , ) 2 1 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. +.ILE LOOP: 1 DECLARE 2 V(COUNTER NUMBER(13)%I35 ) V(NUM NUMBER(13)%I135 , BEGIN . WHILE V(COUNTER W V(NUM LOOP / DBMS(OUTPUT.PUT(LINE(V(COUNTER)5 0 V(COUNTER %I V(COUNTERJ15 2 END LOOP5 # END5 S"L4 / 3 1 2 )

101

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
, . / 0

102

CURSORS: IN ORDER TO PROCESS A S"L STATEMENT ORACLE WILL ALLOCATE AN AREA OF MEMORY 'NOWN AS THE CONTE!T AREA. A CURSOR IS A HANDLE OR POINTER TO THE CONTE!T AREA. T.ERE ARE T+O TYPES OF CURSORS( IMPLICIT CURSORS. E!PLICIT CURSORS.

THE ORACLE SERVER USES IMPLICIT CIRSORS TO PARSE AND E!ECUTE YOUR S"L STATEMENTS. E!PLICIT CURSORS ARE E!PLICITLY DECLARED BY THE PROGRAMMER. I)PLICIT CURSOR ATTRIBUTES: USING IMPLICIT CURSOR ATTRIBUTES$YOU CAN TEST THE OUTCOME OF YOUR S"L STATEMENTS. THE ORACLE ENGINE AUTOMATICALLY OPENS AND CLOSES THE S"L CURSOR AFTER E!ECUTING ITS S"L -ISOPEN ASSOCIATED SELECT$INSERT$UPDATE OR DELETE S"L STATEMENT HAS BEEN PROCESSED IN CASE OF IMPLICIT CURSORS. THUS THE S"L-IS OPEN ATTRIBUTE OF AN IMPLICIT CURSOR CANNOT BE REFERENCES OUTSIDE OF ITS S"L STATEMENT. AS A RESULT$S"L-ISOPEN ALWAYS EVALUATES TO FALSE. BOOLEAN ATTRIBUTE THAT EVALUATES TO TRUE$ IF AN INSERT$UPDATE OR DELETE AFFECTED ONE S"L-FOUND OR MORE ROWS OR SELECT STATEMENT RETURNS ONE OR MORE ROWS.OTHERWISE IT EVALUATES TO FALSE. THE SYNTA! FOR ACCESSING THIS ATTRIBUTE IS S"L-FOUND. BOOLEAN ATTRIBUTE THAT EVALUATES TO FALSE$ IF AN INSERT$UPDATE OR DELETE AFFECTED ONE S"L-NOTFOUND OR MORE ROWS OR SELECT STATEMENT RETURNS ONE OR MORE ROWS.OTHERWISE IT EVALUATES TO TRUE. THE SYNTA! FOR ACCESSING THIS ATTRIBUTE IS S"L-NOTFOUND. RETURNS THE NUMBER OF ROWS AFFECTED BY AN INSERT$UPDATE OR DELETE OR SELECT INTO S"L-ROWCOUNT STATEMENT.THE SYNTA! FOR ACCESSING THIS ATTRIBUTE IS S"L-ROWCOUNT. S"L4 VARIABLE ROW(DELETED VARCHAR2()3) S"L4 DECLARE 2 V(DEPTNO EMP.DEPTNO-TYPE %I135 ) BEGIN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
, DELETE FROM EMP . WHERE DEPTNOIV(DEPTNO5 / %ROW(DELETED %I(S"L-ROWCOUNT VV CROWS DELETEDC)5 0 END5 2 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 PRINT ROW(DELETED ROW(DELETED &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& )ROWS DELETED S"L4 BEGIN 2 DELETE FROM DEPT1 ) WHERE DEPTNOI135 , IF S"L-FOUND THEN . DBMS(OUTPUT.PUT(LINE(CDEPARTMENT SUCCESSFULLY DELTEDC)5 / END IF5 0 IF S"L-NOTFOUND THEN 2 DBMS(OUTPUT.PUT(LINE(CDEPARTMENT NO DOES NOT E!SITSC)5 END IF5 13 END5 11 / DEPARTMENT SUCCESSFULLY DELTED PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 BEGIN 2 DELETE FROM DEPT1 ) WHERE DEPTNOI135 , IF S"L-FOUND THEN . DBMS(OUTPUT.PUT(LINE(CDEPARTMENT SUCCESSFULLY DELETEDC)5 / END IF5 0 IF S"L-NOTFOUND THEN 2 DBMS(OUTPUT.PUT(LINE(CDEPARTMENT NO DOES NOT E!SITSC)5 END IF5 13# END5 11 / DEPARTMENT NO DOES NOT E!SITS PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

10)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SQL 5RO+COUNT: 1 DECLARE 2 ROWS(DELETED NUMBER(13)5 ) BEGIN , DELETE FROM EMP1 . WHERE DEPTNOI135 / ROWS(DELETED%IS"L-ROWCOUNT5 0 DBMS(OUTPUT.PUT(LINE(CNO OF ROWS DELETED% C VVROWS(DELETED)5 2# END5 S"L4 / NO OF ROWS DELETED% ) PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. PROCESSING T.E E/PLICIT CURSORS: THE FOUR PL/S"L STEPS NECESSARY FOR E!PLICIT CURSOR PROCESSING ARE AS FOLLOWS% DECLARE THE CURSOR. OPEN THE CURSOR FOR "UERY. FETCH THE RESULTS INTO PL/S"L VARIBALES. CLOSE THE CURSOR.

10,

E/PLICIT CURSOR ATTRIBUTES: -ROWCOUNT RETURNS THE NUMBER OF ROWS FETCHED FROM THE ACTIVE SET. IT IS SET TO ZERO WHEN THE CURSOR IS OPENED.THE SYNTA! FOR ACCESSING THIS ATTRIBUTEIS CURSORNAME-FOUND. BOOLEAN ATTRIBUTE THAT EVALUATES TO TRUE IF THE LAST FETCH SUCCEEDED BECAUSE A ROW WAS AVALIABLE5 OR TO FALSE IF THE LAST FETCH FAILED BECAUSE NO MORE ROWS WERE AVALIABLE. THE SYNTA! FOR ACCESSING THIS ATTRIBUTEIS CURSORNAME-FOUND. BOOLEAN ATTRIBUTE THAT EVALUATES TO FALSE IF THE LAST FETCH SUCCEEDED BECAUSE A ROW WAS AVALIABLE5 OR TO TRUE IF THE LAST FETCH FAILED BECAUSE NO MORE ROWS WERE AVALIABLE. THE SYNTA! FOR ACCESSING THIS ATTRIBUTE IS CURSORNAME-NOTFOUND. EVALUATES TO TRUE$IF AN E!PLICIT CURSOR IS OPEN. OR TO FALSE$ IF IT IS CLOSED.THE SYNTA! FOR ACCESSING THIS ATTRIBUTE IS CURSORNAME -ISOPEN.

-FOUND

-NOTFOUND

-IS OPEN

IN T.E BELO+ PL0SQL BLOC- ONLY ONE RO+ RETURNS FRO) SELECT STATE)ENT( 1 DECLARE 2 V(ENAME EMP.ENAME-TYPE5 ) V(JOB EMP.JOB-TYPE5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
, V(SAL EMP.SAL-TYPE5 . BEGIN / SELECT ENAME$JOB$SAL INTO V(ENAME$V(JOB$V(SAL FROM EMP 0 WHERE EMPNOI+EMPLOYEE(NO5 2 DBMS(OUTPUT.PUT(LINE(V(ENAMEVVC CVVV(JOBVVC CVVV(SAL)5 # END5 S"L4 / EK<9; Q68?9 TD; 9>B8DA99(KD% 0)/ SMITH CLER' 233 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. T.E BELO+ PL0SQL BLOC- RETURNS )ORE T.AN ONE RO+( 1 DECLARE 2 V(ENAME EMP.ENAME-TYPE5 ) V(JOB EMP.JOB-TYPE5 , V(SAL EMP.SAL-TYPE5 . BEGIN / SELECT ENAME$JOB$SAL INTO V(ENAME$V(JOB$V(SAL FROM EMP 0 WHERE DEPTNOI+DEPARTMENT(NO5 2 DBMS(OUTPUT.PUT(LINE(V(ENAMEVVC CVVV(JOBVVC CVVV(SAL)5 # END5 S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 DECLARE # ERROR 6< 8NK9 1% ORA&31,22% 9U6:< T9<:R ;9<?;KF >D;9 <R6K ;9P?9F<9= K?>79; DT ;DEF ORA&3/.12% 6< 8NK9 / SLO*ING T.E ABO*E PROBLE) +IT. CURSORS: 1 DECLARE 2 CURSOR C IS SELECT ENAME$JOB$SAL FROM EMP ) WHERE DEPTNOI+DEPARTMENT(NO5 , V(ENAME EMP.ENAME-TYPE5 . V(JOB EMP.JOB-TYPE5 / V(SAL EMP.SAL-TYPE5 0 BEGIN 2 OPEN C5 LOOP

10.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
13 FETCH C INTO V(ENAME$V(JOB$V(SAL5 11 E!IT WHEN C-NOTFOUND5 12 DBMS(OUTPUT.PUT(LINE(V(ENAMEVVC CVVV(JOBVVC CVVV(SAL)5 1) END LOOP5 1,# END5 S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 CLAR' MANAGER 2,.3 'ING PRESIDENT .333 MILLER CLER' 1)33 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

10/

1 SELECT EMPNO$ENAME$SAL FROM EMP1 2# WHERE DEPTNOI13 S"L4 / EMPNO ENAME &&&&&&&&& &&&&&&&&&& &&&&&&&&& 0022 CLAR' 2,.3 02) 'ING .333 0 ), MILLER 1)33 SAL

1 DECLARE 2 V(EMPNO ) V(ENAME , V(SAL EMP.EMPNO-TYPE5 EMP.ENAME-TYPE5 EMP.SAL-TYPE5

. V(DEPTNO EMP.DEPTNO-TYPE%I135 / V(NO(ROWS NUMBER(.)5 0 CURSOR EMP(CURSOR IS SELECT EMPNO$ENAME$SAL FROM EMP1 WHERE DEPTNOIV(DEPTNO5 2 BEGIN OPEN EMP(CURSOR5 13 LOOP 11 FETCH EMP(CURSOR INTO V(EMPNO$V(ENAME$V(SAL5 12 E!IT WHEN EMP(CURSOR-NOTFOUND5 1) DBMS(OUTPUT.PUT(LINE(V(EMPNO VV C 1, END LOOP5 1. V(NO(ROWS %I EMP(CURSOR-ROWCOUNT5 1/ DBMS(OUTPUT.PUT(LINE(CNO OF ROWS AFFECTEDC VV C 10 CLOSE EMP(CURSOR5 12# END5 C VV V(NO(ROWS)5 C VV V(ENAME VV C CVVV(SAL)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 / 0022 CLAR' 2,.3 02) 'ING .333 0 ), MILLER 1)33 NO OF ROWS AFFECTED ) PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. +OR-ING+IT. 5ISOPEN CURSOR ATTRIBUTE: 1 DECLARE 2 V(EMPNO ) V(ENAME , V(SAL EMP.EMPNO-TYPE5 EMP.ENAME-TYPE5 EMP.SAL-TYPE5

100

. V(DEPTNO EMP.DEPTNO-TYPE%I135 / V(NO(ROWS NUMBER(.)5 0 CURSOR EMP(CURSOR IS SELECT EMPNO$ENAME$SAL FROM EMP1 WHERE DEPTNOIV(DEPTNO5 2 BEGIN OPEN EMP(CURSOR5 13 IF EMP(CURSOR-ISOPEN THEN 11 LOOP 12 FETCH EMP(CURSOR INTO V(EMPNO$V(ENAME$V(SAL5 1) E!IT WHEN EMP(CURSOR-NOTFOUND5 1, DBMS(OUTPUT.PUT(LINE(V(EMPNO VV C 1. END LOOP5 1/ V(NO(ROWS %I EMP(CURSOR-ROWCOUNT5 10 DBMS(OUTPUT.PUT(LINE(CNO OF ROWS AFFECTEDC VV C 12 END IF5 1 CLOSE EMP(CURSOR5 C VV V(NO(ROWS)5 C VV V(ENAME VV C CVVV(SAL)5

23# END5 S"L4 / 0022 CLAR' 2,.3 02) 'ING .333 0 ), MILLER 1)33 NO OF ROWS AFFECTED

PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

+OR-ING +IT. 5FOUND CURSOR ATTRIBUTE: S"L4 2 DECLARE V(EMPNO EMP.EMPNO-TYPE5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) , . / V(ENAME V(SAL EMP.ENAME-TYPE5 EMP.SAL-TYPE5 V(DEPTNO EMP.DEPTNO-TYPE%I135 V(NO(ROWS NUMBER(.)5 0 CURSOR EMP(CURSOR IS SELECT EMPNO$ENAME$SAL FROM EMP1 WHERE DEPTNOIV(DEPTNO5 2 BEGIN OPEN EMP(CURSOR5 13 11 12 IF EMP(CURSOR-ISOPEN THEN LOOP FETCH EMP(CURSOR INTO V(EMPNO$V(ENAME$V(SAL5

102

1) IF EMP(CURSOR-FOUND THEN 1, DBMS(OUTPUT.PUT(LINE(V(EMPNO VV C C VV V(ENAME VV C CVVV(SAL)5

1. ELSE 1/ E!IT5 10 END IF5 12 END LOOP5 1 23 21 22 2) 2, / 0022 CLAR' 2,.3 02) 'ING .333 0 ), MILLER 1)33 NO OF ROWS AFFECTED V(NO(ROWS %I EMP(CURSOR-ROWCOUNT5 DBMS(OUTPUT.PUT(LINE(CNO OF ROWS AFFECTEDC VV C END IF5 CLOSE EMP(CURSOR5 END5 C VV V(NO(ROWS)5

PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

+OR-ING+IT.5NOTFOUNDCURSOR ATTRIBUTE: S"L4 2 ) , . / DECLARE V(EMPNO V(ENAME V(SAL EMP.EMPNO-TYPE5 EMP.ENAME-TYPE5 EMP.SAL-TYPE5

V(DEPTNO EMP.DEPTNO-TYPE%I135 V(NO(ROWS NUMBER(.)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0 2 CURSOR EMP(CURSOR IS SELECT EMPNO$ENAME$SAL FROM EMP1 WHERE DEPTNOIV(DEPTNO5 BEGIN OPEN EMP(CURSOR5 13 11 12 IF EMP(CURSOR-ISOPEN THEN LOOP FETCH EMP(CURSOR INTO V(EMPNO$V(ENAME$V(SAL5

10

1) IF EMP(CURSOR-NOTFOUND THEN 1, E!IT5 1. ELSE 1/ DBMS(OUTPUT.PUT(LINE(V(EMPNO VV C 10 END IF5 12 END LOOP5 1 23 21 22 2) 2, / 0022 02) 0 ), CLAR' 2,.3 'ING .333 MILLER 1)33 ) V(NO(ROWS %I EMP(CURSOR-ROWCOUNT5 DBMS(OUTPUT.PUT(LINE(CNO OF ROWS AFFECTEDC VV C END IF5 CLOSE EMP(CURSOR5 END5 C VV V(NO(ROWS)5 C VV V(ENAME VV C CVVV(SAL)5

NO OF ROWS AFFECTED

PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. +OR-ING +IT. +.ILE LOOP IN CURSORS:

1 2 ) , . / 0 2

DECLARE V(EMPNO V(ENAME V(SAL EMP.EMPNO-TYPE5 EMP.ENAME-TYPE5 EMP.SAL-TYPE5

V(DEPTNO EMP.DEPTNO-TYPE%I135 V(NO(ROWS NUMBER(.)5 CURSOR EMP(CURSOR IS SELECT EMPNO$ENAME$SAL FROM EMP1 WHERE DEPTNOIV(DEPTNO5 BEGIN OPEN EMP(CURSOR5

13

IF EMP(CURSOR-ISOPEN THEN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
11 FETCH EMP(CURSOR INTO V(EMPNO$V(ENAME$V(SAL5 12 WHILE EMP(CURSOR-FOUND LOOP 1) DBMS(OUTPUT.PUT(LINE(V(EMPNO VV C C VV V(ENAME VV C CVVV(SAL)5 1, FETCH EMP(CURSOR INTO V(EMPNO$V(ENAME$V(SAL5 1. END LOOP5 1/ 10 12 1 23# 21 / 0022 02) 0 ), CLAR' 2,.3 'ING .333 MILLER 1)33 ) V(NO(ROWS %I EMP(CURSOR-ROWCOUNT5 DBMS(OUTPUT.PUT(LINE(CNO OF ROWS AFFECTEDC VV C END IF5 CLOSE EMP(CURSOR5 END5 C VV V(NO(ROWS)5

123

NO OF ROWS AFFECTED

PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. +OR-ING +IT. FOR LOOP IN CURSORS: 1 2 ) , . / 0 2 DECLARE V(EMPNO V(ENAME V(SAL EMP.EMPNO-TYPE5 EMP.ENAME-TYPE5 EMP.SAL-TYPE5

V(DEPTNO EMP.DEPTNO-TYPE%I135 V(NO(ROWS NUMBER(.)5 CURSOR EMP(CURSOR IS SELECT EMPNO$ENAME$SAL FROM EMP1 WHERE DEPTNOIV(DEPTNO5 BEGIN FOR V(S IN EMP(CURSOR LOOP

13 DBMS(OUTPUT.PUT(LINE(V(S.EMPNO VV C 11 V(NO(ROWS %IEMP(CURSOR-ROWCOUNT5 12 END LOOP5

C VV V(S.ENAME VV C

CVVV(S.SAL)5

1) DBMS(OUTPUT.PUT(LINE(CNO OF ROWS AFFECTEDC VV C 1,# END5 1. / 0022 02) 0 ), CLAR' 2,.3 'ING .333 MILLER 1)33 )

C VV V(NO(ROWS)5

NO OF ROWS AFFECTED

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 2 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

121

E/CEPTION .ANDLING: 1 2 ) , . / 0 2 DECLARE V(EMPNO NUMBER(13)5 V(ENAME VARCHAR2(13)5 V(SAL NUMBER(13)5

V(DEPTNO NUMBER(13)5 BEGIN V(DEPTNO %I +DEPARTMENT(NO5 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5

DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 13# END5 S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13/ DECLARE # ERROR 6< 8NK9 1% ORA&31,22% 9U6:< T9<:R ;9<?;KF >D;9 <R6K ;9P?9F<9= K?>79; DT ;DEF ORA&3/.12% 6< 8NK9 2

.ANDLING E/CEPTION +IT. E/CEPTION .ANDLER:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 DECLARE 2 V(EMPNO NUMBER(13)5 ) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5 . V(DEPTNO NUMBER(13)5 / BEGIN 0 V(DEPTNO %I +DEPARTMENT(NO5 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5 13 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 11 E!CEPTION 11 WHEN NO(DATA(FOUND THEN 12 DBMS(OUTPUT.PUT(LINE(CDEPRTMENT NO%CVVV(DEPTNOVV CIS NOT PRESENT IN THE EMPTABLEC)5 1) WHEN TOO(MANY(ROWS THEN 1, DBMS(OUTPUT.PUT(LINE(CDEPRTMENT NO%CVVV(DEPTNOVV CIS RETRIVING MORE THAN ONE ROWC)5 1.# END5 / 1/ / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 DEPRTMENT NO%13IS RETRIVING MORE THAN ONE ROW PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 V(EMPNO NUMBER(13)5 ) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5

122

. V(DEPTNO NUMBER(13)5 / BEGIN 0 V(DEPTNO %I +DEPARTMENT(NO5 2 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 13 E!CEPTION 11 WHEN TOO(MANY(ROWS THEN 12 1) DBMS(OUTPUT.PUT(LINE(CDEPRTMENT NO%CVVV(DEPTNOVV CIS RETRIVING MORE THAN ONE ROWC)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1)# END5 S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 1 DECLARE # ERROR 6< 8NK9 1% ORA&31,3)% KD =6<6 TD?K= ORA&3/.12% 6< 8NK9 2 1 DECLARE 2 V(EMPNO NUMBER(13)5 ) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5

12)

. V(DEPTNO NUMBER(13)5 / BEGIN 0 V(DEPTNO %I +DEPARTMENT(NO5 2 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 13 E!CEPTION 11 WHEN NO(DATA(FOUND THEN 12 1) DBMS(OUTPUT.PUT(LINE(CDEPRTMENT NO%CVVV(DEPTNOVV CIS NOT PRESENT IN THE EMPTABLEC)5

1) WHEN TOO(MANY(ROWS THEN 1, DBMS(OUTPUT.PUT(LINE(CDEPRTMENT NO%CVVV(DEPTNOVV 1. CIS RETRIVING MORE THAN ONE ROWC)5 1.# END5 S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 1 DEPRTMENT NO%1 IS NOT PRESENT IN THE EMPTABLE PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 CREATE TABLE DEPARTMENT 2 AS ) SELECT # FROM DEPT5 T6789 :;96<9=. S"L4 SELECT # FROM DEPARTMENT5 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 ACCOUNTING NEW YOR' 23 RESEARCH DALLAS )3 SALES CHICAGO ,3 OPERATIONS BOSTON S"L4 ALTER TABLE DEPARTMENT 2 ADD CONSTRAINT DEPT(P' PRIMARY 'EY(DEPTNO)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
T6789 68<9;9=. 1 2 ) , . / 0 2 DECLARE V(DEPTNO NUMBER(13)5 V(DNAME VARCHAR2(13)5 V(LOC VARCHAR2(13)5 BEGIN V(DEPTNO %I +DEPARTMENT(NO5 V(DNAME V(LOC %IC+DEPARTMENT(NAMEC5 %IC+LOCC5

12,

INSERT INTO DEPARTMENT VALUES (V(DEPTNO$V(DNAME$V(LOC)5 13# END5 S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 EK<9; Q68?9 TD; =9B6;<>9K<(K6>9% COMPUTERS EK<9; Q68?9 TD; 8D:% MIAMI DECLARE # ERROR 6< 8NK9 1% ORA&33331% ?KNP?9 :DKF<;6NK< (SCOTT.DEPT(P') QND86<9= ORA&3/.12% 6< 8NK9 1 2 ) , . / 0 2 DECLARE V(DEPTNO NUMBER(13)5 V(DNAME VARCHAR2(13)5 V(LOC VARCHAR2(13)5 BEGIN V(DEPTNO %I +DEPARTMENT(NO5 V(DNAME V(LOC %IC+DEPARTMENT(NAMEC5 %IC+LOCC5

INSERT INTO DEPARTMENT VALUES (V(DEPTNO$V(DNAME$V(LOC)5 13 E!CEPTION 11 WHEN DUP(VAL(ON(INDE! THEN DBMS(OUTPUT.PUT(LINE(CDEPARTMENT NO%CVVC CVVV(DEPTNOVV CIS ALREADY ENTERED IN THE DEPARTMENT TABLEC)5 1)# END5 S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 EK<9; Q68?9 TD; =9B6;<>9K<(K6>9% COMPUTERS EK<9; Q68?9 TD; 8D:% MIAMI DEPARTMENT NO% 13 IS ALREADY ENTERED IN THE DEPARTMENT TABLE 12

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 2 ) , . / 0 2 DECLARE V(DEPTNO NUMBER(13)5 V(DNAME VARCHAR2(13)5 V(LOC VARCHAR2(13)5 BEGIN V(DEPTNO %I +DEPARTMENT(NO5 V(DNAME %IC+DEPARTMENT(NAMEC5 V(LOC %IC+LOCC5

12.

INSERT INTO DEPARTMENT VALUES (V(DEPTNO$V(DNAME$V(LOC)5 13 E!CEPTION 11 WHEN DUP(VAL(ON(INDE! THEN 12 DBMS(OUTPUT.PUT(LINE(CDEPARTMENT NO%CVVC CVVV(DEPTNOVV CIS ALREADY ENTERED IN THE DEPARTMENT TABLEC)5 1)# END5 1, / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 EK<9; Q68?9 TD; =9B6;<>9K<(K6>9% COMPUTERS + TECHNOLOGY EK<9; Q68?9 TD; 8D:% MIAMI DECLARE # ERROR 6< 8NK9 1% ORA&3/.32% PL/S"L% K?>9;N: D; Q68?9 9;;D;% :R6;6:<9; F<;NKS 7?TT9; <DD F>688 ORA&3/.12% 6< 8NK9 0

1 2 ) , . / 0 2

DECLARE V(DEPTNO NUMBER(13)5 V(DNAME VARCHAR2(13)5 V(LOC VARCHAR2(13)5 BEGIN V(DEPTNO %I +DEPARTMENT(NO5 V(DNAME V(LOC %IC+DEPARTMENT(NAMEC5 %IC+LOCC5

INSERT INTO DEPARTMENT VALUES (V(DEPTNO$V(DNAME$V(LOC)5 13 E!CEPTION 11 WHEN DUP(VAL(ON(INDE! THEN 12 DBMS(OUTPUT.PUT(LINE(CDEPARTMENT NO%CVVC CVVV(DEPTNOVV CIS ALREADY ENTERED IN THE DEPARTMENT TABLEC)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1) WHEN VALUE(ERROR THEN 1, DBMS(OUTPUT.PUT(LINE(CDATA TYPE OR DATA SIZE INVALIDC)5 1.# END5 1/ / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 EK<9; Q68?9 TD; =9B6;<>9K<(K6>9% COMPUTERS + TECHNOLOGY EK<9; Q68?9 TD; 8D:% MIAMI DATA TYPE OR DATA SIZE INVALID PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. RAISE STATE)ENT: S"L4 CREATE TABLE BAN'(TRANS 2 (ACC(NO NUMBER(13)$ ) CURRBAL NUMBER(13)) , / T6789 :;96<9=. S"L4 INSERT INTO BAN'(TRANS 2 VALUES ) (1$1333) , / 1 ;DE :;96<9=. S"L4 ED W;D<9 TN89 6TN9=<.7?T 1 INSERT INTO BAN'(TRANS 2 VALUES )# (2$2333) S"L4 / 1 ;DE :;96<9=. S"L4 ED W;D<9 TN89 6TN9=<.7?T 1 INSERT INTO BAN'(TRANS 2 VALUES )# ()$)333) S"L4 / 1 ;DE :;96<9=. S"L4 ED W;D<9 TN89 6TN9=<.7?T 1 DECLARE

12/

2 V(ACCNO NUMBER(13)5 ) , V(CURRBAL NUMBER(13)5 V(WITHDRAWAMT NUMBER(13)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
. / 0 2 MORE(THAN(BAL E!CEPTION5 BEGIN V(ACCNO %I +ACCOUNT(NO5 SELECT ACC(NO$CURRBAL INTO V(ACCNO$V(CURRBAL FROM BAN'(TRANS5 WHERE ACC(NOIV(ACCNO5 13 11 12 1) 1, 1. V(WITHDRAWAMT %I +WITHDRAWAMT5 IF V(WITHDRAWAMT 4 V(CURRBAL THEN RAISE MORE(THAN(BAL5 ELSE DBMS(OUTPUT.PUT(LINE(CYOU SUCCESSFULLY WITHDRAWN AMOUNTC)5 END IF5

120

1/ 10 12 1 23 21

E!CEPTION WHEN MORE(THAN(BAL THEN DBMS(OUTPUT.PUT(LINE(CATTEMPTED TO WITH DRAW MORE THAN THE CURRENT BALANCEC VV C CVV V(CURRBAL VVC C VV C FROM THE ACCOUNT NUMBERC VV C C VV V(ACCNO)5

23# END5 21 / EK<9; Q68?9 TD; 6::D?K<(KD% 1 EK<9; Q68?9 TD; EN<R=;6E6><% .33 YOU SUCCESSFULLY WITHDRAWN AMOUNT PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; 6::D?K<(KD% 2 EK<9; Q68?9 TD; EN<R=;6E6><% )333 ATTEMPTED TO WITH DRAW MORE THAN THE CURRENT BALANCE 2333 FROM THE ACCOUNT NUMBER 2 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

PRAG)A E/CEPTION2INIT: 1 DECLARE

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 V(EMPNO NUMBER(13)5 ) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5 . V(DEPTNO NUMBER(13)5 / BEGIN 0 V(DEPTNO %I +DEPARTMENT(NO5 2 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 13# END5 11 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 DECLARE # ERROR 6< 8NK9 1% ORA&31,22% 9U6:< T9<:R ;9<?;KF >D;9 <R6K ;9P?9F<9= K?>79; DT ;DEF ORA&3/.12% 6< 8NK9 2 1 DECLARE 2 V(EMPNO NUMBER(13)5 ) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5

122

. V(DEPTNO NUMBER(13)5 / E(TOOOOMANYROWS E!CEPTION5 0 PRAGMA E!CEPTION(INIT(E(TOOOOMANYROWS$&1,22)5 2 BEGIN V(DEPTNO %I +DEPARTMENT(NO5 13 11 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5

11 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 12 E!CEPTION 1) WHEN E(TOOOOMANYROWS THEN 1) 1, DBMS(OUTPUT.PUT(LINE(CTHE DEPTNO CVVV(DEPTNO VVC C VV CFETCHING MORE THAN ONE ROWC)5

1.# END5 S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 THE DEPTNO 13 FETCHING MORE THAN ONE ROW

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 V(EMPNO NUMBER(13)5 ) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5

12

. V(DEPTNO NUMBER(13)5 / E(TOOOOMANYROWS E!CEPTION5 0 PRAGMA E!CEPTION(INIT(E(TOOOOMANYROWS$&1,21)5 2 BEGIN V(DEPTNO %I +DEPARTMENT(NO5 13 11 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5

11 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 12 E!CEPTION 1) WHEN E(TOOOOMANYROWS THEN 1. 1/ DBMS(OUTPUT.PUT(LINE(CTHE DEPTNO CVVV(DEPTNO VVC C VV CFETCHING MORE THAN ONE ROWC)5

1.# END5 S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 DECLARE # ERROR 6< 8NK9 1% ORA&31,22% 9U6:< T9<:R ;9<?;KF >D;9 <R6K ;9P?9F<9= K?>79; DT ;DEF ORA&3/.12% 6< 8NK9 13

1 DECLARE 2 V(EMPNO NUMBER(13)5 ) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
. V(DEPTNO NUMBER(13)5 / BEGIN 0 V(DEPTNO %I +DEPARTMENT(NO5 2 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 13 E!CEPTION 11 WHEN TOO(MANY(ROWS THEN 12 1) DBMS(OUTPUT.PUT(LINE(CTHE DEPTNO CVVV(DEPTNO VVC C VV CFETCHING MORE THAN ONE ROWC)5

1 3

1)# END5 1, / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 THE DEPTNO 13 FETCHING MORE THAN ONE ROW PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. +.EN OT.ERS: 1 DECLARE 2 V(EMPNO NUMBER(13)5 ) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5

. V(DEPTNO NUMBER(13)5 / BEGIN 0 V(DEPTNO %I +DEPARTMENT(NO5 2 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 13 E!CEPTION 11 WHEN TOO(MANY(ROWS THEN 12 1) DBMS(OUTPUT.PUT(LINE(CTHE DEPTNO CVVV(DEPTNO VVC C VV CFETCHING MORE THAN ONE ROWC)5

1) WHEN OTHERS THEN 1, 1. DBMS(OUTPUT.PUT(LINE(CTHE DEPTNO CVVV(DEPTNO VVC C VV CIS NOT PRESENT IN THE TABLEC)5

1.# END5 S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 THE DEPTNO 13 FETCHING MORE THAN ONE ROW

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 1 THE DEPTNO 1 IS NOT PRESENT IN THE TABLE PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

1 1

SQL CODE : SQLERR): S"L4 DECLARE 2 V(EMPNO NUMBER(13)5 ) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5

. V(DEPTNO NUMBER(13)5 / V(ERRORCODE NUMBER(13)5 0 V(ERRORTE!T VARCHAR2(2..)5 13 BEGIN V(DEPTNO %I +DEPARTMENT(NO5 11 12 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5

11 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 12 E!CEPTION 1) WHEN TOO(MANY(ROWS THEN 1) 1, DBMS(OUTPUT.PUT(LINE(CTHE DEPTNO CVVV(DEPTNO VVC C VV CFETCHING MORE THAN ONE ROWC)5

1. WHEN OTHERS THEN 1/ V(ERRORCODE%IS"LCODE5 10 V(ERRORTE!T%IS"LERRM5 12 DBMS(OUTPUT.PUT(LINE(V(ERRORCODE VV V(ERRORTE!T)5 1 END5

23 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 THE DEPTNO 13 FETCHING MORE THAN ONE ROW PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 V(EMPNO NUMBER(13)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5 . V(DEPTNO NUMBER(13)5 / V(ERRORCODE NUMBER(13)5 0 V(ERRORTE!T VARCHAR2(2..)5 2 BEGIN V(DEPTNO %I +DEPARTMENT(NO5 13 11 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5

1 2

11 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 12 E!CEPTION 1) WHEN TOO(MANY(ROWS THEN 1. 1/ DBMS(OUTPUT.PUT(LINE(CTHE DEPTNO CVVV(DEPTNO VVC C VV CFETCHING MORE THAN ONE ROWC)5

1. WHEN OTHERS THEN 1/ V(ERRORCODE%IS"LCODE5 10 V(ERRORTE!T%IS"LERRM5 12 DBMS(OUTPUT.PUT(LINE(V(ERRORCODE VV V(ERRORTE!T)5 1 # END5 S"L4 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 1 133ORA&31,3)% KD =6<6 TD?K= PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 V(EMPNO NUMBER(13)5 ) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5

. V(DEPTNO NUMBER(13)5 / V(ERRORCODE NUMBER(13)5 0 V(ERRORTE!T VARCHAR2(2..)5 2 BEGIN V(DEPTNO %I +DEPARTMENT(NO5 13 11 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5

11 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
12 E!CEPTION 1) WHEN TOO(MANY(ROWS THEN 1, 1. DBMS(OUTPUT.PUT(LINE(CTHE DEPTNO CVVV(DEPTNO VVC C VV CFETCHING MORE THAN ONE ROWC)5 1. WHEN OTHERS THEN 1/ V(ERRORCODE%IS"LCODE5 10 V(ERRORTE!T%IS"LERRM5 12 DBMS(OUTPUT.PUT(LINE(V(ERRORCODE)5 1 DBMS(OUTPUT.PUT(LINE(V(ERRORTE!T)5

1 )

23# END5 21 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 1 133 ORA&31,3)% KD =6<6 TD?K= PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 V(EMPNO NUMBER(13)5 ) V(ENAME VARCHAR2(13)5 , V(SAL NUMBER(13)5

. V(DEPTNO NUMBER(13)5 / V(ERRORCODE NUMBER(13)5 0 V(ERRORTE!T VARCHAR2(2..)5 2 BEGIN V(DEPTNO %I +DEPARTMENT(NO5 13 11 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE DEPTNOIV(DEPTNO5

11 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 12 E!CEPTION 1) WHEN OTHERS THEN 1, V(ERRORCODE%IS"LCODE5 1. V(ERRORTE!T%IS"LERRM5 1/ DBMS(OUTPUT.PUT(LINE(V(ERRORCODE)5 10 DBMS(OUTPUT.PUT(LINE(V(ERRORTE!T)5 12# END5 1 / EK<9; Q68?9 TD; =9B6;<>9K<(KD% 13 &1,22

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ORA&31,22% 9U6:< T9<:R ;9<?;KF >D;9 <R6K ;9P?9F<9= K?>79; DT ;DEF PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 DECLARE 2 V(EMPNO NUMBER(13)5 ) V(ENAME NUMBER(13)5 , V(SAL NUMBER(13)5

1 ,

. V(DEPTNO NUMBER(13)5 / V(ERRORCODE NUMBER(13)5 0 V(ERRORTE!T VARCHAR2(2..)5 2 BEGIN V(EMPNO %I +EMPLOYEE(NO5 13 11 SELECT EMPNO$ENAME$SAL INTO V(EMPNO$V(ENAME$V(SAL FROM EMP WHERE EMPNOIV(EMPNO5

11 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAMEVVV(SAL)5 12 E!CEPTION 1) WHEN OTHERS THEN 1, V(ERRORCODE%IS"LCODE5 1. V(ERRORTE!T%IS"LERRM5 1/ DBMS(OUTPUT.PUT(LINE(V(ERRORCODE)5 10 DBMS(OUTPUT.PUT(LINE(V(ERRORTE!T)5 12 END5 1 / EK<9; Q68?9 TD; 9>B8DA99(KD% 0)/ &/.32 ORA&3/.32% PL/S"L% K?>9;N: D; Q68?9 9;;D;% :R6;6:<9; <D K?>79; :DKQ9;FNDK 9;;D; PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 2 ) , DECLARE

V(ACCNO NUMBER(13)5 V(CURRBAL NUMBER(13)5 V(WITHDRAWAMT NUMBER(13)5

. V(ERRORCODE NUMBER(13)5 / V(ERRORTE!T VARCHAR2(2..)5 0 MORE(THAN(BAL E!CEPTION5 2 BEGIN V(ACCNO %I +ACCOUNT(NO5 13 SELECT ACC(NO$CURRBAL INTO V(ACCNO$V(CURRBAL

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
11 11 12 1) 1, 1. 1/ 10 12 1 FROM BAN'(TRANS5 WHERE ACC(NOIV(ACCNO5 V(WITHDRAWAMT %I +WITHDRAWAMT5 IF V(WITHDRAWAMT 4 V(CURRBAL THEN RAISE MORE(THAN(BAL5 ELSE DBMS(OUTPUT.PUT(LINE(CYOU SUCCESSFULLY WITHDRAWN AMOUNTC)5 END IF5 E!CEPTION WHEN OTHERS THEN

1 .

23 V(ERRORCODE%IS"LCODE5 21 V(ERRORTE!T%IS"LERRM5 22 DBMS(OUTPUT.PUT(LINE(V(ERRORCODE)5 2) DBMS(OUTPUT.PUT(LINE(V(ERRORTE!T)5 2, END5 2. / EK<9; Q68?9 TD; 6::D?K<(KD% 1 EK<9; Q68?9 TD; EN<R=;6E6><% 2333 1 UF9;&D9TNK9= EU:9B<NDK PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. RAISE2APPLICATION2ERROR: USE CAN USE THE BUILT& IN FUNCTION RAISE(APPLICATION(ERROR TO CREATE YOUR OWN ERROR MESSAGES$ WHICH CAN BE MORE DESCRIPTIVE THAN NAMED E!CEPTIONS. RAISE2APPLICATION2ERROR(ERROR2NU)BER" ERROR2)ESSAGE)( WHERE ERROR(NUMBER IS A VALUE BETWEEN 123$333 AND 123$ ERROR MESSAGE IS THE TE!T ASSOCIATED WITH THIS ERROR. 1 DECLARE 2 V(SAL NUMBER(13)5 ) V(EMPNO NUMBER(13)5 , BEGIN . V(EMPNO%I+EMPLOYEE(NO5 / SELECT SAL INTO V(SAL FROM EMP 0 WHERE EMPNOIV(EMPNO5 2 IF LENGTH(V(EMPNO) 4 , THEN RAISE(APPLICATION(ERROR(&23333$CYOU CANNOT ENTER EMPNO WITH MORE THAN , NUMBERSC)5 .

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
13 END IF5 11 DBMS(OUTPUT.PUT(LINE(V(SAL)5 12 E!CEPTION 1) WHEN NO(DATA(FOUND THEN 1, RAISE(APPLICATION(ERROR(&23331$CTHERE IS NO DATA FOR THE EMPNO YOU ENTEREDC)5 1.# END5 S"L4 / EK<9; Q68?9 TD; 9>B8DA99(KD% 0)/ PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON S"L4 / EK<9; Q68?9 TD; 9>B8DA99(KD% 0)/ 233 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; 9>B8DA99(KD% DECLARE # ERROR 6< 8NK9 1% ORA&23331% THERE IS NO DATA FOR THE EMPNO YOU ENTERED ORA&3/.12% 6< 8NK9 1, 1 DECLARE 2 V(SAL NUMBER(13)5 ) V(EMPNO NUMBER(13)5 , BEGIN . V(EMPNO%I+EMPLOYEE(NO5 / IF LENGTH(V(EMPNO) 4 , THEN 0 RAISE(APPLICATION(ERROR(&23333$CYOU CANNOT ENTER EMPNO WITH MORE THAN , NUMBERSC)5 2 END IF5 SELECT SAL INTO V(SAL FROM EMP 13 WHERE EMPNOIV(EMPNO5 11 DBMS(OUTPUT.PUT(LINE(V(SAL)5 12 E!CEPTION 1) WHEN NO(DATA(FOUND THEN 1, RAISE(APPLICATION(ERROR(&23331$CTHERE IS NO DATA FOR THE EMPNO YOU ENTEREDC)5

1 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1.# END5 S"L4 / EK<9; Q68?9 TD; 9>B8DA99(KD% 0)/ 233 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; 9>B8DA99(KD% DECLARE # ERROR 6< 8NK9 1% ORA&23331% THERE IS NO DATA FOR THE EMPNO YOU ENTERED ORA&3/.12% 6< 8NK9 1, S"L4 / EK<9; Q68?9 TD; 9>B8DA99(KD% DECLARE # ERROR 6< 8NK9 1% ORA&23333% YOU CANNOT ENTER EMPNO WITH MORE THAN , NUMBERS ORA&3/.12% 6< 8NK9 0 PARA)ETERISED CURSORS: 1 DECLARE 2 CURSOR C (V(DEPTNO NUMBER) IS SELECT EMPNO$ENAME FROM EMP WHERE DEPTNOIV(DEPTNO5 ) V(EMPNO EMP.EMPNO-TYPE5 , V(ENAME EMP.ENAME-TYPE5 . BEGIN / OPEN C(13)5 0 LOOP 2 FETCH C INTO V(EMPNO$V(ENAME5 E!IT WHEN C-NOTFOUND5 13 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAME)5 11 END LOOP5 12# END5 S"L4 / 0022CLAR' 02) 'ING 0 ),MILLER PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 CURSOR C (V(DEPTNO NUMBER) IS SELECT EMPNO$ENAME FROM EMP WHERE DEPTNOIV(DEPTNO5 ) V(EMPNO EMP.EMPNO-TYPE5 , V(ENAME EMP.ENAME-TYPE5 . BEGIN / OPEN C(+DEPTNO)5 0 LOOP 2 FETCH C INTO V(EMPNO$V(ENAME5 E!IT WHEN C-NOTFOUND5 13 DBMS(OUTPUT.PUT(LINE(V(EMPNOVVV(ENAME)5 11 END LOOP5 12# END5

1 0

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 / EK<9; Q68?9 TD; =9B<KD% 13 0022CLAR' 02) 'ING 0 ),MILLER PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; =9B<KD% 23 0)/ SMITH 0.//JONES 0022SCOTT 020/ADAMS 0 32FORD PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; =9B<KD% )3 0, ALLEN 0.21WARD 0/.,MARTIN 0/ 2BLA'E 02,,TURNER 0 33JAMES PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 CURSOR C (V(DEPTNO NUMBER) IS SELECT EMPNO$ENAME FROM EMP WHERE DEPTNOIV(DEPTNO5 ) V(EMPNO EMP.EMPNO-TYPE5 , V(ENAME EMP.ENAME-TYPE5 . BEGIN / FOR V(FOR IN C(+DEPTNO) LOOP 0 DBMS(OUTPUT.PUT(LINE(V(FOR.EMPNOVVV(FOR.ENAME)5 2 END LOOP5 # END5 13 / EK<9; Q68?9 TD; =9B<KD% 13 0022CLAR' 02) 'ING 0 ),MILLER PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. PARAMETERISED CURSORS WITH FOR LOOP% 1 DECLARE 2 CURSOR C (V(DEPTNO NUMBER) IS SELECT EMPNO$ENAME FROM EMP WHERE DEPTNOIV(DEPTNO5 ) BEGIN , FOR V(FOR IN C(+DEPTNO) LOOP . DBMS(OUTPUT.PUT(LINE(V(FOR.EMPNOVVV(FOR.ENAME)5 / END LOOP5 0# END5 S"L4 / EK<9; Q68?9 TD; =9B<KD% 13 0022CLAR' 02) 'ING 0 ),MILLER PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; =9B<KD% 23 0)/ SMITH 0.//JONES

1 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0022SCOTT 020/ADAMS 0 32FORD PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; =9B<KD% )3 0, ALLEN 0.21WARD 0/.,MARTIN 0/ 2BLA'E 02,,TURNER 0 33JAMES PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

PL0SQL RECORDS: 1 DECLARE 2 V(DEPTNO DEPT.DEPTNO-TYPE5 ) V(DNAME DEPT.DNAME-TYPE5 , V(LOC . BEGIN / SELECT DEPTNO$DNAME$LOC INTO V(DEPTNO$V(DNAME$V(LOC 0 FROM DEPT WHERE DEPTNOI+DEPTNO5 2 DBMS(OUTPUT.PUT(LINE(V(DEPTNOVVV(DNAMEVVV(LOC)5 # END5 13 / EK<9; Q68?9 TD; =9B<KD% 13 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON EK<9; Q68?9 TD; =9B<KD% 13 13ACCOUNTINGNEW YOR' PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; =9B<KD% 23 23RESEARCHDALLAS PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DEPT.LOC-TYPE5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 / EK<9; Q68?9 TD; =9B<KD% )3 )3SALESCHICAGO PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; =9B<KD% ,3 ,3OPERATIONSBOSTON PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

233

DECLARING A RECORD TYPE: 1 DECLARE 2 ) , . / TYPE DEPT(RECORD IS RECORD ( V(DEPTNO DEPT.DEPTNO-TYPE$ V(DNAME DEPT.DNAME-TYPE$ V(LOC DEPT.LOC-TYPE)5

0 DEPT(REC DEPT(RECORD5 2 BEGIN SELECT DEPTNO$DNAME$LOC INTO DEPT(REC 13 FROM DEPT WHERE DEPTNOI+DEPTNO5 11 DBMS(OUTPUT.PUT(LINE(DEPT(REC.V(DEPTNOVVDEPT(REC.V(DNAMEVVDEPT(REC.V(LOC)5 12# END5 1) / EK<9; Q68?9 TD; =9B<KD% 13 13ACCOUNTINGNEW YOR' PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; =9B<KD% 23 23RESEARCHDALLAS PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; =9B<KD% )3 )3SALESCHICAGO PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; =9B<KD% ,3 ,3OPERATIONSBOSTON PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DECLARE TYPE DEPT(RECORD IS RECORD ( V(DEPTNO DEPT.DEPTNO-TYPE$ V(DNAME DEPT.DNAME-TYPE$ V(LOC DEPT.LOC-TYPE)5 DEPT(REC DEPT(RECORD5 BEGIN SELECT DEPTNO$DNAME$LOC INTO DEPT(REC FROM DEPT5 13 DBMS(OUTPUT.PUT(LINE(DEPT(REC.V(DEPTNOVVDEPT(REC.V(DNAMEVVDEPT(REC.V(LOC)5 11# END5 S"L4 / DECLARE # ERROR 6< 8NK9 1% ORA&31,22% 9U6:< T9<:R ;9<?;KF >D;9 <R6K ;9P?9F<9= K?>79; DT ;DEF ORA&3/.12% 6< 8NK9 USING CURSOR TO SLO*E T.E ERROR: DECLARE CURSOR C IS SELECT DEPTNO$DNAME$LOC FROM DEPT5 TYPE DEPT(RECORD IS RECORD ( V(DEPTNO DEPT.DEPTNO-TYPE$ V(DNAME DEPT.DNAME-TYPE$ V(LOC DEPT.LOC-TYPE)5 DEPT(REC DEPT(RECORD5 BEGIN 13 OPEN C5 11 LOOP 12 FETCH C INTO DEPT(REC5 1) E!IT WHEN C-NOTFOUND5 1, DBMS(OUTPUT.PUT(LINE(DEPT(REC.V(DEPTNOVVDEPT(REC.V(DNAMEVVDEPT(REC.V(LOC)5 1. END LOOP5 1/ CLOSE C5 10# END5 12 / 13ACCOUNTINGNEW YOR' 23RESEARCHDALLAS )3SALESCHICAGO ,3OPERATIONSBOSTON PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 2 ) , . / 0 2 1 2 ) , . / 0 2

231

USING 5RO+TYPE: 1 2 ) , . / 0 2 DECLARE CURSOR C IS SELECT DEPTNO$DNAME$LOC FROM DEPT5 DEPT(REC DEPT-ROWTYPE5 BEGIN OPEN C5 LOOP FETCH C INTO DEPT(REC5 E!IT WHEN C-NOTFOUND5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DBMS(OUTPUT.PUT(LINE(DEPT(REC.DEPTNOVVDEPT(REC.DNAMEVVDEPT(REC.LOC)5 13 END LOOP5 11 CLOSE C5 12# END5 S"L4 / 13ACCOUNTINGNEW YOR' 23RESEARCHDALLAS )3SALESCHICAGO ,3OPERATIONSBOSTON PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DECLARE CURSOR C IS SELECT # FROM DEPT5 DEPT(REC DEPT-ROWTYPE5 BEGIN OPEN C5 LOOP FETCH C INTO DEPT(REC5 E!IT WHEN C-NOTFOUND5 DBMS(OUTPUT.PUT(LINE(DEPT(REC.DEPTNOVVDEPT(REC.DNAMEVVDEPT(REC.LOC)5 13 END LOOP5 11 CLOSE C5 12# END5 S"L4 / 13ACCOUNTINGNEW YOR' 23RESEARCHDALLAS )3SALESCHICAGO ,3OPERATIONSBOSTON PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 2 ) , . / 0 2

232

DECLARE CURSOR C IS SELECT # FROM EMP5 EMP(REC EMP-ROWTYPE5 BEGIN OPEN C5 LOOP FETCH C INTO EMP(REC5 E!IT WHEN C-NOTFOUND5 DBMS(OUTPUT.PUT(LINE(EMP(REC.EMPNOVVEMP(REC.ENAMEVVEMP(REC.JOBVV 13 EMP(REC.MGRVVEMP(REC.HIREDATEVVEMP(REC.SALVV 11 EMP(REC.COMMVVEMP(REC.DEPTNO)5 12 END LOOP5 1) CLOSE C5 1,# END5 1. / 0)/ SMITHCLER'0 3210&DEC&2323323 0, ALLENSALESMAN0/ 223&FEB&211/33)33)3 0.21WARDSALESMAN0/ 222&FEB&2112.3.33)3 0.//JONESMANAGER02) 32&APR&212 0.23 0/.,MARTINSALESMAN0/ 222&SEP&2112.31,33)3 0/ 2BLA'EMANAGER02) 31&MAY&2122.3)3 0022CLAR'MANAGER02) 3 &JUN&212,.313 0022SCOTTANALYST0.//1 &APR&20)33323

1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
02) 'INGPRESIDENT10&NOV&21.33313 02,,TURNERSALESMAN0/ 232&SEP&211.333)3 020/ADAMSCLER'00222)&MAY&20113323 0 33JAMESCLER'0/ 23)&DEC&21 .3)3 0 32FORDANALYST0.//3)&DEC&21)33323 0 ),MILLERCLER'00222)&JAN&221)3313 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

23)

PL0SQL TABLES: 1 DECLARE 2 TYPE NUMBERTAB IS TABLE OF NUMBER ) INDE! BY BINARY(INTEGER5 , V(NUMBERS NUMBERTAB5 . BEGIN FOR ASSIGNING VALUES% / FOR V(COUNT IN 1..13 LOOP 0 V(NUMBERS(V(COUNT) %I V(COUNT#135 2 END LOOP5 FOR RETRIVING VALUES FROM TABLE% FOR V(COUNT IN 1..13 LOOP 13 DBMS(OUTPUT.PUT(LINE(V(NUMBERS(V(COUNT))5 11 END LOOP5 12# END5 1) / 13 23 )3 ,3 .3 /3 03 23 3 133 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

1 DECLARE 2 TYPE NUMBERTAB IS TABLE OF NUMBER ) INDE! BY BINARY(INTEGER5 , V(NUMBERS NUMBERTAB5 . BEGIN / FOR V(COUNT IN 1..13 LOOP 0 V(NUMBERS(V(COUNT) %I V(COUNT#135 2 END LOOP5 FOR V(COUNT IN 1..13 LOOP 13 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%C)5 11 DBMS(OUTPUT.PUT(LINE(V(NUMBERS(V(COUNT))5 12 END LOOP5 1)# END5 1, / V(NUMBERS(1)%

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
13 V(NUMBERS(2)% 23 V(NUMBERS())% )3 V(NUMBERS(,)% ,3 V(NUMBERS(.)% .3 V(NUMBERS(/)% /3 V(NUMBERS(0)% 03 V(NUMBERS(2)% 23 V(NUMBERS( )% 3 V(NUMBERS(13)% 133 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 ED W;D<9 TN89 6TN9=<.7?T 1 2 ) , DECLARE TYPE NUMBERTAB IS TABLE OF NUMBER INDE! BY BINARY(INTEGER5 V(NUMBERS NUMBERTAB5

23,

. BEGIN / FOR V(COUNT IN 1..13 LOOP 0 V(NUMBERS(V(COUNT) %I V(COUNT#135 2 END LOOP5 FOR V(COUNT IN 1..13 LOOP 13 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 11 END LOOP5 12# END5 1) / V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3 V(NUMBERS(,)%,3 V(NUMBERS(.)%.3 V(NUMBERS(/)%/3 V(NUMBERS(0)%03 V(NUMBERS(2)%23 V(NUMBERS( )% 3 V(NUMBERS(13)%133 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 TYPE NUMBERTAB IS TABLE OF NUMBER ) INDE! BY BINARY(INTEGER5 , V(NUMBERS NUMBERTAB5 . BEGIN / FOR V(COUNT IN 1..13 LOOP 0 V(NUMBERS(V(COUNT) %I V(COUNT#135 2 END LOOP5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
FOR V(COUNT IN 1..13 LOOP 13 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 11 END LOOP5 12 DBMS(OUTPUT.PUT(LINE(V(NUMBERS.COUNT)5 1) DBMS(OUTPUT.PUT(LINE(V(NUMBERS.FIRST)5 1, DBMS(OUTPUT.PUT(LINE(V(NUMBERS.LAST)5 1.# END5 1/ / V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3 V(NUMBERS(,)%,3 V(NUMBERS(.)%.3 V(NUMBERS(/)%/3 V(NUMBERS(0)%03 V(NUMBERS(2)%23 V(NUMBERS( )% 3 V(NUMBERS(13)%133 13 1 13 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DECLARE TYPE NUMBERTAB IS TABLE OF NUMBER INDE! BY BINARY(INTEGER5 V(NUMBERS NUMBERTAB5 BEGIN FOR V(COUNT IN 1..13 LOOP V(NUMBERS(V(COUNT) %I V(COUNT#135 END LOOP5 FOR V(COUNT IN 1..13 LOOP 13 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 11 END LOOP5 12 DBMS(OUTPUT.PUT(LINE(CNUMBER OF ELEMENTS IN TABLE% CVV V(NUMBERS.COUNT)5 1) DBMS(OUTPUT.PUT(LINE(CFIRST ELEMENT IN TABLE % C VVV(NUMBERS.FIRST)5 1, DBMS(OUTPUT.PUT(LINE(CTHE LAST ELEMENT IN TABLE % CVVV(NUMBERS.LAST)5 1.# END5 S"L4 / V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3 V(NUMBERS(,)%,3 V(NUMBERS(.)%.3 V(NUMBERS(/)%/3 V(NUMBERS(0)%03 V(NUMBERS(2)%23 V(NUMBERS( )% 3 V(NUMBERS(13)%133 NUMBER OF ELEMENTS IN TABLE% 13 FIRST ELEMENT IN TABLE % 1 THE LAST ELEMENT IN TABLE % 13 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 2 ) , . DECLARE TYPE NUMBERTAB IS TABLE OF NUMBER INDE! BY BINARY(INTEGER5 V(NUMBERS NUMBERTAB5 BEGIN 1 2 ) , . / 0 2

23.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
/ FOR V(COUNT IN 1..13 LOOP 0 V(NUMBERS(V(COUNT) %I V(COUNT#135 2 END LOOP5 FOR V(COUNT IN 1..13 LOOP 13 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 11 END LOOP5 12 DBMS(OUTPUT.PUT(LINE(CNUMBER OF ELEMENTS IN TABLE% CVV V(NUMBERS.COUNT)5 1) DBMS(OUTPUT.PUT(LINE(CFIRST ELEMENT IN TABLE % C VVV(NUMBERS.FIRST)5 1, DBMS(OUTPUT.PUT(LINE(CTHE LAST ELEMENT IN TABLE % CVVV(NUMBERS.LAST)5 1. DBMS(OUTPUT.PUT(LINE(CNUMBER OF ELEMENTS IN TABLE% CVV V(NUMBERS.COUNT)5 1/ DBMS(OUTPUT.PUT(LINE(CVALUE OF THE FIRST ELEMENT IN TABLE % C VVV(NUMBERS(V(NUMBERS.FIRST))5 10 DBMS(OUTPUT.PUT(LINE(CVALUE OF THE LAST ELEMENT THE LAST ELEMENT IN TABLE % CVV V(NUMBERS(V(NUMBERS.LAST))5 12# END5 1 / V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3 V(NUMBERS(,)%,3 V(NUMBERS(.)%.3 V(NUMBERS(/)%/3 V(NUMBERS(0)%03 V(NUMBERS(2)%23 V(NUMBERS( )% 3 V(NUMBERS(13)%133 NUMBER OF ELEMENTS IN TABLE% 13 FIRST ELEMENT IN TABLE % 1 THE LAST ELEMENT IN TABLE % 13 NUMBER OF ELEMENTS IN TABLE% 13 VALUE OF THE FIRST ELEMENT IN TABLE % 13 VALUE OF THE LAST ELEMENT THE LAST ELEMENT IN TABLE % 133 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

23/

1 DECLARE 2 TYPE NUMBERTAB IS TABLE OF NUMBER ) INDE! BY BINARY(INTEGER5 , V(NUMBERS NUMBERTAB5 . BEGIN / FOR V(COUNT IN 1..13 LOOP 0 V(NUMBERS(V(COUNT) %I V(COUNT#135 2 END LOOP5 FOR V(COUNT IN 1..13 LOOP 13 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 11 END LOOP5 12 DBMS(OUTPUT.PUT(LINE(V(NUMBERS.PRIOR()))5 1)# END5 1, / V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
V(NUMBERS(,)%,3 V(NUMBERS(.)%.3 V(NUMBERS(/)%/3 V(NUMBERS(0)%03 V(NUMBERS(2)%23 V(NUMBERS( )% 3 V(NUMBERS(13)%133 2 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 TYPE NUMBERTAB IS TABLE OF NUMBER ) INDE! BY BINARY(INTEGER5 , V(NUMBERS NUMBERTAB5 . BEGIN / FOR V(COUNT IN 1..13 LOOP 0 V(NUMBERS(V(COUNT) %I V(COUNT#135 2 END LOOP5 FOR V(COUNT IN 1..13 LOOP 13 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 11 END LOOP5 12 DBMS(OUTPUT.PUT(LINE(CTHE VALUE OF PRIOR% CVV V(NUMBERS(V(NUMBERS.PRIOR())))5 1)# END5 S"L4 / V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3 V(NUMBERS(,)%,3 V(NUMBERS(.)%.3 V(NUMBERS(/)%/3 V(NUMBERS(0)%03 V(NUMBERS(2)%23 V(NUMBERS( )% 3 V(NUMBERS(13)%133 THE VALUE OF PRIOR% 23 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 TYPE NUMBERTAB IS TABLE OF NUMBER ) INDE! BY BINARY(INTEGER5 , V(NUMBERS NUMBERTAB5 . BEGIN / FOR V(COUNT IN 1..13 LOOP 0 V(NUMBERS(V(COUNT) %I V(COUNT#135 2 END LOOP5 FOR V(COUNT IN 1..13 LOOP 13 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 11 END LOOP5 12 DBMS(OUTPUT.PUT(LINE(CTHE VALUE OF PRIOR% CVV V(NUMBERS(V(NUMBERS.NE!T())))5 1)# END5 S"L4 /

230

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3 V(NUMBERS(,)%,3 V(NUMBERS(.)%.3 V(NUMBERS(/)%/3 V(NUMBERS(0)%03 V(NUMBERS(2)%23 V(NUMBERS( )% 3 V(NUMBERS(13)%133 THE VALUE OF PRIOR% ,3 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

232

1 DECLARE 2 TYPE NUMBERTAB IS TABLE OF NUMBER ) INDE! BY BINARY(INTEGER5 , V(NUMBERS NUMBERTAB5 . BEGIN / FOR V(COUNT IN 1..13 LOOP 0 V(NUMBERS(V(COUNT) %I V(COUNT#135 2 END LOOP5 V(NUMBERS.DELETE5 13 FOR V(COUNT IN 1..13 LOOP 11 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 12 END LOOP5 1)# END5 1, / DECLARE # ERROR 6< 8NK9 1% ORA&31,3)% KD =6<6 TD?K= ORA&3/.12% 6< 8NK9 11 1 DECLARE 2 TYPE NUMBERTAB IS TABLE OF NUMBER ) INDE! BY BINARY(INTEGER5 , V(NUMBERS NUMBERTAB5 . BEGIN / FOR V(COUNT IN 1..13 LOOP 0 V(NUMBERS(V(COUNT) %I V(COUNT#135 2 END LOOP5 V(NUMBERS.DELETE(2)5 13 FOR V(COUNT IN 1..13 LOOP 11 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 12 END LOOP5 1)# END5 S"L4 / V(NUMBERS(1)%13 V(NUMBERS(2)%23

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
V(NUMBERS())%)3 V(NUMBERS(,)%,3 V(NUMBERS(.)%.3 V(NUMBERS(/)%/3 V(NUMBERS(0)%03 DECLARE # ERROR 6< 8NK9 1% ORA&31,3)% KD =6<6 TD?K= ORA&3/.12% 6< 8NK9 11 DECLARE TYPE NUMBERTAB IS TABLE OF NUMBER INDE! BY BINARY(INTEGER5 V(NUMBERS NUMBERTAB5 BEGIN FOR V(COUNT IN 1..13 LOOP V(NUMBERS(V(COUNT) %I V(COUNT#135 END LOOP5 V(NUMBERS.DELETE(,$/)5 13 FOR V(COUNT IN 1..13 LOOP 11 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 12 END LOOP5 1)# END5 S"L4 / V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3 DECLARE # ERROR 6< 8NK9 1% ORA&31,3)% KD =6<6 TD?K= ORA&3/.12% 6< 8NK9 11 1 DECLARE 2 TYPE NUMBERTAB IS TABLE OF NUMBER ) INDE! BY BINARY(INTEGER5 , V(NUMBERS NUMBERTAB5 . BEGIN / FOR V(COUNT IN 1..13 LOOP 0 V(NUMBERS(V(COUNT) %I V(COUNT#135 2 END LOOP5 V(NUMBERS.DELETE(,$/)5 13 FOR V(COUNT IN 1..13 LOOP 11 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 12 END LOOP5 1) E!CEPTION 1, WHEN NO(DATA(FOUND THEN 1. FOR V(COUNT IN 0..13 LOOP 1/ DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 10 END LOOP5 12# END5 S"L4 / V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3 V(NUMBERS(0)%03 V(NUMBERS(2)%23 1 2 ) , . / 0 2

23

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
V(NUMBERS( )% 3 V(NUMBERS(13)%133 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 TYPE NUMBERTAB IS TABLE OF NUMBER ) INDE! BY BINARY(INTEGER5 , V(NUMBERS NUMBERTAB5 . V(BOOL BOOLEAN5 / BEGIN 0 FOR V(COUNT IN 1..13 LOOP 2 V(NUMBERS(V(COUNT) %I V(COUNT#135 END LOOP5 13 FOR V(COUNT IN 1..13 LOOP 11 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 12 END LOOP5 1) V(BOOL %I V(NUMBERS.E!ISTS())5 1, IF V(BOOL THEN 1. DBMS(OUTPUT.PUT(LINE(CTHE ELEMENT E!ISITSC)5 1/ ELSE 10 DBMS(OUTPUT.PUT(LINE(CTHE ELEMENT NOT E!ISITSC)5 12 END IF5 1 # END5 S"L4 / V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3 V(NUMBERS(,)%,3 V(NUMBERS(.)%.3 V(NUMBERS(/)%/3 V(NUMBERS(0)%03 V(NUMBERS(2)%23 V(NUMBERS( )% 3 V(NUMBERS(13)%133 THE ELEMENT E!ISITS PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 TYPE NUMBERTAB IS TABLE OF NUMBER ) INDE! BY BINARY(INTEGER5 , V(NUMBERS NUMBERTAB5 . V(BOOL BOOLEAN5 / BEGIN 0 FOR V(COUNT IN 1..13 LOOP 2 V(NUMBERS(V(COUNT) %I V(COUNT#135 END LOOP5 13 FOR V(COUNT IN 1..13 LOOP 11 DBMS(OUTPUT.PUT(LINE(CV(NUMBERS(CVV V(COUNT VVC)%CVVV(NUMBERS(V(COUNT))5 12 END LOOP5

213

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1) V(BOOL %I V(NUMBERS.E!ISTS(+NUMBER)5 1, IF V(BOOL THEN 1. DBMS(OUTPUT.PUT(LINE(CTHE ELEMENT E!ISITSC)5 1/ ELSE 10 DBMS(OUTPUT.PUT(LINE(CTHE ELEMENT NOT E!ISITSC)5 12 END IF5 1 # END5 S"L4 / EK<9; Q68?9 TD; K?>79;% 1 V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3 V(NUMBERS(,)%,3 V(NUMBERS(.)%.3 V(NUMBERS(/)%/3 V(NUMBERS(0)%03 V(NUMBERS(2)%23 V(NUMBERS( )% 3 V(NUMBERS(13)%133 THE ELEMENT E!ISITS PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / EK<9; Q68?9 TD; K?>79;% 11 V(NUMBERS(1)%13 V(NUMBERS(2)%23 V(NUMBERS())%)3 V(NUMBERS(,)%,3 V(NUMBERS(.)%.3 V(NUMBERS(/)%/3 V(NUMBERS(0)%03 V(NUMBERS(2)%23 V(NUMBERS( )% 3 V(NUMBERS(13)%133 THE ELEMENT NOT E!ISITS PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 TYPE CHARTAB IS TABLE OF VARCHAR2(13) ) INDE! BY BINARY(INTEGER5 , V(CHAR CHARTAB5 . BEGIN / V(CHAR(1)%ICPAVANC5 0 V(CHAR(&2)%IC'UMARC5 2 V(CHAR(3) %I CGAYATRIC5 DBMS(OUTPUT.PUT(LINE(V(CHAR(1))5 13 DBMS(OUTPUT.PUT(LINE(V(CHAR(&2))5 11 DBMS(OUTPUT.PUT(LINE(V(CHAR(3))5 12# END5 1) / PAVAN 'UMAR GAYATRI

211

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

212

DECLARE TYPE DATETAB IS TABLE OF DATE INDE! BY BINARY(INTEGER5 V(DATE DATETAB5 BEGIN V(DATE(1)%IC31&DEC&3.C5 V(DATE(&2)%IC11&MAR&32C5 V(DATE(3) %IC31&DEC&3 C5 DBMS(OUTPUT.PUT(LINE(V(DATE(1))5 13 DBMS(OUTPUT.PUT(LINE(V(DATE(&2))5 11 DBMS(OUTPUT.PUT(LINE(V(DATE(3))5 12# END5 S"L4 / 31&DEC&3. 11&MAR&32 31&DEC&3 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

1 2 ) , . / 0 2

PL0SQL TABLES +IT. 5RO+TYPE: 1 DECLARE 2 CURSOR C IS SELECT # FROM DEPT5 ) TYPE DEPT(TABLE(TYPE IS TABLE OF DEPT-ROWTYPE , INDE! BY BINARY(INTEGER5 . DEPT(TABLE DEPT(TABLE(TYPE5 / V(COUN NUMBER(13)%I35 0 BEGIN 2 OPEN C5 LOOP 13 V(COUN %I V(COUNJ15 11 FETCH C INTO DEPT(TABLE(V(COUN)5 12 E!IT WHEN C-NOTFOUND5 1) END LOOP5 1, CLOSE C5 1.# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 CURSOR C IS SELECT # FROM DEPT5 ) TYPE DEPT(TABLE(TYPE IS TABLE OF DEPT-ROWTYPE , INDE! BY BINARY(INTEGER5 . DEPT(TABLE DEPT(TABLE(TYPE5 / V(DEPTREC DEPT-ROWTYPE5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0 V(COUN NUMBER(13)%I35 2 BEGIN OPEN C5 13 11 12 1) 1, 1. LOOP V(COUN %I V(COUNJ15 FETCH C INTO DEPT(TABLE(V(COUN)5 E!IT WHEN C-NOTFOUND5 END LOOP5 CLOSE C5

21)

1/ V(DEPTREC %IDEPT(TABLE(1)5 10 DBMS(OUTPUT.PUT(LINE(V(DEPTREC.DEPTNOVVV(DEPTREC.DNAMEVV 12 V(DEPTREC.LOC)5 1 # END5 23 / 13ACCOUNTINGNEW YOR' PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 CURSOR C IS SELECT # FROM DEPT5 ) TYPE DEPT(TABLE(TYPE IS TABLE OF DEPT-ROWTYPE , INDE! BY BINARY(INTEGER5 . DEPT(TABLE DEPT(TABLE(TYPE5 / V(DEPTREC DEPT-ROWTYPE5 0 V(COUN NUMBER(13)%I35 2 BEGIN OPEN C5 13 LOOP 11 V(COUN %I V(COUNJ15 12 FETCH C INTO DEPT(TABLE(V(COUN)5 1) E!IT WHEN C-NOTFOUND5 1, END LOOP5 1. CLOSE C5 1/ V(DEPTREC %IDEPT(TABLE(1)5 10 DBMS(OUTPUT.PUT(LINE(V(DEPTREC.DEPTNOVVV(DEPTREC.DNAMEVV 12 V(DEPTREC.LOC)5 1 V(DEPTREC %IDEPT(TABLE(2)5 23 DBMS(OUTPUT.PUT(LINE(V(DEPTREC.DEPTNOVVV(DEPTREC.DNAMEVV 21 V(DEPTREC.LOC)5 22 V(DEPTREC %IDEPT(TABLE())5 2) DBMS(OUTPUT.PUT(LINE(V(DEPTREC.DEPTNOVVV(DEPTREC.DNAMEVV 2, V(DEPTREC.LOC)5 2. V(DEPTREC %IDEPT(TABLE(,)5 2/ DBMS(OUTPUT.PUT(LINE(V(DEPTREC.DEPTNOVVV(DEPTREC.DNAMEVV 20 V(DEPTREC.LOC)5 22# END5 2 / 13ACCOUNTINGNEW YOR' 23RESEARCHDALLAS )3SALESCHICAGO ,3OPERATIONSBOSTON PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
STORED PROCEDURES: S"L4 CREATE TABLE EMP(DUP 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 SELECT # FROM EMP(DUP5 EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 1, ;DEF F989:<9=. PROCEDURE +IT. IN PARA)ETER: 1 CREATE OR REPLACE PROCEDURE BALAJI 2 (V(EMPNO IN EMP(DUP.EMPNO-TYPE) ) IS , BEGIN . UPDATE EMP(DUP / SET SAL I SAL J 1333 0 WHERE EMPNO I V(EMPNO5 2# END5 S"L4 / P;D:9=?;9 :;96<9=. S"L4 E!ECUTE BALAJI(0)/ )5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT # FROM EMP(DUP5 EMPNO ENAME JOB MGR HIREDATE &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 1233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 SAL COMM DEPTNO 23 )3 )3 23 )3 )3 13 23 COMM 23 )33 .33 23 1,33 13 23 13 1.33 )3 23 13 3 )3 23 )3 )3 )3 )3 DEPTNO

21,

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
02) 'ING 02,, TURNER 020/ ADAMS 0 33 JAMES 0 32 FORD 0 ), MILLER 1, ;DEF F989:<9=. PROCEDURE +IT. OUT PARA)ETER: 1 CREATE OR REPLACE PROCEDURE BALAJI1 2 (V(EMPNO IN EMP.EMPNO-TYPE$ ) V(ENAME OUT EMP.ENAME-TYPE$ , V(SAL OUT EMP.SAL-TYPE$ . V(DEPTNO OUT EMP.DEPTNO-TYPE) / 0 IS 2 BEGIN SELECT ENAME$SAL$DEPTNO INTO V(ENAME$V(SAL$V(DEPTNO 13 FROM EMP WHERE EMPNOIV(EMPNO5 11# END5 S"L4 / P;D:9=?;9 :;96<9=. 1 DECLARE 2 P(ENAME EMP.ENAME-TYPE5 ) P(SAL EMP.SAL-TYPE5 , P(DEPTNO EMP.DEPTNO-TYPE5 . P(EMPNO EMP.EMPNO-TYPE%I0)/ 5 / BEGIN 0 BALAJI1(P(EMPNO$P(ENAME$P(SAL$P(DEPTNO)5 2 DBMS(OUTPUT.PUT(LINE(P(ENAMEVVP(SALVVP(DEPTNO)5 # END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON S"L4 / SMITH23323 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 VARIABLE G(ENAME VARCHAR2(13) S"L4 VARIABLE G(SAL NUMBER PRESIDENT 10&NOV&21 .333 SALESMAN 0/ 2 32&SEP&21 1.33 CLER' 0022 2)&MAY&20 1133 CLER' 0/ 2 3)&DEC&21 .3 ANALYST 0.// 3)&DEC&21 )333 CLER' 0022 2)&JAN&22 1)33 13 3 23 )3 23 13 )3

21.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 VARIABLE G(DEPTNO NUMBER S"L4 E!ECUTE BALAJI1(0)/ $%G(ENAME$%G(SAL$%G(DEPTNO)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 PRINT G(ENAME G(ENAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& SMITH

21/

S"L4 PRINT G(SAL G(SAL &&&&&&&&&& 233

S"L4 PRINT G(DEPTNO G(DEPTNO &&&&&&&&&& 23 PROCEDURE +IT. IN OUT PARA)ETER: 1 CREATE OR REPLACE PROCEDURE BALAJI2 2 (V(EMPNO(SAL IN OUT NUMBER) ) IS , BEGIN . SELECT SAL INTO V(EMPNO(SAL / FROM EMP WHERE EMPNOIV(EMPNO(SAL5 0# END5 2 / P;D:9=?;9 :;96<9=. 1 DECLARE 2 P(EMPNO(SAL NUMBER%I0)/ 5 ) BEGIN , BALAJI2(P(EMPNO(SAL)5 . DBMS(OUTPUT.PUT(LINE(P(EMPNO(SAL)5 /# END5 0 / 233 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 VARIABLE G(EMPNO(SAL NUMBER

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 BEGIN 2 %G(EMPNO(SAL%I0)/ 5 )# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 E!ECUTE BALAJI2(%G(EMPNO(SAL)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 PRINT G(EMPNO(SAL G(EMPNO(SAL &&&&&&&&&&& 233 USING DEFAULT IN PROCEDURES: S"L4 CREATE TABLE DEPT1 2 AS ) SELECT # FROM DEPT5 T6789 :;96<9=. S"L4 DELETE FROM DEPT15 , ;DEF =989<9=. S"L4 COMMIT5 CD>>N< :D>B89<9. S"L4 CREATE SE"UENCE ADD(DEPT(SE" 2 INCREMENT BY 1 ) START WITH 133 , MA!VALUE 123 . NOCACHE5 S9P?9K:9 :;96<9=. 1 CREATE OR REPLACE PROCEDURE ADD(DEPT 2 (V(DNAME IN DEPT1.DNAME-TYPE DEFAULT CPAVANC$ ) V(LOC IN DEPT1.LOC-TYPE DEFAULT CGAYATRIC) , IS . BEGIN / INSERT INTO DEPT1 0 VALUES 2 (ADD(DEPT(SE".NE!TVAL$V(DNAME$V(LOC)5 # END5 S"L4 / P;D:9=?;9 :;96<9=. 1 BEGIN 2 ADD(DEPT5

210

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) ADD(DEPT(CSALESC$CNEWYOR'C)5 , ADD(DEPT(V(LOC I4 CDALLASC$V(DNAME I4 CEDUCATIONC)5 . ADD(DEPT(V(LOC I4 CBOSTONC)5 /# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT # FROM DEPT15 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 133 PAVAN GAYATRI 131 SALES NEWYOR' 132 EDUCATION DALLAS 13) PAVAN BOSTON S"L4 CREATE TABLE LOG(TABLE 2 (USERID VARCHAR2(13)$ ) LOG(DATE DATE)5 T6789 :;96<9=.

212

DECLARING SUBPROGRA)S: S"L4 CREATE OR REPLACE PROCEDURE LEAVE(EMP2 2 (V(EMPNO IN EMP.EMPNO-TYPE) ) IS , PROCEDURE LOG(E!EC . IS / BEGIN 0 INSERT INTO LOG(TABLE(USERID$LOG(DATE) 2 VALUES (USER$SYSDATE)5 END LOG(E!EC5 13 BEGIN 11 DELETE FROM EMP(DUP 12 WHERE EMPNOIV(EMPNO5 1) LOG(E!EC5 1, END5 1. / P;D:9=?;9 :;96<9=. S"L4 SELECT # FROM LOG(TABLE5 KD ;DEF F989:<9= S"L4 SELECT # FROM EMP(DUP5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 1, ;DEF F989:<9=. S"L4 BEGIN 2 LEAVE(EMP2(0)/ )5 ) END5 , / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DEPTNO 23 )3 )3 23 )3 )3 13 23 13 3 23 )3 23 13 )3

21

S"L4 SELECT # FROM LOG(TABLE5 USERID LOG(DATE &&&&&&&&&& &&&&&&&&& SCOTT 3 &JUN&3. S"L4 SELECT # FROM EMP(DUP5 EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 1) ;DEF F989:<9=. DEPTNO )3 )3 23 )3 )3 13 23 13 )3 23 )3 23 13

S"L4 CREATE OR REPLACE PROCEDURE RAISE(SALARY 2 (V(EMPNO IN EMP.EMPNO-TYPE) ) IS

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
, BEGIN . UPDATE EMP(DUP / SET SAL I SAL# 1.13 0 WHERE EMPNOIV(EMPNO5 2 END5 / P;D:9=?;9 :;96<9=.

223

S"L4 SELECT # FROM EMP(DUP5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 1, ;DEF F989:<9=. IN*O-ING A PROCEDURE FRO) A STORED PROCEDURE: 1 CREATE OR REPLACE PROCEDURE GAYATRI 2 IS ) CURSOR C IS SELECT EMPNO FROM EMP(DUP5 , BEGIN . FOR E IN C / LOOP 0 RAISE(SALARY(E.EMPNO)5 2 END LOOP5 COMMIT5 13# END5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 / P;D:9=?;9 :;96<9=. S"L4 E!ECUTE GAYATRI5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT # FROM EMP(DUP5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 223 23 0, ALLEN SALESMAN 0/ 2 23&FEB&21 10/3 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 1)0. .33 )3 0.// JONES MANAGER 02) 32&APR&21 )202.. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 1)0. 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 )1). )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2/ . 13 0022 SCOTT ANALYST 0.// 1 &APR&20 ))33 23 02) 'ING PRESIDENT 10&NOV&21 ..33 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1/.3 3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1213 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 13,. )3 0 32 FORD ANALYST 0.// 3)&DEC&21 ))33 23 0 ), MILLER CLER' 0022 2)&JAN&22 1,)3 13 1, ;DEF F989:<9=. DROPING A STORED PROCEDURE: S"L4 DROP PROCEDURE GAYATRI5 P;D:9=?;9 =;DBB9=. QUERING STORED PROCEDURES STORED IN DATABASE: S"L4 SELECT OBJECT(NAME$OBJECT(TYPE 2 FROM USER(OBJECTS ) WHERE OBJECT(TYPE I CPROCEDUREC5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE &&&&&&&&&&&&&&&&&& ADD(DEPT PROCEDURE BALAJI PROCEDURE BALAJI1 PROCEDURE BALAJI2 PROCEDURE LEAVE(EMP2 PROCEDURE RAISE(SALARY PROCEDURE / ;DEF F989:<9=.

221

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
QUERING STORED PROCEDURES TE/T STORED IN DATABASE: S"L4 DESC USER(SOURCE N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& NAME VARCHAR2()3) TYPE VARCHAR2(12) LINE NUMBER TE!T VARCHAR2(,333) S"L4 SELECT TE!T FROM USER(SOURCE 2 WHERE NAMEICBALAJIC ) ORDER BY LINE5 TE!T &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& PROCEDURE BALAJI (V(EMPNO IN EMP.EMPNO-TYPE) IS BEGIN UPDATE EMP(DUP SET SAL I SAL J 1333 WHERE EMPNO I V(EMPNO5 END5 2 ;DEF F989:<9=. 1 SELECT TE!T FROM USER(SOURCE 2 WHERE NAMEICBALAJI1C )# ORDER BY LINE S"L4 / TE!T &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& PROCEDURE BALAJI1 (V(EMPNO IN EMP.EMPNO-TYPE$ V(ENAME OUT EMP.ENAME-TYPE$ V(SAL OUT EMP.SAL-TYPE$ V(DEPTNO OUT EMP.DEPTNO-TYPE ) IS BEGIN SELECT ENAME$SAL$DEPTNO INTO V(ENAME$V(SAL$V(DEPTNO FROM EMP WHERE EMPNOIV(EMPNO5 END5 11 ;DEF F989:<9=. 1 SELECT TE!T FROM USER(SOURCE 2 WHERE NAMEICBALAJI2C )# ORDER BY LINE S"L4 / TE!T &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& PROCEDURE BALAJI2 (V(EMPNO(SAL IN OUT NUMBER) IS BEGIN SELECT SAL INTO V(EMPNO(SAL FROM EMP WHERE EMPNOIV(EMPNO(SAL5 END5

222

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0 ;DEF F989:<9=. S"L4 CREATE OR REPLACE PROCEDURE LOG(E!ECUTION 2 IS ) BEGIN , INPUT INTO LOG(TABLE . VALUES / (USER$SYSDATE)5 0 END5 2 / W6;KNKS% P;D:9=?;9 :;96<9= EN<R :D>BN86<NDK 9;;D;F. "UERING ERRORS IN STORED PROCEDURES STORED IN DATABASE% S"L4 DESC USER(ERRORS N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& NAME NOT NULL VARCHAR2()3) TYPE VARCHAR2(12) SE"UENCE NOT NULL NUMBER LINE NOT NULL NUMBER POSITION NOT NULL NUMBER TE!T NOT NULL VARCHAR2(,333) S"L4 SELECT LINEVVC/CVV POSITION POS$TE!T FROM 2 USER(ERRORS ) WHERE NAMEICLOG(E!ECUTIONC , ORDER BY LINE5 POS &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TE!T &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ,/0 PLS&3313)% EK:D?K<9;9= <R9 FA>7D8 OINTOO ER9K 9UB9:<NKS DK9 DT <R9 TD88DENKS% %I . ( Y - 5 0/1 PLS&3313)% EK:D?K<9;9= <R9 FA>7D8 OENDO S"L4 SHOW ERRORS PROCEDURE LOG(E!ECUTION E;;D;F TD; PROCEDURE LOG(E!ECUTION% LINE/COL ERROR &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ,/0 PLS&3313)% EK:D?K<9;9= <R9 FA>7D8 OINTOO ER9K 9UB9:<NKS DK9 DT <R9 TD88DENKS% %I . ( Y - 5 0/1 PLS&3313)% EK:D?K<9;9= <R9 FA>7D8 OENDO

22)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE

22,

STORED FUNCTIONS: S"L4 CREATE OR REPLACE FUNCTION GET(SAL 2 (V(EMPNO IN EMP.EMPNO-TYPE) ) RETURN NUMBER , IS . V(SAL EMP.SAL-TYPE5 / BEGIN 0 SELECT SAL INTO V(SAL FROM EMP 2 WHERE EMPNOIV(EMPNO5 RETURN V(SAL5 13 END5 11 / F?K:<NDK :;96<9=. CALLING FUNTION: S"L4 VARIABLE G(SALARY NUMBER S"L4 E!ECUTE %G(SALARY %IGET(SAL(0)/ ) PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 PRINT G(SALARY G(SALARY &&&&&&&&&& 233 1 DECLARE 2 V(SALARY NUMBER(13)5 ) BEGIN , V(SALARY%IGET(SAL(0)/ )5 . DBMS(OUTPUT.PUT(LINE(V(SALARY)5 /# END5 S"L4 / 233 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CALLING FUNCTION IN *ARIOUS PLACES: S"L4 CREATE OR REPLACE FUNCTION TA! 2 (V(VALUE IN NUMBER) ) RETURN NUMBER , IS . BEGIN / RETURN (V(VALUE#3.32)5 0 END5 2 / F?K:<NDK :;96<9=. S"L4 SELECT EMPNO$ENAME$SAL$TA!(SAL) FROM EMP5 EMPNO ENAME SAL TA!(SAL) &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH 233 /, 0, ALLEN 1/33 0.21 WARD 12.3 133 0.// JONES 2 0. 2)2 0/., MARTIN 12.3 133 0/ 2 BLA'E 22.3 0022 CLAR' 2,.3 1 / 0022 SCOTT )333 2,3 02) 'ING .333 02,, TURNER 1.33 123 020/ ADAMS 1133 22 0 33 JAMES .3 0/ 0 32 FORD )333 0 ), MILLER 1)33 13, 1, ;DEF F989:<9=.

22.

122

222 ,33

2,3

1 SELECT EMPNO FROM EMP 2 WHERE TA!(SAL) 4 (SELECT MA!(TA!(SAL)) FROM EMP )# WHERE DEPTNOI)3) ORDER BY TA!(SAL) DESC , / EMPNO &&&&&&&&&& 02) 0022 0 32 0.// 1 SELECT # FROM EMP 2 WHERE TA!(SAL) 4 (SELECT MA!(TA!(SAL)) FROM EMP )# WHERE DEPTNOI)3) ORDER BY TA!(SAL) DESC S"L4 / EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 02) 'ING PRESIDENT 10&NOV&21 0022 SCOTT ANALYST 0.// 1 &APR&20 0 32 FORD ANALYST 0.// 3)&DEC&21 0.// JONES MANAGER 02) 32&APR&21 COMM .333 )333 )333 2 0. DEPTNO 13 23 23 23

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT SAL$TA!(SAL) FROM EMP 2 WHERE TA!(SAL) 4 (SELECT MA!(TA!(SAL)) FROM EMP ) WHERE DEPTNOI)3) ORDER BY TA!(SAL) DESC5 SAL TA!(SAL) &&&&&&&&&& &&&&&&&&&& .333 ,33 )333 2,3 )333 2,3 2 0. 2)2 DROPING A FUNCTION: S"L4 DROP FUNCTION TA!5 F?K:<NDK =;DBB9=. SELECTING FUNCTION FRO) DATABASE: S"L4 SELECT OBJECT(NAME$OBJECT(TYPE 2 FROM USER(OBJECTS ) WHERE OBJECT(TYPEICFUNCTIONC5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE &&&&&&&&&&&&&&&&&& GET(SAL FUNCTION SOURCE CODE OF FUNCTION: 1 SELECT TE!T FROM USER(SOURCE 2# WHERE NAMEICGET(SALC ) / TE!T &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& FUNCTION GET(SAL (V(EMPNO IN EMP.EMPNO-TYPE) RETURN NUMBER IS V(SAL EMP.SAL-TYPE5 BEGIN SELECT SAL INTO V(SAL FROM EMP WHERE EMPNOIV(EMPNO5 RETURN V(SAL5 END5 13 ;DEF F989:<9=. DESCRIBING FUNCTION IN SQL*PLUS: S"L4 DESC GET(SAL FUNCTION GET(SAL RETURNS NUMBER A;S?>9K< N6>9 TAB9 IK/O?< D9T6?8<@ &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&& &&&&&& &&&&&&&& V(EMPNO NUMBER(,) IN DESCRIBING PROCEDURE IN SQL*PLUS:

22/

S"L4 DESC PROCEDURE(NAME5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
YOU WILL GET ALL PARAMETER INFORMATION OF THE PROCEDURE. LI'E ABOVE OUTPUT FOR FUNCTION. LOCATIONS TO CALL USER%DEFINED FUNCTIONS: SELECT LIST OF A SELECT COMMAND. CONDITION OF WHERE AND HAVING CLAUSES. CONNECT BY $START WITH $ORDER BY AND GROUP BY CLAUSES. VALUES CLAUSES OF INSERT COMMAND. SET CLAUSE OF THE UPDATE COMMAND.

220

CO)PARING PROCEDURES AND FUNCTIONS: PROCEDURE FUNCTION

E!ECUTE AS A PL/S"L STATEMENT.

INVO'E AS PART OF A N E!PRESSION.

NO RETURN DATA TYPE.

MUST CONTAIN A RETURN DATA TYPE.

CAN RETURN NONE$ONE OR MANY VALUES

MUST RETURN A SINGLE VALUE.

BENEFITS OF STORED PROCEDURES AND STORED FUNCTIONS:

IMPROVED PERFORMANCE. IMPROVED MAINTENANCE. IMPROVED DATA SECURITY AND INTEGRITY.

TRIGGERS: A TRIGGER IS A PL/S"L BLOC' THAT E!ECUTES IMPLICITLY WHENEVER A PARTICULAR EVENT TA'ES PLACE. CREATING TRIGGERS: TRIGGER TI)ING: &FOR TABLE % BEFORE$AFTER &FOR VIEW % INSTEAD OF. TRIGGERING E*ENT: INSERT$UPDATE OR DELETE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
TABLE NA)E: ON TABLE OR VIEW. TRIGGER TYPE : ROW OR STATEMENT. +.EN CLAUSE : RESTRICTING CONDITION TRIGGER BODY : PL/S"L BLOC'. TRIGGER CO)PONENTS: TRIGGER TI)ING: WHEN SHOULD THE TRIGGER FIRE@ BEFORE: E!ECUTE THE TRIGGER BODY BEFORE THE TRIGGERING DML EVENT ON A TABLE. AFTER: E!ECUTE THE TRIGGER BODY AFTER THE TRIGGERING DML EVENT ON A TABLE. INSTEAD OF: E!ECUTE THE TRIGGER BODY INSTEAD OF THE TRIGGERING STATEMENT. USED FOR VIEWS THAT ARE NOT OTHERWISE MODIFIABLE. WHAT DML STATEMENT WIL CAUSE THE TRIGGER TO E!ECUTE@ TRIGGER TYPE: STATE)ENT: THE TRIGGER BODY E!ECUTES ONCE FOR THE TRIGGERING EVENT. THIS IS THE DEFAULT. RO+:THE TRIGGER BODY E!ECUTES ONCE FOR EACH ROW AFFECTED BY THE TRIGGERING EVENT. WHAT ACTION SHOULD THE TRIGGER PERFORM@ THE TRIGGER BODY IS A PL/S"L BLOC' OR A CALL TO A PROCEDURE. FIRING SEQUENCE: FIRING SE"UENCE OF A TRIGGER ON A TABLE$ WHEN A SINGLE ROW IS MANIPULATED. D)L STATE)ENT: INSERT INTO DEPT VALUES (.3$COMPUTERS$NEW YOR')5 TRIGGERING ACTION: BEFORE STATE)ENT TRIGGER( DEPTNO 13 23 )3 ,3 DNAME ACCOUNTING RESEARCH SALES OPERATIONS LOC NEW YOR' DALLAS CHICAGO BOSTON INSERT. UPDATE. DELETE.

222

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
.3 COMPUTERS NEW YOR' BEFORE ROW TRIGGER. AFTER ROW TRIGGER. AFTER STATEMENT TRIGGER.

22

FIRING SEQUENCE OF A TRIGGER ON A TABLE" +.EN )ANY RO+S ARE )ANUPULATED( UPDATE EMP SET SAL I SAL#1.1 WHERE DEPTNOI)35 BEFORE STATEMENT TRIGGER EMPNO 02) ENAME 'ING DEPTNO )3 BEFORE ROW TRIGGER AFTER ROW TRIGGER. 0/ 2 BLA'E )3 BEFORE ROW TRIGGER AFTER ROW TRIGGER. 0022 SMITH )3 BEFORE ROW TRIGGER AFTER ROW TRIGGER. AFTER STATEMENT TRIGGER.

WHEN THE TRIGGERING DATA MANIPULATION STATEMENT AFFECTS MANY ROWS$ THE STATEMENT TRIGGER FIRES E!ACTLY ONCE$ AND THE ROW TRIGGER FIRES ONCE FOR EVERY ROW AFFECTED BY STATEMENT. THE S"L STATEMENT IN THE SLIDE ABOVE CAUSES A ROW&LEVEL TRIGGER TO FIRE A NUMBER OF TIMES E"UAL TO THE NUMBER OF ROWS THAT SATISFY THE WHERE CLAUSE$ THAT IS$ THE NUMBER OF EMPLOYEES REPORTING TO DEPARTMENT )3.

CREATING STATE)ENT TRIGGERS: S"L4 CREATE OR REPLACE TRIGGER SECURE(EMP 2 BEFORE INSERT ON EMP ) BEGIN , IF (TO(CHAR(SYSDATE$CDYC) IN (CSATC$CSUNC)) OR . (TO(CHAR(SYSDATE$CHH2,C) NOT BETWEEN C32C AND C12C) / THEN RAISE(APPLICATION(ERROR (&23.33$ CYOU MAY ONLY INSERT INTO EMP

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0 DURING BUSINESS HOURSC)5 2 END IF5 END5 13 / T;NSS9; :;96<9=. INSERT IN TO E)P DURING NON OFFICE .OURS( S"L4 INSERT INTO EMP 2 (EMPNO$ENAME$DEPTNO) ) VALUES , (1$CPAVANC$,3)5 INSERT INTO EMP # ERROR 6< 8NK9 1% ORA&23.33% YOU MAY ONLY INSERT INTO EMP DURING BUSINESS HOURS ORA&3/.12% 6< OSCOTT.SECURE(EMPO$ 8NK9 , ORA&3,322% 9;;D; =?;NKS 9U9:?<NDK DT <;NSS9; CSCOTT.SECURE(EMPC INSERT IN TO E)P DURING OFFICE .OURS( S"L4 INSERT INTO EMP 2 (EMPNO$ENAME$DEPTNO) ) VALUES , (1$CPAVANC$,3)5 1 ;DE :;96<9=.

2)3

USING CONDITIONAL PREDICATES: 1 CREATE OR REPLACE TRIGGER SECURE(EMP1 2 BEFORE INSERT OR UPDATE OR DELETE ON EMP ) BEGIN , IF (TO(CHAR(SYSDATE$CDYC) IN (CSATC$CSUNC)) OR . (TO(CHAR(SYSDATE$CHH2,C) NOT BETWEEN C32C AND C12C)

/ THEN

0 IF DELETING 2 THEN RAISE(APPLICATION(ERROR (&23.32$ CYOU MAY ONLY DELETE FROM EMP DURING BUSINESS HOURSC)5

ELSIF INSERTING 13 THEN RAISE(APPLICATION(ERROR (&23.33$ CYOU MAY ONLY INSERT INTO EMP DURING BUSINESS HOURSC)5 11 ELSIF UPDATING (CSALC) 12 THEN RAISE(APPLICATION(ERROR (&23.3)$ CYOU MAY ONLY UPDATE SAL IN EMP DURING BUSINESS HOURSC)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1) ELSE 1, RAISE(APPLICATION(ERROR (&23.3,$ CYOU MAY ONLY UPDATE EMP DURING BUSINESS HOURSC)5 1. END IF5 1/ END IF5 10# END5 12 / T;NSS9; :;96<9=.

2)1

CREATING RO+ LE*EL TRIGGERS: USING OLD AND NE+ QUALIFIERS:

1 CREATE TABLE DEPT1 2 AS )# SELECT # FROM DEPT , / T6789 :;96<9=. 1 CREATE TABLE AUDIT(DEPT(TABLE 2 (USERNAME VARCHAR2(13)$ ) TODAYDATE TIMESTAMP$ , NEW(DEPTNO NUMBER(13)$

. OLD(DEPTNO NUMBER(13)$ / NEW(DNAME 0 OLD(DNAME 2 NEW(LOC # OLD(LOC S"L4 / T6789 :;96<9=. VARCHAR2(13)$ VARCHAR2(13)$ VARCHAR2(13)$ VARCHAR2(13))

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 CREATE OR REPLACE TRIGGER AUDIT(DEPT(VALUES 2 AFTER DELETE OR INSERT OR UPDATE ON DEPT1 ) FOR EACH ROW , BEGIN . INSERT INTO AUDIT(DEPT(TABLE / VALUES 0 (USER$SYSTIMESTAMP$%NEW.DEPTNO$%OLD.DEPTNO$%NEW.DNAME$%OLD.DNAME$ 2 %NEW.LOC$%OLD.LOC)5 # END5 S"L4 / T;NSS9; :;96<9=. DATA OPERATION. INSERT. UPDATE. DELETE. OLD VALUE. NULL. VALUE BEFORE UPDATE. VALUE BEFORE DELETE. NEW VALUE. INSERTED VALUE. VALUE AFTER UPDATE. NULL.

2)2

THE OLD AND NEW "UALIFIERS ARE ONLY AVAILABLEIN ROW TRIGGERS. PREFI! THESE "UALIFIERS WITH A COLON(%) IN EVERY S"L AND PL/S"L STATEMENT. DELETING: S"L4 DELETE FROM DEPT1 2 WHERE DEPTNOI135 1 ;DE =989<9=. S"L4 SELECT # FROM AUDIT(DEPT(TABLE5 USERNAME TIMESTAMP NEW(DEPTNO OLD(DEPTNO NEW(DNAME OLD(DNAME NEW(LOC &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& SCOTT 3 &JUN&3. 13 ACCOUNTING INSERTING: S"L4 INSERT INTO DEPT1 2 VALUES ) (.3$CCOMPUTERSC$CNEW YOR'C)5 1 ;DE :;96<9=. S"L4 SELECT # FROM AUDIT(DEPT(TABLE5 USERNAME TIMESTAMP NEW(DEPTNO OLD(DEPTNO NEW(DNAME OLD(DNAME NEW(LOC OLD(LOC &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& SCOTT 3 &JUN&3. 13 ACCOUNTING NEW YOR' SCOTT 3 &JUN&3. .3 COMPUTERS NEW YOR' OLD(LOC NEW YOR'

UPDATING WITH WHERE CLAUSE% S"L4 UPDATE DEPT1

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 SET DNAMEICPAVANC ) WHERE DEPTNOI.35 1 ;DE ?B=6<9=. S"L4 SELECT # FROM AUDIT(DEPT(TABLE5 USERNAME TIMESTAMP NEW(DEPTNO OLD(DEPTNO NEW(DNAME OLD(DNAME NEW(LOC &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& SCOTT 3 &JUN&3. 13 ACCOUNTING SCOTT SCOTT 3 &JUN&3. 3 &JUN&3. .3 .3 .3 COMPUTERS PAVAN OLD(LOC NEW YOR' NEW YOR'

2))

COMPUTERS NEW YOR' NEW YOR'

UPDATING +IT.OUT +.ERE CLAUSE: S"L4 UPDATE DEPT1 2 SET DEPTNOI15 , ;DEF ?B=6<9=. S"L4 SELECT # FROM AUDIT(DEPT(TABLE5 USERNAME TIMESTAMP NEW(DT OLD(DT NEW(DNAME OLD(DNAME NEW(LOC &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& SCOTT 3 &JUN&3. 13 ACCOUNTING NEW YOR' SCOTT SCOTT SCOTT SCOTT SCOTT SCOTT 3 &JUN&3. 3 &JUN&3. 3 &JUN&3. 3 &JUN&3. 3 &JUN&3. 3 &JUN&3. .3 .3 1 1 1 1 .3 23 )3 ,3 .3 COMPUTERS PAVAN RESEARCH SALES NEW YOR' COMPUTERS NEW YOR' NEW YOR' RESEARCH SALES DALLAS CHICAGO DALLAS CHICAGO BOSTON OLD(LOC

OPERATIONS OPERATIONS BOSTON PAVAN PAVAN

NEW YOR' NEW YOR'

0 ;DEF F989:<9=.

PROCEDURE *S TRIGGERS: TRIGGER DEFINED WITH CREATE TRIGGER. DATA DICTIONARY CONTAINS SOURCE CODE. IMPLICITLY INVO'ED. PROCEDURE DEFINED WITH CREATE PROCEDURE. DATA DICTIONARY CONTAINS SOURCE CODE. E!PLICTLY INVO'ED.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
COMMIT$SAVEPOINT$ROLL BAC' ARE NOT ALLOWED. COMMIT$SAVEPOINT$ROLL BAC' ARE ALLOWED. USER2TRIGGERS FOR SOURCE CODE: S"L4 DESC USER(TRIGGERS5 NAME NULL@ TYPE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TRIGGER(NAME VARCHAR2()3) TRIGGER(TYPE VARCHAR2(1/) TRIGGERING(EVENT VARCHAR2(220) TABLE(OWNER VARCHAR2()3) BASE(OBJECT(TYPE VARCHAR2(1/) TABLE(NAME VARCHAR2()3) COLUMN(NAME VARCHAR2(,333) REFERENCING(NAMES VARCHAR2(122) WHEN(CLAUSE VARCHAR2(,333) STATUS VARCHAR2(2) DESCRIPTION VARCHAR2(,333) ACTION(TYPE VARCHAR2(11) TRIGGER(BODY LONG

2),

S"L4 SELECT TRIGGER(NAME$TRIGGER(BODY FROM USER(TRIGGERS5 TRIGGER(NAME TRIGGER(BODY &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& SECURE(EMP BEGIN IF (TO(CHAR(SYSDATE$CDYC) IN (CSATC$CSUNC)) OR (TO(CHAR(SYSDATE$CHH2,C

SELECTTRIGGER(NAME$TRIGGER(TYPE$TRIGGERING(EVENT$ TRIGGER(BODY FROM USER(TRIGGERS5 TRIGGER(NAME TRIGGER(TYPE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& TRIGGERING(EVENT &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TRIGGER(BODY &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& SECURE(EMP BEFORE STATEMENT INSERT BEGIN IF (TO(CHAR(SYSDATE$CDYC) IN (CSATC$CSUNC)) OR (TO(CHAR(SYSDATE$CHH2,C DISABLE OR REENABLE A CL DATABASE TRIGGER: ALTER TRIGGER TRIGGER(NAME DISABLE/ENABLE. DISABLE OR REENABLE ALL TRIGGERS FOR A TABLE: ALTER TABLE TABLE(NAME DISABLE/ENABLE ALL TRIGGERS. RECO)IPLE A TRIGGER FOR A TABLE: ALTER TRIGGER TRIGGER2NA)E CO)PILE( CREATNG DATABASE TRIGGERS: TRIGGERING USER E*ENT:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CREATE $ ALTER OR DROP LOGGING ON OR OFF

2).

TRIGGERING DATABASE OR SYSTE) E*ENT: DATA BASE SHUTTING DOWN OR STARTING UP. A SPECIFIC ERROR OR ANY ERROR BEING RAISED.

CREATE: S"L4 CREATE TABLE DDL(CREATIONS 2 (USER(ID VARCHAR2(13)$ ) OBJECT(TYPE VARCHAR2()3)$ , OBJECT(NAME VARCHAR2()3)$ . OBJECT(OWNER VARCHAR2(23)$ / CREATIONDATE TIMESTAMP(.))5 T6789 :;96<9=. S"L4 CREATE OR REPLACE TRIGGER LOGCREATIONS 2 AFTER CREATE ON SCHEMA ) BEGIN , INSERT INTO DDL(CREATIONS . VALUES / (USER$SYS.DICTIONARY(OBJ(TYPE$SYS.DICTIONARY(OBJ(NAME$ 0 SYS.DICTIONARY(OBJ(OWNER$SYSTIMESTAMP)5 2 END5 / T;NSS9; :;96<9=.

1 CREATE TABLE BALAJI11

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2# (EMPNO NUMBER(13)) S"L4 / T6789 :;96<9=. S"L4 SELECT # FROM DDL(CREATIONS5 USER(ID OBJECT(TYPE OBJECT(NAME OBJECT(OWNER &&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&& CREATIONDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& SCOTT TABLE BALAJI11 SCOTT 1.&JUN&3. 12.3).2,.33333 AM DROP: S"L4 CREATE OR REPLACE TRIGGER PREVENT(DROP 2 BEFORE DROP ON SCOTT.SCHEMA ) BEGIN , IF ORA(DICT(OBJ(OWNERICSCOTTC . AND ORA(DICT(OBJ(TYPE ICTABLEC / THEN RAISE(APPLICATION(ERROR 0 (&23332$COPERATION NOT PERMITTEDC)5 2 END IF5 END5 13 / T;NSS9; :;96<9=. S"L4 DROP TABLE EMP1335 DROP TABLE EMP133 # ERROR 6< 8NK9 1% ORA&33/3,% 9;;D; D::?;;9= 6< ;9:?;FNQ9 S"L 89Q98 1 ORA&23332% OPERATION NOT PERMITTED ORA&3/.12% 6< 8NK9 ,

2)/

S"L4 CREATE OR REPLACE TRIGGER PREVENT(DROP1 2 BEFORE DROP ON SCOTT.SCHEMA ) BEGIN , IF ORA(DICT(OBJ(OWNERICSCOTTC . AND ORA(DICT(OBJ(NAME LI'E CE-C / AND ORA(DICT(OBJ(TYPE ICTABLEC 0 THEN RAISE(APPLICATION(ERROR 2 (&23332$COPERATION NOT PERMITTED TABLES BEGINING WITH E LETTERC)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
END IF5 13 END5 11 / T;NSS9; :;96<9=. S"L4 DROP TABLE EMP1335 DROP TABLE EMP133 # ERROR 6< 8NK9 1% ORA&33/3,% 9;;D; D::?;;9= 6< ;9:?;FNQ9 S"L 89Q98 1 ORA&23332% OPERATION NOT PERMITTED TABLES BEGINING WITH E LETTER ORA&3/.12% 6< 8NK9 .

2)0

LOGGING AND LOGOFF ON SC.E)A: 1 CREATE TABLE LOG(TRIG(TABLE 2 (USER(ID VARCHAR2(13)$ ) LOG(DATE DATE$ ,# ACTION S"L4 / T6789 :;96<9=. 1 CREATE OR REPLACE TRIGGER LOGON(TRIG 2 AFTER LOGON ON SCHEMA ) BEGIN , INSERT INTO LOG(TRIG(TABLE/ . VALUES / (USER$SYSDATE$CLOGGGING ONC)5 0# END5 S"L4 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER LOGOFF(TRIG 2 BEFORE LOGOFF ON SCHEMA ) BEGIN , INSERT INTO LOG(TRIG(TABLE . VALUES / (USER$SYSDATE$CLOGGGING OFFC)5 0# END5 S"L4 / VARCHAR2(13))

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
T;NSS9; :;96<9=. LOGGING AND LOGOFF ON DATABASE: 1 CREATE TABLE LOG(TRIG(TABLE1 2 (USER(ID VARCHAR2(23)$ ) DATETIME TIMESTAMP(.)$ ,# ACTION S"L4 / T6789 :;96<9=. VARCHAR2(23))

2)2

1 CREATE OR REPLACE TRIGGER LOGOFF(TRIG1 2 BEFORE LOGOFF ON DATABASE ) BEGIN , INSERT INTO LOG(TRIG(TABLE1 . VALUES / (USER$SYSTIMESTAMP$CLOGGGING OFFC)5 0# END5 S"L4 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER LOGON(TRIG1 2 AFTER LOGON ON DATABASE ) BEGIN , INSERT INTO LOG(TRIG(TABLE1 . VALUES / (USER$SYSTIMESTAMP$CLOGGGING ONC)5 0# END5 S"L4 / T;NSS9; :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE

2)

STARTUP AND S.UTDO+N OF DATABASE: CREATE TABLE START(SHUT(DBASE (DATETIME TIMESTAMP(.))5 T6789 :;96<9=. S"L4 CREATE OR REPLACE TRIGGER DATABASE(UP 2 AFTER STARTUP ) ON DATABASE , BEGIN . INSERT INTO / START(SHUT(DBASE 0 VALUES 2 (SYSTIMESTAMP)5 END5 13 / T;NSS9; :;96<9=. S"L4 CREATE OR REPLACE TRIGGER DATABASE(SHUTDOWN 2 BEFORE SHUTDOWN ) ON DATABASE , BEGIN . INSERT INTO / START(SHUT(DBASE 0 VALUES 2 (SYSTIMESTAMP)5 END5 13 / T;NSS9; :;96<9=.

A SPECIFIC ERROR OR ANY ERROR:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 CREATE TABLE ERROR(LOG 2 (DATETIME TIMESTAMP(.)$ ) USER(ID , INSTANCE VARCHAR2(23)$ NUMBER$ . DATABASE(NAME VARCHAR2(133)$ /# ERROR(STAC' VARCHAR2(2333)) S"L4 / T6789 :;96<9=. 1 CREATE OR REPLACE TRIGGER LOGERROS 2 AFTER SERVERERROR ON DATABASE ) BEGIN , INSERT INTO ERROR(LOG . VALUES / (SYSTIMESTAMP$SYS.LOGIN(USER$SYS.INSTANCE(NUM$ 0 SYS.DATABASE(NAME$DBMS(UTILITY.FORMAT(ERROR(STAC')5 2# END5 S"L4 / T;NSS9; :;96<9=. S"L4 SELECT # FORM EMP5 SELECT # FORM EMP # ERROR 6< 8NK9 1% ORA&33 2)% FROM L9AED;= KD< TD?K= ER9;9 9UB9:<9= S"L4 SELECT # FROM DDDDDD5 SELECT # FROM DDDDDD # ERROR 6< 8NK9 1% ORA&33 ,2% <6789 D; QN9E =D9F KD< 9UNF< S"L4 BEGIN 2 INSERT INTO LLL VALUES (1)5 ) END5 , / INSERT INTO LLL VALUES (1)5 # ERROR 6< 8NK9 2% ORA&3/..3% 8NK9 2$ :D8?>K 1)% PL/S"L% ORA&33 ,2% <6789 D; QN9E =D9F KD< 9UNF< ORA&3/..3% 8NK9 2$ :D8?>K 1% PL/S"L% S"L S<6<9>9K< NSKD;9= S"L4 BEGIN 2 DELETE FROM DDDD5

2,3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) , / BEGIN # ERROR 6< 8NK9 1% ORA&3/..3% 8NK9 )$ :D8?>K 3% PLS&3313)% EK:D?K<9;9= <R9 FA>7D8 O9K=&DT&TN89O ER9K 9UB9:<NKS DK9 DT <R9 TD88DENKS% 79SNK :6F9 =9:86;9 9K= 9U:9B<NDK 9UN< TD; SD<D NT 8DDB >D= K?88 B;6S>6 ;6NF9 ;9<?;K F989:< ?B=6<9 ERN89 EN<R W6K N=9K<NTN9;4 W6 =D?789&P?D<9= =98N>N<9=&N=9K<NTN9;4 W6 7NK= Q6;N67894 WW :8DF9 :?;;9K< =989<9 T9<:R 8D:L NKF9;< DB9K ;D8876:L F6Q9BDNK< F9< FP8 9U9:?<9 :D>>N< TD;688 >9;S9 W6 FNKS89&P?D<9= S"L F<;NKS4 BNB9 S"L4 SELECT # FROM ERROR(LOG5 DATETIME USER(ID INSTANCE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&& &&&&&&&&&& DATABASE(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ERROR(STAC' &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 1.&JUN&3. 12.3 .2..33333 AM SCOTT 1 ORCL.US.ORACLE.COM ORA&33 2)% FROM L9AED;= KD< TD?K= ER9;9 9UB9:<9= 1.&JUN&3. 12.3 .)..33333 AM ORCL.US.ORACLE.COM ORA&33 ,2% <6789 D; QN9E =D9F KD< 9UNF< 1.&JUN&3. 12.3 ..,.33333 AM ORCL.US.ORACLE.COM ORA&3/..3% 8NK9 2$ :D8?>K 1)% PL/S"L% ORA&33 ,2% <6789 D; QN9E =D9F KD< 9UNF< ORA&3/..3% 8NK9 2$ :D8?>K 1% PL/S"L% S"L S<6<9>9K< NSKD;9= SCOTT 1

2,1

SCOTT

1.&JUN&3. 12.13.22.33333 AM SCOTT 1 ORCL.US.ORACLE.COM ORA&3/..3% 8NK9 )$ :D8?>K 3% PLS&3313)% EK:D?K<9;9= <R9 FA>7D8 O9K=&DT&TN89O ER9K 9UB9:<NKS DK9 DT <R9 TD88DENKS% 79SNK :6F9 =9:86;9 9K= 9U:9B<NDK 9UN< TD; SD<D NT 8DDB >D= K?88 B;6S>6 ;6NF9 ;9<?;K F989:< ?B=6<9 ERN89 EN<R W6K N=9K<NTN9;4 W6 =D?789&P?D<9= =98N>N<9=&N=9K<NTN9;4 W6 7NK= Q6;N67894 WW :8DF9 :?;;9K< =989<9 T9<:R 8D:L NKF9;< DB9K ;D8876:L F6Q9BDNK< F9< FP8 9U9:?<9 :D>>N< TD;688 >9;S9 W6 FNKS89&P?D<9= S"L F<;NKS4 BNB9 RESTRICTING A RO+ TRIGGER +IT. +.EN CLAUSE:

S"L4 CREATE TABLE WHEN(MANAGER 2 (ACTION VARCHAR2(13)$ ) DATETIME TIMESTAMP(.))5 T6789 :;96<9=. 1 CREATE OR REPLACE TRIGGER WHEN(JOB 2 BEFORE INSERT ON EMP ) FOR EACH ROW

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
, WHEN (NEW.JOBICMANAGERC) . BEGIN / INSERT INTO WHEN(MANAGER 0 VALUES 2 (CMANAGERC$SYSTIMESTAMP)5 # END5 S"L4 / T;NSS9; :;96<9=.

2,2

S"L4 INSERT INTO EMP 2 VALUES ) (1$CPAVANC$CMAANGERC$12$C31&DEC&21C$1333$133$13)5 1 ;DE :;96<9=. 1 INSERT INTO EMP 2 VALUES )# (2$CPAVANC$CMANAGERC$12$C31&DEC&21C$1333$133$13) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO EMP 2 VALUES )# ()$C'UMARC$CMANAGERC$12$C31&DEC&21C$1333$133$13) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT # FROM WHEN(MANAGER5 ACTION DATETIME &&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& MANAGER 1.&JUN&3. 12.23....33333 AM MANAGER 1.&JUN&3. 12.21.3 .33333 AM 1 INSERT INTO EMP 2 VALUES )# (,$C'UMARC$CGERC$12$C31&DEC&21C$1333$133$13) S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 ;DE :;96<9=. S"L4 SELECT # FROM WHEN(MANAGER5 ACTION DATETIME &&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& MANAGER 1.&JUN&3. 12.23....33333 AM MANAGER 1.&JUN&3. 12.21.3 .33333 AM

2,)

1 INSERT INTO EMP 2 VALUES )# (.$CMANAGERC$CMANAGERC$12$C31&DEC&21C$1333$133$13) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT # FROM WHEN(MANAGER5 ACTION DATETIME &&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& MANAGER 1.&JUN&3. 12.23....33333 AM MANAGER 1.&JUN&3. 12.21.3 .33333 AM MANAGER 1.&JUN&3. 12.22..1.33333 AM CALLING A PROCEDURE FRO) TRIGGER: 1 CREATE TABLE LOG(TABLE 2 (USER VARCHAR2(13)$ )# TDATE S"L4 / T6789 :;96<9=. TIMESTAMP)

S"L4 CREATE OR REPLACE PROCEDURE CALL(TRIGGER 2 AS ) BEGIN , INSERT INTO LOG(TABLE . VALUES / (USER$SYSTIMESTAMP)5 0 END5 2 / P;D:9=?;9 :;96<9=.

1 CREATE OR REPLACE TRIGGER CALL(PROC

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 BEFORE INSERT ON EMP )# CALL CALL(TRIGGER S"L4 / T;NSS9; :;96<9=. S"L4 SELECT # FROM LOG(TABLE5 KD ;DEF F989:<9= 1 INSERT INTO EMP 2 (EMPNO$DEPTNO) ) VALUES ,# (/$13) S"L4 / 1 ;DE :;96<9=.

2,,

S"L4 SELECT # FROM LOG(TABLE5 US D &&&&&&&&&& &&&&&&&&& SCOTT 1.&JUN&3. CREATING PAC'AGES% WE USE PAC'AGES TO GROUP LOGICALLY RELATED PL/S"L TYPES$SUBPROGRAMS. PAC'AGE CONSISTS OF PAC'AGE SPECIFICATION AND PAC'AGE BODY. PAC'AGE SPECIFICATION CONTAINS DECLARATIONS OF ALL LOGICALLY RELATED ITEMS. PAC'AGE BODY CONTAINS BODY FOR ALL WHAT ALL WE DECLARED IN THE PAC'AGE SPECIFICATION.

CREATING PAC-AGE SPECIFICATION: 1 CREATE OR REPLACE PAC'AGE HANUMAN IS 2 G(SAL NUMBER5 ) PROCEDURE FIND(SAL , (V(EMPNO IN NUMBER)5 .# END5 / / P6:L6S9 :;96<9=.

CREATING PAC-AGE BODY: 1 CREATE OR REPLACE PAC'AGE BODY HANUMAN IS 2 FUNCTION FINDFUN(SAL

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) (V(EMPNO IN NUMBER) , RETURN NUMBER IS . V(SAL NUMBER(13)5 / BEGIN 0 SELECT SAL INTO V(SAL FROM EMP 2 WHERE EMPNO I V(EMPNO5 RETURN V(SAL5 13 END5 11 PROCEDURE FIND(SAL 12 (V(EMPNO IN NUMBER) 1) IS 1, BEGIN 1. G(SAL%IFINDFUN(SAL(V(EMPNO)5 1/ DBMS(OUTPUT.PUT(LINE(G(SAL)5 10 END5 12# END5 S"L4 / P6:L6S9 7D=A :;96<9=.

2,.

S"L4 E!ECUTE HANUMAN.FIND(SAL(0)/ ) PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON S"L4 E!ECUTE HANUMAN.FIND(SAL(0)/ ) 233 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DECLARING GLOBAL2*ARIABLES IN A PAC-AGE:

S"L4 CREATE OR REPLACE PAC'AGE GOLBAL(VARS IS 2 V(EMPNO CONSTANT NUMBER%I0)/ 5

) V(DEPTNO CONSTANT NUMBER%I135 , END5 . / P6:L6S9 :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 CREATE OR REPLACE PROCEDURE GLOBALFIND(SAL 2 IS ) V(SAL NUMBER(13)5 , BEGIN . SELECT SAL INTO V(SAL FROM EMP / WHERE EMPNOIGOLBAL(VARS.V(EMPNO5 0 DBMS(OUTPUT.PUT(LINE(V(SAL)5 2# END5 S"L4 / P;D:9=?;9 :;96<9=.

2,/

S"L4 E!ECUTE GLOBALFIND(SAL5 233 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

O*ERLOADING IN PAC-AGES: 1 CREATE OR REPLACE PAC'AGE OVERLOAD(DEPT IS 2 PROCEDURE ADD(DEPT ) (V(DEPTNO IN DEPT.DEPTNO-TYPE)5 , PROCEDURE ADD(DEPT . (V(DEPTNO IN DEPT.DEPTNO-TYPE$ / V(DNAME IN DEPT.DNAME-TYPE)5 0 PROCEDURE ADD(DEPT 2 (V(DEPTNO IN DEPT.DEPTNO-TYPE$ V(DNAME IN DEPT.DNAME-TYPE$ 13 V(LOC IN DEPT.LOC-TYPE)5 11# END5 S"L4 / P6:L6S9 :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE

2,0

1 CREATE OR REPLACE PAC'AGE BODY OVERLOAD(DEPT IS 2 PROCEDURE ADD(DEPT ) (V(DEPTNO IN DEPT.DEPTNO-TYPE) , IS . BEGIN / INSERT INTO DEPT 0 (DEPTNO) 2 VALUES (V(DEPTNO)5 13 END5 11 PROCEDURE ADD(DEPT 12 (V(DEPTNO IN DEPT.DEPTNO-TYPE$ 1) V(DNAME IN DEPT.DNAME-TYPE) 1, IS 1. BEGIN 1/ INSERT INTO DEPT 10 (DEPTNO$DNAME) 12 VALUES 1 (V(DEPTNO$V(DNAME)5

23 END5 21 PROCEDURE ADD(DEPT 22 (V(DEPTNO IN DEPT.DEPTNO-TYPE$ 2) V(DNAME IN DEPT.DNAME-TYPE$ 2, V(LOC IN DEPT.LOC-TYPE) 2. IS 2/ BEGIN 20 INSERT INTO DEPT 22 (DEPTNO$DNAME$LOC)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 VALUES )3 (V(DEPTNO$V(DNAME$V(LOC)5 )1 END5 )2# END5 )) / P6:L6S9 7D=A :;96<9=. S"L4 E!ECUTE OVERLOAD(DEPT.ADD(DEPT(.3)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 E!ECUTE OVERLOAD(DEPT.ADD(DEPT(/3$CCOMPUTERSC)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 E!ECUTE OVERLOAD(DEPT.ADD(DEPT(03$CIPC$CLONDONC)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT # FROM DEPT5 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 ACCOUNTING NEW YOR' 23 RESEARCH DALLAS )3 SALES CHICAGO ,3 OPERATIONS BOSTON .3 /3 COMPUTERS 03 IP LONDON 0 ;DEF F989:<9=.

2,2

CREATING TYPES: S"L4 CREATE TYPE ADDRESS(TY AS OBJECT 2 (STREET VARCHAR2(13)$ ) CITY VARCHAR2(13)$ , STATE VARCHAR2(13)$ . ZIP NUMBER)5 / / TAB9 :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 CREATE TYPE PERSON(TY AS OBJECT 2 (NAME VARCHAR2(13)$ ) ADDRESS ADDRESS(TY)5 , / TYPE CREATED( S"L4 CREATE TABLE CUSTOMER 2 (CUSTOMER(ID NUMBER$ ) PERSON PERSON(TY)5 T6789 :;96<9=.

2,

S"L4 DESC CUSTOMER N6>9 N?88@ &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/ &&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CUSTOMER(ID PERSON TAB9

NUMBER PERSON(TY

S"L4 DESC PERSON(TY N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& NAME VARCHAR2(13) ADDRESS ADDRESS(TY

S"L4 DESC ADDRESS(TY N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STREET VARCHAR2(13) CITY VARCHAR2(13) STATE VARCHAR2(13) ZIP NUMBER

T.E USER2TAB2COLU)NS DATA DICTIONARY *IE+ CAN BE QUERIED TO SEE T.E DATA TYPE ASSOCIATED +IT. EAC. COLU)N IN T.E CUSTO)ER TABLE( S"L4 SELECT COLUMN(NAME$DATA(TYPE FROM USER(TAB(COLUMNS 2 WHERE TABLE(NAME I CCUSTOMERC5

COLUMN(NAME

DATA(TYPE

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CUSTOMER(ID PERSON NUMBER PERSON(TY SELECT ATTR(NAME$LENGTH$ATTR(TYPE(NAME FROM USER(TYPE(ATTRS WHERE TYPE(NAME I CPERSON(TYC5 S"L4 /

2.3

IN THE FOLLOWING "UERY $ THE NAME$ LENGTH$ AND DATA TYPE ARE SELECTED FOR EACH OF THE ATTRIBUTES WITHIN THE PWESON(TY DATATYPE.

ATTR(NAME LENGTH ATTR(TYPE(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& NAME 13 VARCHAR2 ADDRESS ADDRESS(TY

QUERY USER2TYPE2ATTRS AGAIN TO SEE T.E ATTRIBUTES OF T.E ADDRESS2TY DATATYPE( SELECT ATTR(NAME$LENGTH$ATTR(TYPE(NAME FROM USER(TYPE(ATTRS WHERE TYPE(NAME I CADDRESS(TYC5 S"L4 / ATTR(NAME LENGTH ATTR(TYPE(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STREET 13 VARCHAR2 CITY 13 VARCHAR2 STATE 13 VARCHAR2 ZIP NUMBER INSERTING RECORDS IN TO T.E CUSTO)ER TABLE:

1 INSERT INTO CUSTOMER VALUES 2# (1$PERSON(TY(CPAVANC$ADDRESS(TY(CRAMNAGARC$CHYDC$CA.PC$.333,,))) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO CUSTOMER VALUES 2# (2$PERSON(TY(CGAYATRIC$ADDRESS(TY(CRAMNAGARC$CHYDC$CA.PC$.333,,))) ) / 1 ;DE :;96<9=.

1 INSERT INTO CUSTOMER VALUES 2# ()$PERSON(TY(CGAYATRIJIC$ADDRESS(TY(CRAMNAGARC$CHYDC$CA.PC$.333,,))) S"L4 / 1 ;DE :;96<9=. S"L4 DESC CUSTOMER N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CUSTOMER(ID NUMBER PERSON PERSON(TY

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECTING RECORDS IN TO T.E CUSTO)ER TABLE:

2.1

S"L4 SELECT # FROM CUSTOMER5 CUSTOMER(ID &&&&&&&&&&& PERSON(NAME$ ADDRESS(STREET$ CITY$ STATE$ ZIP)) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 1 PERSON(TY(CPAVANC$ ADDRESS(TY(CRAMNAGARC$ CHYDC$ CA.PC$ .333,,)) 2 PERSON(TY(CGAYATRIC$ ADDRESS(TY(CRAMNAGARC$ CHYDC$ CA.PC$ .333,,)) ) PERSON(TY(CGAYATRIJIC$ ADDRESS(TY(CRAMNAGARC$ CHYDC$ CA.PC$ .333,,)) S"L4 SELECT CUSTOMER(ID FROM CUSTOMER5 CUSTOMER(ID &&&&&&&&&&& 1 2 )

S"L4 SELECT CUSTOMER(ID$CLIENT.PERSON.NAME FROM CUSTOMER CLIENT5 CUSTOMER(ID PERSON.NAM &&&&&&&&&&& &&&&&&&&&& 1 PAVAN 2 GAYATRI ) GAYATRIJI S"L4 DESC CUSTOMER N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CUSTOMER(ID NUMBER PERSON PERSON(TY S"L4 DESC PERSON(TY N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& NAME VARCHAR2(13) ADDRESS ADDRESS(TY

S"L4 DESC ADDRESS(TY N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STREET VARCHAR2(13) CITY VARCHAR2(13) STATE VARCHAR2(13) ZIP NUMBER

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
UPDATING RECORDS IN TO T.E CUSTO)ER TABLE: 1 SELECT CUSTOMER(ID$CLIENT.PERSON.NAME$ 2# CLIENT.PERSON.ADDRESS.CITY FROM CUSTOMER CLIENT. S"L4 / CUSTOMER(ID PERSON.NAM PERSON.ADD &&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 1 PAVAN HYD 2 GAYATRI HYD ) GAYATRIJI HYD S"L4 UPDATE CUSTOMER CLIENT 2 SET CLIENT.PERSON.ADDRESS.CITYICNEW YOR'C ) WHERE CLIENT.PERSON.NAMEICGAYATRIJIC5 1 ;DE ?B=6<9=. S"L4 SELECT CUSTOMER(ID$CLIENT.PERSON.NAME$ 2 CLIENT.PERSON.ADDRESS.CITY FROM CUSTOMER CLIENT5 CUSTOMER(ID PERSON.NAM PERSON.ADD &&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 1 PAVAN HYD 2 GAYATRI HYD ) GAYATRIJI NEW YOR'

2.2

DELETING RECORDS IN TO T.E CUSTO)ER TABLE:

S"L4 DELETE FROM CUSTOMER CLIENT 2 WHERE CLIENT.PERSON.NAMEICPAVANC5 1 ROW DELETED. S"L4 SELECT CUSTOMER(ID$CLIENT.PERSON.NAME$ 2 CLIENT.PERSON.ADDRESS.CITY FROM CUSTOMER CLIENT5 CUSTOMER(ID PERSON.NAM PERSON.ADD &&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 2 GAYATRI HYD ) GAYATRIJI NEW YOR' OBJECT *IE+S:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
WHAT IF TABLES ALREADY E!IST@

2.)

WHAT IF A RELATIONAL DATABASE APPLICATION IS ALREADY CREATED AND E!ISTING AND OBJECT&RELATIONAL CONCEPTS ARE TO BE IMPLEMENTED IN THE APPLICATION WITHOUT REBUILDING AND RECREATING THE ENTIRE APPLICATION. THE NEED WOULD BE THE ABLITY TO OVELAY OBJECT&ORIENTED STRUCTURES$SUCH AS ABSTRACT DATATYPES ON E!ISTING RELATIONAL TABLES. ORACLE PROVIDES OBJECT&VIEWS AS A MEANS FOR DOING THIS. FOR CREATING OBJECT *IE+S BASED ON E/ISTING RELATIONAL TABLES"T.E ORDER OF OPERATION IS:

CREATE THE CUSTOMER TABLE.(RETATIONAL TYPE USING 2I/ I DATA TYPES) CREATE THE ADDRESS(TY DATATYPE. CREATE THE PERSON(TYPE DATA TYPE USING ADDRESS(TY DATATYPE. CREATE THE CUSTOMER(TY DATA TYPE USING PERSON(TY DATATYPE. CREATE THE CUSTOMER(OV OBJECT VIEW$USING THE DEFINED DATATYPES.

CREATE T.E CUSTO)ER TABLE((RETATIONAL TYPE USING 1I09I DATA TYPES): 1 CREATE TABLE CUSTOMER1 2 (CUSTOMER(ID NUMBER PRIMARY 'EY$ ) NAME , STREET . CITY / STATE 0# ZIP S"L4 / T6789 :;96<9=. CREATE T.E ADDRESS2TY DATATYPE: VARCHAR2(13)$ VARCHAR2(13)$ VARCHAR2(13)$ VARCHAR2(13)$ NUMBER(13))

1 CREATE OR REPLACE TYPE ADDRESS(TY1 AS OBJECT 2 (STREET ) CITY , STATE .# ZIP S"L4 / VARCHAR2(13)$ VARCHAR2(13)$ VARCHAR2(13)$ NUMBER(13))5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
TAB9 :;96<9=. CREATE T.E PERSON2TYPE DATA TYPE USING ADDRESS2TY DATATYPE: 1 CREATE OR REPLACE TYPE PERSON(TY1 AS OBJECT 2 (NAME VARCHAR2(13)$ )# ADDRESS ADDRESS(TY1)5 , / TAB9 :;96<9=.

2.,

CREATE T.E CUSTO)ER2TY DATA TYPE USING PERSON2TY DATATYPE: 1 CREATE OR REPLACE TYPE CUSTOMER(TY1 AS OBJECT 2 (CUSTOMER(ID NUMBER$ )# PERSON PERSON(TY)5 S"L4 / TAB9 :;96<9=. CREATE T.E CUSTO)ER2O* OBJECT *IE+"USING T.E DEFINED DATATYPES: S"L4 CREATE OR REPLACE VIEW CUSTOMER(VIEW 2 (CUSTOMER(ID$PERSON) ) AS , . / SELECT CUSTOMER(ID$PERSON(TY1 (NAME$ADDRESS(TY1(STREET$CITY$STATE$ZIP)) FROM CUSTOMER15

VN9E :;96<9=. S"L4 SELECT # FROM CUSTOMER(VIEW5 KD ;DEF F989:<9=

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
INSERTING *ALUES IN TO CUSTO)ER7 TABLE *IA TABLE: 1 INSERT INTO CUSTOMER1 2 VALUES )# (1$CPAVANC$CRAMNAGARC$CHYDC$CAPC$.333,,) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO CUSTOMER1 2 VALUES )# (2$CGAYATRIC$CRAMNAGARC$CHYDC$CAPC$.333,,) , / 1 ;DE :;96<9=. 1 INSERT INTO CUSTOMER1 2 VALUES )# ()$CGAYATRIJIC$CRAMNAGARC$CHYDC$CAPC$.333,,) S"L4 / 1 ;DE :;96<9=. SELECTING *ALUES T.ROUG. OBJECT *IE+S: S"L4 SELECT # FROM CUSTOMER(VIEW5 CUSTOMER(ID &&&&&&&&&&& PERSON(NAME$ ADDRESS(STREET$ CITY$ STATE$ ZIP)) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 1 PERSON(TY1(CPAVANC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,)) 2 PERSON(TY1(CGAYATRIC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,)) ) PERSON(TY1(CGAYATRIJIC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,))

2..

INSERTING *ALUES T.ROUG. OBJECT *IE+: 1 INSERT INTO CUSTOMER(VIEW 2 VALUES )# (,$PERSON(TY1(CGAYAANGELC$ ADDRESS(TY1(CRAMNAGARC$CHYDC$CAPC$.333,,))) S"L4 / 1 ;DE :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM CUSTOMER(VIEW5 CUSTOMER(ID &&&&&&&&&&& PERSON(NAME$ ADDRESS(STREET$ CITY$ STATE$ ZIP)) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 1 PERSON(TY1(CPAVANC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,)) 2 PERSON(TY1(CGAYATRIC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,)) ) PERSON(TY1(CGAYATRIJIC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,)) , PERSON(TY1(CGAYAANGELC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,))

2./

UPDATING TABLE *IA OBJECT *IE+: S"L4 UPDATE CUSTOMER(VIEW E 2 SET E.PERSON.ADDRESS.CITYICNEW YOR'C ) WHERE E.PERSON.NAMEICPAVANC5 1 ;DE ?B=6<9=. S"L4 SELECT # FROM CUSTOMER15 CUSTOMER(ID NAME STREET CITY STATE &&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 1 PAVAN RAMNAGAR NEW YOR' AP 2 GAYATRI RAMNAGAR HYD AP ) GAYATRIJI RAMNAGAR HYD AP , GAYAANGELRAMNAGAR HYD AP S"L4 SELECT # FROM CUSTOMER(VIEW5 CUSTOMER(ID &&&&&&&&&&& PERSON(NAME$ ADDRESS(STREET$ CITY$ STATE$ ZIP)) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 1 PERSON(TY1(CPAVANC$ ADDRESS(TY1(CRAMNAGARC$ CNEW YOR'C$ CAPC$ .333,,)) 2 PERSON(TY1(CGAYATRIC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,)) ) PERSON(TY1(CGAYATRIJIC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,)) , PERSON(TY1(CGAYAANGELC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,)) DELETING *ALUES T.ROUG. OBJECT2*IE+S: S"L4 DELETE FROM CUSTOMER(VIEW E 2 WHERE E.CUSTOMER(IDI15 1 ;DE =989<9=. S"L4 SELECT # FROM CUSTOMER(VIEW5 ZIP .333,, .333,, .333,, .333,,

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CUSTOMER(ID &&&&&&&&&&& PERSON(NAME$ ADDRESS(STREET$ CITY$ STATE$ ZIP)) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 2 PERSON(TY1(CGAYATRIC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,)) ) PERSON(TY1(CGAYATRIJIC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,)) , PERSON(TY1(CGAYAANGELC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,)) S"L4 DELETE FROM CUSTOMER(VIEW E 2 WHERE E.PERSON.NAMEICGAYAANGELC5 1 ;DE =989<9=. S"L4 SELECT # FROM CUSTOMER(VIEW5 CUSTOMER(ID &&&&&&&&&&& PERSON(NAME$ ADDRESS(STREET$ CITY$ STATE$ ZIP)) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 2 PERSON(TY1(CGAYATRIC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,)) ) PERSON(TY1(CGAYATRIJIC$ ADDRESS(TY1(CRAMNAGARC$ CHYDC$ CAPC$ .333,,)) S"L4 SELECT # FROM CUSTOMER15 CUSTOMER(ID NAME STREET CITY STATE ZIP &&&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 2 GAYATRI RAMNAGAR HYD AP .333,, ) GAYATRIJI RAMNAGAR HYD AP .333,, DB)S2OUTPUT PAC-AGE: S"L4 DECLARE 2 V(SAL NUMBER(13)5 ) BEGIN , SELECT SAL INTO V(SAL FROM EMP . WHERE EMPNOI+EMPNO5 / DBMS(OUTPUT.PUT(LINE(V(SAL)5 0 END5 2 / EK<9; Q68?9 TD; 9>BKD% 0)/ D8= .% WHERE EMPNOI+EMPNO5 K9E .% WHERE EMPNOI0)/ 5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON

2.0

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 / EK<9; Q68?9 TD; 9>BKD% 0)/ D8= .% WHERE EMPNOI+EMPNO5 K9E .% WHERE EMPNOI0)/ 5 233 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 BEGIN 2 DBMS(OUTPUT.DISABLE5 ) END5 , / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 DECLARE 2 V(SAL NUMBER(13)5 ) BEGIN , SELECT SAL INTO V(SAL FROM EMP . WHERE EMPNOI+EMPNO5 / DBMS(OUTPUT.PUT(LINE(V(SAL)5 0 END5 2 / EK<9; Q68?9 TD; 9>BKD% 0)/ D8= .% WHERE EMPNOI+EMPNO5 K9E .% WHERE EMPNOI0)/ 5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 BEGIN 2 DBMS(OUTPUT.ENABLE5 ) END5 , / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

2.2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 DECLARE 2 V(SAL NUMBER(13)5 ) BEGIN , SELECT SAL INTO V(SAL FROM EMP . WHERE EMPNOI+EMPNO5 / DBMS(OUTPUT.PUT(LINE(V(SAL)5 0 END5 2 / EK<9; Q68?9 TD; 9>BKD% 0)/ D8= .% WHERE EMPNOI+EMPNO5 K9E .% WHERE EMPNOI0)/ 5 233 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 BEGIN ) DBMS(OUTPUT.ENABLE(2333)5 , DBMS(OUTPUT.PUT(LINE(CTHREE NAMES WILL BE WRITTEN.C)5 . DBMS(OUTPUT.PUT(CPAVANC)5 / DBMS(OUTPUT.NEW(LINE5 0 DBMS(OUTPUT.PUT(CGAYATRIC)5 2 DBMS(OUTPUT.NEW(LINE5 DBMS(OUTPUT.PUT(CPRATHIMAC)5 13 DBMS(OUTPUT.NEW(LINE5 11# END5 12 /

2.

THREE NAMES WILL BE WRITTEN. PAVAN GAYATRI PRATHIMA PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

S"L4 SET SERVEROUTPUT OFF

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 BEGIN 2 DBMS(OUTPUT.ENABLE(2333)5 ) DBMS(OUTPUT.PUT(LINE(CTHREE NAMES WILL BE WRITTEN.C)5 , DBMS(OUTPUT.PUT(CPAVANC)5 . DBMS(OUTPUT.NEW(LINE5 / DBMS(OUTPUT.PUT(CGAYATRIC)5 0 DBMS(OUTPUT.NEW(LINE5 2 DBMS(OUTPUT.PUT(CPRATHIMAC)5 DBMS(OUTPUT.NEW(LINE5 13 END5 11 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON 1 DECLARE 2 THROW(AWAY VARCHAR2(.3)5 ) NAME1 VARCHAR2(13)5 , NAME2 VARCHAR2(13)5 . NAME) VARCHAR2(13)5 / STATUS NUMBER5 0 BEGIN 2 DBMS(OUTPUT.GET(LINE(THROW(AWAY$STATUS)5 DBMS(OUTPUT.GET(LINE(NAME1$STATUS)5 13 DBMS(OUTPUT.GET(LINE(NAME2$STATUS)5 11 DBMS(OUTPUT.GET(LINE(NAME)$STATUS)5 12 DBMS(OUTPUT.PUT(LINE(NAME1VVCANDCVVNAME2VVCANDCVVNAME))5 1)# END5 S"L4 / PAVAN AND GAYATRI AND PRATHIMA PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. UTL2FILE PAC-AGE: 1 DECLARE 2 FILE(HANDLE ) DATA(LINE , BEGIN UTL(FILE.FILE(TYPE5 VARCHAR2(133)5

2/3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
. FILE(HANDLE %IUTL(FILE.FOPEN(CC%ZPAVANC$CPAVAN.T!TC$CRC)5 / UTL(FILE.GET(LINE(FILE(HANDLE$DATA(LINE)5 0 DBMS(OUTPUT.PUT(LINE(DATA(LINE)5 2 UTL(FILE.GET(LINE(FILE(HANDLE$DATA(LINE)5 DBMS(OUTPUT.PUT(LINE(DATA(LINE)5 13 UTL(FILE.GET(LINE(FILE(HANDLE$DATA(LINE)5 11 DBMS(OUTPUT.PUT(LINE(DATA(LINE)5 12 UTL(FILE.FCLOSE(FILE(HANDLE)5 1)# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON S"L4 / GOD IS GREAT. PAVAN IS GOOD BOY. GAYATRI IS CUTE GIRL. PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 FILE(HANDLE UTL(FILE.FILE(TYPE5 ) DATA(LINE VARCHAR2(133)5 , BEGIN . FILE(HANDLE %IUTL(FILE.FOPEN(CC%ZPAVANC$C'UMAR.T!TC$CWC)5 / FOR V(EMP IN (SELECT EMPNO$ENAME$JOB FROM EMP) LOOP 0 UTL(FILE.PUT(LINE(FILE(HANDLE$TO(CHAR(V(EMP.EMPNO)VV 2 C$OC VV V(EMP.ENAME VVC$OCVVV(EMP.JOBVVCOC)5 END LOOP5 13 UTL(FILE.FCLOSE(FILE(HANDLE)5 11# END5 12 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

2/1

CREATION OF DIRECTORY:

S"L4 CREATE OR REPLACE DIRECTORY BALAJI AS CC%ZORACLEZHANUMANC5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DN;9:<D;A :;96<9=. DROPING DIRECTORY: S"L4 DROP DIRECTORY BALAJI5 DN;9:<D;A =;DBB9=.

2/2

CREATING E/TERNAL TABLE: CREATE TABLE OLDEMP (EMPNO NUMBER$ ENAME CHAR(23)$ JOB CHAR(23)) ORGANIZATION E!TERNAL (TYPE ORACLE(LOADER DEFAULT DIRECTORY BALAJI ACCESS PARAMETERS (RECORDS DELIMITED BY NEWLINE 13 BADFILE CBAD(EMPC 11 LOGFILE CLOG(EMPC 12 FIELDS TERMINATED BY C$C 1) (EMPNO CHAR$ 1, ENAME CHAR$ 1. JOB CHAR)) 1/ LOCATION (CE!T.T!TC)) 10 PARALLEL . 12# REJECT LIMIT 233 1 / T6789 :;96<9=. 1 2 ) , . / 0 2

S"L4 DESC OLDEMP N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER ENAME CHAR(23) JOB CHAR(23)

1 CREATE TABLE NEWEMP 2 (EMPNO NUMBER(13)$ ) ENAME VARCHAR2(23)$ ,# JOB VARCHAR2(23)) S"L4 / T6789 :;96<9=. S"L4 INSERT INTO NEWEMP 2 SELECT EMPNO$ENAME$JOB FROM OLDEMP5 , ;DEF :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM NEWEMP5 EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&& 13 PAVAN MANAGER 23 GAYATRI MANAGER )3 PRATHIMA MANAGER ,3 SRIDEVI MANAGER S"L4 SELECT # FROM OLDEMP5 EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&& 13 PAVAN MANAGER 23 GAYATRI MANAGER )3 PRATHIMA MANAGER ,3 SRIDEVI MANAGER S"L4 DESC OLDEMP N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER ENAME CHAR(23) JOB CHAR(23) N*L6: THE NVL2 FUNCTION E!AMINES THE FIRST E!PRESSION. IF THE FIRST E!PRESSION IS NOT NULL$THEN NVL2 FUNCTION RETURNS THE SECOND E!PRESSION. IF THE FIRST E!PRESSION IS NULL$THEN THE THIRD E!PRESSION IS RETURNED. S"L4 SELECT EMPNO$SAL$COMM$NVL2(COMM$CSALJCOMMC$CSALC) INCOME 2 FROM EMP5 EMPNO SAL COMM INCOME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&& 0)/ 233 SAL 0, 1/33 )33 SALJCOMM 0.21 12.3 .33 SALJCOMM 0.// 2 0. SAL 0/., 12.3 1,33 SALJCOMM 0/ 2 22.3 SAL 0022 2,.3 SAL 0022 )333 SAL 02) .333 SAL 02,, 1.33 3 SALJCOMM 020/ 1133 SAL 0 33 .3 SAL 0 32 )333 SAL 0 ), 1)33 SAL , ;DEF F989:<9=. S"L4 SELECT EMPNO$SAL$COMM$NVL2(COMM$SALJCOMM$SAL) INCOME 2 FROM EMP5 EMPNO SAL COMM INCOME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ 233 233 0, 1/33 )33 1 33 0.21 12.3 .33 10.3 0.// 2 0. 2 0. 0/., 12.3 1,33 2/.3 0/ 2 22.3 22.3 0022 2,.3 2,.3 0022 )333 )333 02) .333 .333

2/)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
02,, 020/ 0 33 0 32 0 ), 1.33 1133 .3 )333 1)33 3 1.33 1133 .3 )333 1)33 1, ;DEF F989:<9=. S"L4 SELECT EMPNO$SAL$COMM$SALJNVL(COMM$3) INCOME FROM EMP5 EMPNO SAL COMM INCOME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ 233 233 0, 1/33 )33 1 33 0.21 12.3 .33 10.3 0.// 2 0. 2 0. 0/., 12.3 1,33 2/.3 0/ 2 22.3 22.3 0022 2,.3 2,.3 0022 )333 )333 02) .333 .333 02,, 1.33 3 1.33 020/ 1133 1133 0 33 .3 .3 0 32 )333 )333 0 ), 1)33 1)33 1, ;DEF F989:<9=.

2/,

NULLIF: THE NULLIF FUNCTION COMPARES TWO E!PRESSIONS. IF THEY ARE E"UAL$THE FUNCTION RETURNS NULL. IF THEY ARE NOT E"UAL$THE FUNCTION RETURNS THE FIRST E!PRESSION. S"L4 SELECT ENAME$JOB FROM EMP5 ENAME JOB &&&&&&&&&& &&&&&&&&& SMITH CLER' ALLEN SALESMAN WARD SALESMAN JONES MANAGER MARTIN SALESMAN BLA'E MANAGER CLAR' MANAGER SCOTT ANALYST 'ING PRESIDENT TURNER SALESMAN ADAMS CLER' JAMES CLER' FORD ANALYST MILLER CLER' 1, ;DEF F989:<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 SELECT ENAME$ 2 LENGTH(ENAME) OE!PR1O$ ) LENGTH(JOB) OE!PR2O$ ,# NULLIF(LENGTH(ENAME)$LENGTH(JOB)) ORESULTO FROM EMP S"L4 / ENAME E!PR1 E!PR2 &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& SMITH . . ALLEN . 2 WARD , 2 JONES . 0 MARTIN / 2 BLA'E . 0 CLAR' . 0 SCOTT . 0 'ING , TURNER / 2 ADAMS . . JAMES . . FORD , 0 MILLER / . 1, ;DEF F989:<9=. COALESCE: THE COALESCE FUNCTION RETURNS THE FIRST NON&NULL E!PRESSION IN THE LIST. COALESCE(E!PR1$E!PR2$**E!PRN) IN SYNTA!% E!PR1 E!PR2 E!PRN RETURNS THIS E!PRESSION IF IT IS NOT NULL. RETURNS THIS E!PRESSION IF THE FIRST E!PRESSION IS NULL AND THIS E!PRESSION IS NOT NULL. RETURNS THIS E!PRESSION IF THE PRECEDING E!PRESSIONS ARE NULL. RESULT . , . / . . . , / , /

2/.

SELECT EMPNO$ENAME$COALESCE(COMM$SAL$13) COMM FROM EMP ORDER BY COMM5 EMPNO ENAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 02,, TURNER 0, ALLEN 0.21 WARD 0)/ SMITH 0 33 JAMES 020/ ADAMS 0 ), MILLER 0/., MARTIN 0022 CLAR' 0/ 2 BLA'E 0.// JONES 0022 SCOTT 0 32 FORD 02) 'ING 1, ;DEF F989:<9=. COMM 3 )33 .33 233 .3 1133 1)33 1,33 2,.3 22.3 2 0. )333 )333 .333

1 SELECT EMPNO$ENAME$SAL$COMM$COALESCE(COMM$SAL$13) OCOMMISSIONO FROM EMP 2# ORDER BY COMM S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMPNO ENAME SAL COMM COMMISSION &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 02,, TURNER 1.33 3 3 0, ALLEN 1/33 )33 )33 0.21 WARD 12.3 .33 .33 0/., MARTIN 12.3 1,33 1,33 0)/ SMITH 233 233 0.// JONES 2 0. 2 0. 0 33 JAMES .3 .3 0 ), MILLER 1)33 1)33 0 32 FORD )333 )333 020/ ADAMS 1133 1133 0/ 2 BLA'E 22.3 22.3 0022 CLAR' 2,.3 2,.3 0022 SCOTT )333 )333 02) 'ING .333 .333 1, ;DEF F989:<9=. S"L4 INSERT INTO EMP 2 VALUES ) (1$CPAVANC$CMANAGERC$0)/ $C31&DEC&3.C$NULL$NULL$13)5 1 ;DE :;96<9=. 1 INSERT INTO EMP 2 VALUES )# (2$C'UMARC$CMANAGERC$0)/ $C31&DEC&3.C$NULL$NULL$13) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT EMPNO$ENAME$SAL$COMM$COALESCE(COMM$SAL$13) OCOMMISSIONO FROM EMP 2 ORDER BY COMM5 EMPNO ENAME SAL COMM COMMISSION &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 02,, TURNER 1.33 3 3 0, ALLEN 1/33 )33 )33 0.21 WARD 12.3 .33 .33 0/., MARTIN 12.3 1,33 1,33 0)/ SMITH 233 233 0.// JONES 2 0. 2 0. 0 33 JAMES .3 .3 0 ), MILLER 1)33 1)33 2 'UMAR 13 1 PAVAN 13 0 32 FORD )333 )333 020/ ADAMS 1133 1133 0/ 2 BLA'E 22.3 22.3 0022 CLAR' 2,.3 2,.3 0022 SCOTT )333 )333 02) 'ING .333 .333 1/ ;DEF F989:<9=.

2//

CURSOR FOR UPDATE CLAUSE: YOU MAY WANT TO LOC' ROWS BEFORE UPDATE OR DELETE ROWS. ADD THE FOR UPDATE CLAUSE IN THE CURSOR "UERY TO LOC' THE AFFECTED ROWS WHEN THE CUSOR IS OPENED.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECT * FROM *.. FOR UPDATE [OF COLUMN(REFERENCE\ [NO WAIT\5 IN T.E SYNTA/:

2/0

COLUMN(REFERENCE % IS A COLUMN IN THE TABLE AGAINST WHICH THE "UERY IS PERFORMED.(A LIST OF COLUMNS MAY ALSO BE USED)5 NO WAIT% RETURNS AN ORACLE ERROR IF THE ROWS ARE LOC'ED BY ANOTHER SESSION. IF YOU WONT SPECIFY IT WAITS UNTILL THE LOC' RELEASES.

THIS IS USEFUL WHEN YOU WANT TO BASE AN UPDATE ON E!SITING VALUES IN A ROW. IN THAT CASE$YOU MUST MA'E SURE THE ROW IS NOT CHANGED BY ANOTHER USER BEFORE THE UPDATE. THE FOR UPDATE CLAUSE WILL BE THE LAST CLAUSE IN A SELECT STATEMENT EVEN AFTER ORDER BY. WHEN EVER YOU COMMIT OR ROLLBAC' LOC'S WILL BE RELEASED. DECLARE CUSSOR EMP(CURSOR IS SELECT # FROM EMP WHERE DEPTNOI13 FOR UPDATE OF SAL NOWAIT5

T.E +.ERE CURRENT OF CLAUSE: +.ERE CURRENT OF CURSOR? USE CURSORS TO UPDATE OR DELETE THE CURRENT ROW. INCLUDE THE FOR UPDATE CLAUSE IN THE CURSOR "UERY TO LOC' THE ROWS FIRST. USE THE WHERE CURRENT OF CLAUSE TO REFERENCE THE CURRENT ROW FROM AN E!PLICIT CURSOR. DECLARE CURSOR SAL(CURSOR IS SELECT # FROM EMP WHERE DEPTNO I13 FOR UPDATE OF SALARY NOWAIT5 BEGIN FOR EMP(RECORD IN SAL(CURSOR LOOP IF EMP(RECORD.SAL W .333 THEN UPDATE EMP SET SAL I EMP(RECORD.SAL#1.13 WHERE CURRENT OF SAL(CURSOR5 END IF5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
END LOOP5 END5 CREATING INDE/ES: AN INDE/: IS A SCHEMA OBJECT. IS USED BY THE ORACLE SERVER TO SPPED UP THE RETRIEVAL OF ROWS BY USING A POINTER. CAN REDUCE DIS' I/O BY USING A RAPID PATH ACCESS METHOD TO LOCATE DATA "UIC'LY. IS INDEPENDENT OF THE TABLE IT INDE!ES. IS USED AND MAINTAINED AUTOMATICALLY BY THE ORACLE SERVER.

2/2

AUTO)ATICALLY: A UN"UE INDE! IS CREATED AUTOMATICALLY WHEN YOU DEFINE A PRIMARY 'EY OR UNI"UE CONSTRAINT IN A TABLE DEFINITION. )ANUALLY: USER E!PLICITLY CAN CREATE INDE!ES FOR SPEED UP THE ACCESS TO THE ROWS.

CREATING NON%UNIQUE2INDE/: S"L4 CREATE INDE! EMP1(EMPNO(ID! 2 ON EMP1(EMPNO)5 IK=9U :;96<9=. S"L4 SELECT INDE!(NAME$INDE!(TYPE$TABLE(NAME$UNI"UENESS 2 FROM USER(INDE!ES5 INDE!(NAME INDE!(TYPE TABLE(NAME UNI"UENES &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&& EMP1(EMPNO(ID! NORMAL EMP1 NONUNI"UE P'(DEPT NORMAL DEPT UNI"UE P'(EMP ORMAL EMP UNI"UE CREATING UNIQUE2INDE/:

S"L4 CREATE UNI"UE INDE! DEPT1(DEPTNO(ID! 2 ON DEPT1(DEPTNO)5 IK=9U :;96<9=. S"L4 SELECT INDE!(NAME$INDE!(TYPE$TABLE(NAME$UNI"UENESS 2 FROM USER(INDE!ES5 INDE!(NAME INDE!(TYPE TABLE(NAME UNI"UENES &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&& DEPT1(DEPTNO(ID! NORMAL DEPT1 UNI"UE

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMP1(EMPNO(ID! P'(DEPT P'(EMP NORMAL EMP1 NORMAL DEPT NORMAL EMP NONUNI"UE UNI"UE UNI"UE

2/

CREATING CO)POSITE2INDE/: S"L4 CREATE INDE! EMP1(EMPNO(ENAME(ID! 2 ON EMP1(EMPNO$ENAME)5 IK=9U :;96<9=. S"L4 SELECT INDE!(NAME$INDE!(TYPE$TABLE(NAME$UNI"UENESS 2 FROM USER(INDE!ES5 INDE!(NAMEINDE!(TYPE TABLE(NAME UNI"UENES &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&& DEPT1(DEPTNO(ID! NORMAL DEPT1 UNI"UE EMP1(EMPNO(ENAME(ID! NORMAL EMP1 NONUNI"UE EMP1(EMPNO(ID! NORMAL EMP1 NONUNI"UE P'(DEPT NORMAL DEPT UNI"UE P'(EMP NORMAL EMP UNI"UE CREATING FUNCTIONBASED2INDE/: S"L4 CREATE INDE! DEPT1(FUNDNAME(ID! 2 ON DEPT1(UPPER(DNAME))5 IK=9U :;96<9=. S"L4 SELECT INDE!(NAME$INDE!(TYPE$TABLE(NAME$UNI"UENESS 2 FROM USER(INDE!ES5 CREATING BIT)AP2INDE/:

S"L4 CREATE BITMAP INDE! BITMAP(EMP1(JOB(ID! 2 ON EMP1(JOB)5 IK=9U :;96<9=.

SELECTING COLU)N NA)ES ON +.IC. INDE/ES CREATED: 1 SELECT UC.INDE!(NAME$UC.COLUMN(NAME$UI.UNI"UENESS 2 FROM USER(INDE!ES UI$USER(IND(COLUMNS UC

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) WHERE UI.INDE!(NAMEIUC.INDE!(NAME ,# AND UC.TABLE(NAME I CEMP1C S"L4 / INDE!(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& COLUMN(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& UNI"UENES &&&&&&&&& EMP1(EMPNO(ID! EMPNO NONUNI"UE EMP1(EMPNO(ENAME(ID! EMPNO NONUNI"UE EMP1(EMPNO(ENAME(ID! ENAME NONUNI"UE BITMAP(EMP1(JOB(ID! JOB NONUNI"UE RE)O*ING INDE/: DROP INDE/ INDE/2NA)E? +.EN TO CREATE AN INDE/: A COLUMN CONTAINS A WIDE RANGE OF VALUES. A COLUMN CONTAINS LARGE NUMBER OF NULL VALES. ONE OR MORE COLUMNS ARE FRE"UENTLY USED TOGETHER IN A WHERE CLAUSE.

203

+.EN TO NOT CREATE AN INDE/:

THE TABLE IS SMALL. THE COLUMNS ARE NOT OFTEN USED AS CONDITION IN THE "UERY. THE TABLE IS UPDATED FRE"UENTLY.

BREA- (SQL * PLUS CO))AND): TO SUPRESS DUPLICATES WE USE BREA' IN S"L PROMPT.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 BREA' ON JOB S"L4 SELECT # FROM EMP ORDER BY JOB5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 0 32 FORD 0.// 3)&DEC&21 )333 23 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 020/ ADAMS 0022 2)&MAY&20 1133 23 0 ), MILLER 0022 2)&JAN&22 1)33 13 0 33 JAMES 0/ 2 3)&DEC&21 .3 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0022 CLAR' 02) 3 &JUN&21 2,.3 13 0/ 2 BLA'E 02) 31&MAY&21 22.3 )3 02) 'ING PRESIDENT 10&NOV&21 .333 13 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0/., MARTIN 0/ 2 22&SEP&21 12.3 1,33 )3 02,, TURNER 0/ 2 32&SEP&21 1.33 3 )3 0.21 WARD 0/ 2 22&FEB&21 12.3 .33 )3 1, ;DEF F989:<9=. S"L4 CLEAR BREA'5 7;96LF :896;9= S"L4 SELECT # FROM EMP ORDER BY JOB5 EMPNO ENAMEJOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 02) 'ING PRESIDENT 10&NOV&21 .333 13 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 02,, TURNER SALESMAN0/ 2 32&SEP&21 1.33 3 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 1, ;DEF F989:<9=.

201

*ARRAYS: VARRAYS ARE SIMILAR TO C OR JAVA ARRAYS. ARRAY IS COLLECTION OF SIMILAR DATATYPES. S"L4 CREATE TABLE FRIENDS 2 (NAME VARCHAR2(13)$ ) FRIEND(NAME VARCHAR2(13))5 T6789 :;96<9=. S"L4 ALTER TABLE FRIENDS 2 ADD CONSTRAINT FRIENDS(P' PRIMARY 'EY(NAME)5 T6789 68<9;9=. S"L4 INSERT INTO FRIENDS 2 VALUES

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) (CPAVANC$CRAMC)5 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS 2 VALUES )# (CPAVANC$CSRIRAMC) S"L4 / INSERT INTO FRIENDS # ERROR 6< 8NK9 1% ORA&33331% ?KNP?9 :DKF<;6NK< (SCOTT.FRIENDS(P') QND86<9=

202

S"L4 ALTER TABLE FRIENDS 2 DROP CONSTRAINT FRIENDS(P'5 T6789 68<9;9=. S"L4 INSERT INTO FRIENDS 2 VALUES ) (CPAVANC$CSRIRAMC)5 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS 2 VALUES )# (CPAVANC$CGAYATRIC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS 2 VALUES )# (CPAVANC$CSRI DEVIC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS 2 VALUES )# (CBALAJIC$CSRI DEVIC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS 2 VALUES )# (CBALAJIC$CGAYATRIC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS 2 VALUES )# (CBALAJIC$CPRATHIMAC)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS 2 VALUES )# (CHANUMANC$CPRATHIMAC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS 2 VALUES )# (CHANUMANC$CSRI DEVIC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS 2 VALUES )# (CHANUMANC$CSUNDARIC) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT # FROM FRIENDS5 NAME FRIEND(NAM &&&&&&&&&& &&&&&&&&&& PAVAN RAM PAVAN SRIRAM PAVAN GAYATRI PAVAN SRI DEVI BALAJI SRI DEVI BALAJI GAYATRI BALAJI PRATHIMA HANUMAN PRATHIMA HANUMAN SRI DEVI HANUMAN SUNDARI 13 ;DEF F989:<9=.

20)

CREATION OF *ARRAY: S"L4 CREATE OR REPLACE TYPE FRIENDS(NAME AS VARRAY(.) OF VARCHAR2(13)5 2 / TAB9 :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CREATING TABLE USING *ARRAY: S"L4 CREATE TABLE FRIENDS1 2 (NAME VARCHAR2(13)$ ) FRIEND(NAME FRIENDS(NAME)5 T6789 :;96<9=. S"L4 ALTER TABLE FRIENDS1 2 ADD CONSTRAINT FRIENDS1(P' PRIMARY 'EY(NAME)5 T6789 68<9;9=. DESCRIBING T.E TABLE:

20,

S"L4 DESC FRIENDS1 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& NAME NOT NULL VARCHAR2(13) FRIEND(NAME FRIENDS(NAME 1 SELECT COLUMN(NAME$DATA(TYPE 2 FROM USER(TAB(COLUMNS )# WHERE TABLE(NAMEICFRIENDS1C S"L4 / COLUMN(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DATA(TYPE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& NAME VARCHAR2 FRIEND(NAME FRIENDS(NAME 1 SELECT TYPECODE$ATTRIBUTES 2 FROM USER(TYPES )# WHERE TYPE(NAMEICFRIENDS(NAMEC S"L4 / TYPECODE ATTRIBUTES &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&& COLLECTION 3

S"L4 SELECT COLL(TYPE$ELEM(TYPE(OWNER$ELEM(TYPE(NAME$ UPPER(BOUND$LENGTH 2 FROM USER(COLL(TYPES ) WHERE TYPE(NAMEICFRIENDS(NAMEC5 COLL(TYPE ELEM(TYPE(OWNER ELEM(TYPE(NAME UPPER(BOUND &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&& &&&&&&&&&& VARYING ARRAY VARCHAR2 . 13 LENGTH

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 ;DE :;96<9=.

20.

INSERTING *ALUES IN TO T.E TABLE:

1 INSERT INTO FRIENDS1 2 VALUES )# (CPAVANC$FRIENDS(NAME(CRAMC$CSRIRAMC$CGAYATRIC$CSRI DEVIC)) , /

1 INSERT INTO FRIENDS1 2 VALUES )# (CBALAJIC$FRIENDS(NAME(CPRATHIMAC$CGAYATRIC$CSRI DEVIC)) , / 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS1 2 VALUES )# (CHANUMANC$FRIENDS(NAME(CPRATHIMAC$CGAYATRIC$CSUNDARIC)) S"L4 / 1 ;DE :;96<9=.

SELECTING *ALUES FRO) T.E TABLE:

S"L4 SELECT # FROM FRIENDS15 NAME &&&&&&&&&& FRIEND(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& PAVAN FRIENDS(NAME(CRAMC$ CSRIRAMC$ CGAYATRIC$ CSRI DEVIC) BALAJI FRIENDS(NAME(CPRATHIMAC$ CGAYATRIC$ CSRI DEVIC) HANUMAN FRIENDS(NAME(CPRATHIMAC$ CGAYATRIC$ CSUNDARIC) SELECTING *ALUES FRO) T.E TABLE USING CURSOR: DECLARE CURSOR C IS SELECT # FROM FRIENDS15 BEGIN FOR C(REC IN C LOOP DBMS(OUTPUT.PUT(LINE(CNAME% C VVC(REC.NAME)5 FOR I IN 1.. C(REC.FRIEND(NAME.COUNT LOOP DBMS(OUTPUT.PUT(LINE(C(REC.FRIEND(NAME(I))5 END LOOP5 END LOOP5 13# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON S"L4 / NAME% PAVAN RAM 1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SRIRAM GAYATRI SRI DEVI NAME% BALAJI PRATHIMA GAYATRI SRI DEVI NAME% HANUMAN PRATHIMA GAYATRI SUNDARI PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 SELECT F.NAME$N.# 2# FROM FRIENDS1 F$ TABLE(F.FRIEND(NAME) N ) / NAME COLUMN(VAL &&&&&&&&&& &&&&&&&&&& PAVAN RAM PAVAN SRIRAM PAVAN GAYATRI PAVAN SRI DEVI BALAJI PRATHIMA BALAJI GAYATRI BALAJI SRI DEVI HANUMAN PRATHIMA HANUMAN GAYATRI HANUMAN SUNDARI 13 ;DEF F989:<9=. CREATING NU)BER *ARRAY: DECLARE TYPE NUMBERS IS VARRAY(23) OF NUMBER())5 V(LIST1 NUMBERS %I NUMBERS(1$2$)$,$.)5 V(LIST2 NUMBERS5 BEGIN FOR I IN 1..V(LIST1.COUNT LOOP DBMS(OUTPUT.PUT(LINE(V(LIST1(I))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 13# END5 S"L4 / 1 2 ) , . COUNT%. PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DECLARE TYPE NUMBERS IS VARRAY(.) OF NUMBER())5 V(LIST1 NUMBERS %I NUMBERS(1$2$)$,$.)5 V(LIST2 NUMBERS5 BEGIN FOR I IN 1..V(LIST1.COUNT LOOP DBMS(OUTPUT.PUT(LINE(V(LIST1(I))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 13# END5 S"L4 / 1 2 ) , . / 0 2 1 2 ) , . / 0 2

20/

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 2 ) , . COUNT%. PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DECLARE TYPE NUMBERS IS VARRAY(.) OF NUMBER())5 V(LIST1 NUMBERS %I NUMBERS(1$2$)$,$.)5 BEGIN FOR I IN 1..V(LIST1.COUNT LOOP DBMS(OUTPUT.PUT(LINE(V(LIST1(I))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 # END5 13 / 1 2 ) , . COUNT%. PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DECLARE TYPE NUMBERS IS VARRAY(/) OF NUMBER())5 V(LIST1 NUMBERS %I NUMBERS(1$2$)$,$.)5 BEGIN FOR I IN 1..V(LIST1.COUNT LOOP DBMS(OUTPUT.PUT(LINE(V(LIST1(I))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 V(LIST1.E!TEND5 13 V(LIST1(/)%I/5 11 DBMS(OUTPUT.PUT(LINE(V(LIST1(/))5 12# END5 S"L4 / 1 2 ) , . COUNT%. / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 2 ) , . / 0 2 1 2 ) , . / 0 2

200

DECLARE TYPE NUMBERS IS VARRAY(/) OF NUMBER())5 V(LIST1 NUMBERS %I NUMBERS(1$2$)$,$.)5 BEGIN FOR I IN 1..V(LIST1.COUNT LOOP DBMS(OUTPUT.PUT(LINE(V(LIST1(I))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 V(LIST1.E!TEND5 13 V(LIST1(/)%I/5

1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
11 V(LIST1.E!TEND5 12 DBMS(OUTPUT.PUT(LINE(V(LIST1(/))5 1)# END5 S"L4 / 1 2 ) , . COUNT%. DECLARE # ERROR 6< 8NK9 1% ORA&3/.)2% S?7F:;NB< D?<FN=9 DT 8N>N< ORA&3/.12% 6< 8NK9 11

202

DECLARE TYPE NUMBERS IS VARRAY(/) OF NUMBER())5 V(LIST1 NUMBERS %I NUMBERS(1$2$)$,$.)5 BEGIN FOR I IN 1..V(LIST1.COUNT LOOP DBMS(OUTPUT.PUT(LINE(V(LIST1(I))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 V(LIST1.E!TEND5 13 V(LIST1(/)%I/5 11 DBMS(OUTPUT.PUT(LINE(V(LIST1(/))5 12 DBMS(OUTPUT.PUT(LINE(CLIMIT%CVVV(LIST1.COUNT)5 1)# END5 1, / 1 2 ) , . COUNT%. / LIMIT%/ PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

1 2 ) , . / 0 2

DECLARE TYPE NUMBERS IS VARRAY(/) OF NUMBER())5 V(LIST1 NUMBERS %I NUMBERS(1$2$)$,$.)5 BEGIN FOR I IN 1..V(LIST1.COUNT LOOP DBMS(OUTPUT.PUT(LINE(V(LIST1(I))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 V(LIST1.E!TEND5 13 V(LIST1(/)%I/5 11 DBMS(OUTPUT.PUT(LINE(V(LIST1(/))5 12 DBMS(OUTPUT.PUT(LINE(CLIMIT%CVVV(LIST1.COUNT)5 1) DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 1,# END5 S"L4 / 1 2 ) , . COUNT%. / LIMIT%/

1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
COUNT%/ PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DECLARE TYPE NUMBERS IS VARRAY(/) OF NUMBER())5 V(LIST1 NUMBERS %I NUMBERS(1$2$)$,$.)5 BEGIN FOR I IN 1..V(LIST1.COUNT LOOP DBMS(OUTPUT.PUT(LINE(V(LIST1(I))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 V(LIST1.E!TEND5 13 V(LIST1(/)%I/5 11 DBMS(OUTPUT.PUT(LINE(V(LIST1(/))5 12 DBMS(OUTPUT.PUT(LINE(CLIMIT%CVVV(LIST1.COUNT)5 1) DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 1, DBMS(OUTPUT.PUT(LINE(CFIRST%CVVV(LIST1.FIRST)5 1. DBMS(OUTPUT.PUT(LINE(CLAST%CVVV(LIST1.LAST)5 1/ DBMS(OUTPUT.PUT(LINE(CPRIOR%CVVV(LIST1.PRIOR(2))5 10 DBMS(OUTPUT.PUT(LINE(CNE!T%CVVV(LIST1.NE!T(2))5 12# END5 1 / 1 2 ) , . COUNT%. / LIMIT%/ COUNT%/ FIRST%1 LAST%/ PRIOR%1 NE!T%) PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DECLARE TYPE NUMBERS IS VARRAY(/) OF NUMBER())5 V(LIST1 NUMBERS %I NUMBERS(1$2$)$,$.)5 BEGIN FOR I IN 1..V(LIST1.COUNT LOOP DBMS(OUTPUT.PUT(LINE(V(LIST1(I))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 V(LIST1.E!TEND5 13 V(LIST1(/)%I/5 11 DBMS(OUTPUT.PUT(LINE(V(LIST1(/))5 12 DBMS(OUTPUT.PUT(LINE(CLIMIT%CVVV(LIST1.COUNT)5 1) DBMS(OUTPUT.PUT(LINE(CCOUNT%CVVV(LIST1.COUNT)5 1, DBMS(OUTPUT.PUT(LINE(CFIRST%CVVV(LIST1.FIRST)5 1. DBMS(OUTPUT.PUT(LINE(CLAST%CVVV(LIST1.LAST)5 1/ DBMS(OUTPUT.PUT(LINE(CPRIOR%CVVV(LIST1.PRIOR(2))5 10 DBMS(OUTPUT.PUT(LINE(CNE!T%CVVV(LIST1.NE!T(2))5 12# END5 S"L4 / 1 2 ) , . COUNT%. / LIMIT%/ 1 2 ) , . / 0 2 1 2 ) , . / 0 2

20

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
COUNT%/ FIRST%1 LAST%/ PRIOR%1 NE!T%) PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

223

NESTED TABLES: CREATING FRIEND TYPE% 1 CREATE OR REPLACE TYPE FRIEND(TY AS OBJECT 2 (NAME VARCHAR2(13)$ ) CITY VARCHAR2(13)$ , STATE VARCHAR2(13)$ .# COUNTRY VARCHAR2(13))5 S"L4 / TAB9 :;96<9=. CON*ERTING FRIEND2TY AS NESTED TABLE: THE FROEND(TY CONTAINS RECORD FOR EACH FRIEND. TO USE THIS DATA TYPE AS THE BASIS FOR A NESTED TABLE$YOU NEED TO CREATE NEW DATA TYPE. S"L4 CREATE TYPE FRIEND(NT AS TABLE OF FRIEND(TY5 2 / TAB9 :;96<9=. AS TABLE OF CLAUSE OF THIS CRETE TYPE COMMAND TELLS ORACLE THAT YOU WILL BE USING THIS TYPE AS THE BASIS FOR A NESTED TABLE. THE FRIEND(NT STORES MULTIPLE ROWS. CREATING TABLE USING NESTED TABLE: S"L4 CREATE TABLE FRIENDS(NESTED 2 (NAME VARCHAR2(13)$ ) FRIENDS FRIEND(NT) , NESTED TABLE FRIENDS STORE AS FRIEND(NT(TAB5 T6789 :;96<9=. FIRST COLUMN IS NAME$THE SECOND COLUMN IS A COLUMN NAMED FRIENDS WHOSE DEFINITION IS THE NESTED TABLE FRIEND(NT. WHEN CREATING THE TABLE THAT INCLUDES A NESTED TABLE$YOU MUST SPECIFY THE NAME OF THE TABLE THAT WILL BE USED TO STORE THE NESTED TABLES DATA.THAT IS $THE DATA FOR THE NESTED TABLE IS NOT STORED MINLINEH WITH THE REST OF THE TABLES DATA.INSTEAD$IT IS STORED APART FROM THE MAIN TABLE.THE DATA IN THE FRIENDS COLUMN WILL BE STORED IN ONE TABLE$AND THE DATA IN THE NAME COLUMN WILL BE STORED IN A SEPARATE TABLE. ORACLE WILL MAINTAIN POINTERS BETWEEN THE TABLES. HERE THE OUT(OF(LINE DATA FOR THE NESTED TABLE IS STORED IN A TABLE NAMED FRIEND(NT(TAB.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
INSERTING INTO NESTED TABLE: 1 INSERT INTO FRIENDS(NESTED 2 VALUES ) (CPAVANC$FRIEND(NT , (FRIEND(TY(CGAYATRIC$CHYDC$CAPC$CINDIAC)$ . FRIEND(TY(CSRIDEVIC$CHYDC$CAPC$CINDIAC)$ /# FRIEND(TY(CPRATHIMAC$CHYDC$CAPC$CINDIAC))) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS(NESTED 2 VALUES ) (C'UMARC$FRIEND(NT , (FRIEND(TY(CGAYATRIC$CHYDC$CAPC$CINDIAC)$ . FRIEND(TY(CSRIDEVIC$CHYDC$CAPC$CINDIAC)$ /# FRIEND(TY(CPRATHIMAC$CHYDC$CAPC$CINDIAC))) 0 / 1 ;DE :;96<9=.

221

1 INSERT INTO FRIENDS(NESTED 2 VALUES ) (CSRIRAMC$FRIEND(NT , (FRIEND(TY(CSHILPAC$CHYDC$CAPC$CINDIAC)$ . FRIEND(TY(CSRIDEVIC$CHYDC$CAPC$CINDIAC)$ /# FRIEND(TY(CLALITHAC$CHYDC$CAPC$CINDIAC))) 0 / 1 ;DE :;96<9=. 1 INSERT INTO FRIENDS(NESTED 2 VALUES ) (CRAVI'ANTHC$FRIEND(NT , (FRIEND(TY(CUSGIRLC$CHYDC$CAPC$CINDIAC)$ . FRIEND(TY(CSRIDEVIC$CHYDC$CAPC$CINDIAC)$ /# FRIEND(TY(CLALITHAC$CHYDC$CAPC$CINDIAC))) 0 / 1 ;DE :;96<9=.

DESCRIBING T.E NESTED TABLE:

S"L4 SET DESCRIBE DEPTH 2 S"L4 DESC FRIENDS(NESTED N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& NAME VARCHAR2(13) FRIENDS FRIEND(NT NAME VARCHAR2(13) CITY VARCHAR2(13) STATE VARCHAR2(13) COUNTRY VARCHAR2(13)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECTING FRO) NESTED TABLE: S"L4 SELECT # FROM FRIENDS(NESTED5 NAME &&&&&&&&&& FRIENDS(NAME$ CITY$ STATE$ COUNTRY) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& PAVAN FRIEND(NT(FRIEND(TY(CGAYATRIC$ CHYDC$ CAPC$ CINDIAC)$ FRIEND(TY(CSRIDEVIC$ CHYDC$ CAPC$ CINDIAC)$ FRIEND(TY(CPRATHIMAC$ CHYDC$ CAP C$ CINDIAC)) 'UMAR FRIEND(NT(FRIEND(TY(CGAYATRIC$ CHYDC$ CAPC$ CINDIAC)$ FRIEND(TY(CSRIDEVIC$ CHYDC$ CAPC$ CINDIAC)$ FRIEND(TY(CPRATHIMAC$ CHYDC$ CAP C$ CINDIAC))

222

SRIRAM FRIEND(NT(FRIEND(TY(CSHILPAC$ CHYDC$ CAPC$ CINDIAC)$ FRIEND(TY(CSRIDEVIC$ CHYDC$ CAPC$ CINDIAC)$ FRIEND(TY(CLALITHAC$ CHYDC$ CAPC$ CINDIAC)) RAVI'ANTH FRIEND(NT(FRIEND(TY(CUSGIRLC$ CHYDC$ CAPC$ CINDIAC)$ FRIEND(TY(CSRIDEVIC$ CHYDC$ CAPC$ CINDIAC)$ FRIEND(TY(CLALITHAC$ CHYDC$ CAPC$ CINDIAC))

1 SELECT NAME$N.NAME$N.CITY$N.STATE$N.COUNTRY FROM FRIENDS(NESTED$ 2# TABLE(FRIENDS(NESTED.FRIENDS) N S"L4 / SELECT NAME$N.NAME$N.CITY$N.STATE$N.COUNTRY FROM FRIENDS(NESTED$ # ERROR 6< 8NK9 1% ORA&33 12% :D8?>K 6>7NS?D?F8A =9TNK9=

1 SELECT FRIENDS(NESTED.NAME$N.NAME$N.CITY$N.STATE$N.COUNTRY FROM FRIENDS(NESTED$ 2# TABLE(FRIENDS(NESTED.FRIENDS) N S"L4 / NAME NAME CITY &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& PAVAN GAYATRI HYD AP PAVAN SRIDEVI HYD AP PAVAN PRATHIMA HYD AP 'UMAR GAYATRI HYD AP 'UMAR SRIDEVI HYD AP 'UMAR PRATHIMA HYD AP SRIRAM SHILPA HYD AP SRIRAM SRIDEVI HYD AP SRIRAM LALITHA HYD AP RAVI'ANTH USGIRL HYD AP RAVI'ANTH SRIDEVI HYD AP RAVI'ANTH LALITHA HYD AP 12 ;DEF F989:<9=. STATE INDIA INDIA INDIA INDIA INDIA INDIA INDIA INDIA INDIA INDIA INDIA INDIA COUNTRY

1 SELECT FRIENDS(NESTED.NAME$N.NAME$N.CITY$N.STATE$N.COUNTRY FROM FRIENDS(NESTED$ 2 TABLE(FRIENDS(NESTED.FRIENDS) N )# WHERE FRIENDS(NESTED.NAMEICPAVANC , /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
NAME NAME CITY STATE COUNTRY &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& PAVAN GAYATRI HYD AP INDIA PAVAN SRIDEVI HYD AP INDIA PAVAN PRATHIMAHYD AP INDIA 1 SELECT FRIENDS(NESTED.NAME$N.NAME$N.CITY$N.STATE$N.COUNTRY FROM FRIENDS(NESTED$ 2 TABLE(FRIENDS(NESTED.FRIENDS) N )# WHERE N.NAMEICSRIDEVIC , / NAME NAME CITY STATE COUNTRY &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& PAVAN SRIDEVI HYD AP INDIA 'UMAR SRIDEVI HYD AP INDIA SRIRAM SRIDEVI HYD AP INDIA RAVI'ANTH SRIDEVI HYD AP INDIA INSERTING ONLY TO NESTED TABLE FOR ONE RECORD: S"L4 INSERT INTO TABLE (SELECT FRIENDS FROM FRIENDS(NESTED 2 WHERE NAMEICPAVANC) ) VALUES , (FRIEND(TY(CNEELIMAC$CWALESC$CCARDIFC$CLONDONC))5 1 ;DE :;96<9=. S"L4 SELECT FRIENDS(NESTED.NAME$N.NAME$N.CITY$N.STATE$N.COUNTRY FROM FRIENDS(NESTED$ 2 TABLE(FRIENDS(NESTED.FRIENDS) N ) WHERE FRIENDS(NESTED.NAMEICPAVANC5 NAME NAME CITY STATE COUNTRY &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& PAVAN GAYATRI HYD AP INDIA PAVAN SRIDEVI HYD AP INDIA PAVAN PRATHIMA HYD AP INDIA PAVAN NEELIMA WALES CARDIF LONDON UPDATING NESTED TABLE% S"L4 UPDATE TABLE (SELECT FRIENDS FROM FRIENDS(NESTED 2 WHERE NAMEICPAVANC) N ) SET N.COUNTRYICUSAC , WHERE N.NAMEICSRIDEVIC5 1 ;DE ?B=6<9=. S"L4 SELECT FRIENDS(NESTED.NAME$N.NAME$N.CITY$N.STATE$N.COUNTRY FROM FRIENDS(NESTED$ 2 TABLE(FRIENDS(NESTED.FRIENDS) N ) WHERE FRIENDS(NESTED.NAMEICPAVANC5 NAME NAME CITY STATE COUNTRY &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& PAVAN GAYATRI HYD AP INDIA PAVAN SRIDEVI HYD AP USA PAVAN PRATHIMA HYD AP INDIA PAVAN NEELIMA WALES CARDIF LONDON DELETING FROM NESTED TABLE% 1 DELETE TABLE(SELECT FRIENDS FROM FRIENDS(NESTED 2 WHERE NAMEICPAVANC) N )# WHERE N.NAMEICPRATHIMAC S"L4 / 1 ;DE =989<9=.

22)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT FRIENDS(NESTED.NAME$N.NAME$N.CITY$N.STATE$N.COUNTRY FROM FRIENDS(NESTED$ 2 TABLE(FRIENDS(NESTED.FRIENDS) N ) WHERE FRIENDS(NESTED.NAMEICPAVANC5 NAME NAME CITY STATE COUNTRY &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& PAVAN GAYATRI HYD AP INDIA PAVAN SRIDEVI HYD AP USA PAVAN NEELIMA WALES CARDIF LONDON CREATING NU)BER NESTED AND *ARRAYS: S"L4 CREATE OR REPLACE TYPE NUMTAB AS TABLE OF NUMBER5 2 / TAB9 :;96<9=. S"L4 CREATE OR REPLACE TYPE NUMVAR AS VARRAY(2.) OF NUMBER5 2 / TAB9 :;96<9=. COUNT AND E/ISTS: COUNT GIVES NO OF ELEMENTS. S"L4 DECLARE 2 V(NESTEDTABLE NUMTAB %INUMTAB(&0$1,.)$).1,1.$NULL$3)5 ) V(COUNT NUMBER(2)%I15 , BEGIN . LOOP / IF V(NESTEDTABLE.E!ISTS(V(COUNT) THEN 0 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVV(COUNTVVC)%C VV 2 V(NESTEDTABLE(V(COUNT))5 V(COUNT %IV(COUNTJ15 13 ELSE 11 E!IT5 12 END IF5 1) END LOOP5 1, END5 1. / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

22,

S"L4 SET SERVEROUTPUT ON S"L4 / V(NESTEDTABLE(1)%&0 V(NESTEDTABLE(2)%1,.) V(NESTEDTABLE())%).1,1. V(NESTEDTABLE(,)% V(NESTEDTABLE(.)%3 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 V(NESTEDTABLE NUMTAB %INUMTAB(1$2$))5 ) V(VARRY NUMVAR %I NUMVAR(&1$&2$&)$&,)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
V(COUNT NUMBER(2)%I15 BEGIN DBMS(OUTPUT.PUT(LINE(CNESTED TABLE COUNT CVV V(NESTEDTABLE.COUNT)5 DBMS(OUTPUT.PUT(LINE(CVARRAY COUNT CVV V(VARRY.COUNT)5 13# END5 11 / NESTED TABLE COUNT ) VARRAY COUNT , PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. LI)IT: LIMIT WILL GIVE NO OF ELEMENTS AT TIME OF DECLARATION. DECLARE V(NESTEDTABLE NUMTAB %INUMTAB(1$2$))5 V(VARRY NUMVAR %I NUMVAR(&1$&2$&)$&,)5 V(COUNT NUMBER(2)%I15 BEGIN DBMS(OUTPUT.PUT(LINE(CNESTED TABLE COUNT CVV V(NESTEDTABLE.COUNT)5 DBMS(OUTPUT.PUT(LINE(CNESTED TABLE LIMIT CVV V(NESTEDTABLE.LIMIT)5 13 DBMS(OUTPUT.PUT(LINE(CVARRAY COUNT CVV 11 V(VARRY.COUNT)5 12 DBMS(OUTPUT.PUT(LINE(CVARRAY LIMIT CVV 1) V(VARRY.LIMIT)5 1,# END5 1. / NESTED TABLE COUNT ) NESTED TABLE LIMIT VARRAY COUNT , VARRAY LIMIT 2. PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 2 ) , . / 0 2 , . / 0 2

22.

FIRST"LAST"NE/T"PRIOR: DECLARE V(NESTEDTABLE NUMTAB %INUMTAB(1$2$))5 V(VARRY NUMVAR %I NUMVAR(&1$&2$&)$&,)5 V(COUNT NUMBER(2)%I15 BEGIN DBMS(OUTPUT.PUT(LINE(CNESTED TABLE FIRST CVV V(NESTEDTABLE.FIRST)5 DBMS(OUTPUT.PUT(LINE(CNESTED TABLE LAST CVV V(NESTEDTABLE.LAST)5 13 DBMS(OUTPUT.PUT(LINE(CNESTED TABLE PRIOR OF 2 CVV 11 V(NESTEDTABLE.PRIOR(2))5 12 DBMS(OUTPUT.PUT(LINE(CNESTED TABLE NE!T OF 2 CVV 1) V(NESTEDTABLE.NE!T(2))5 1, DBMS(OUTPUT.PUT(LINE(CVARRAY FIRST CVV 1. V(VARRY.FIRST)5 1/ DBMS(OUTPUT.PUT(LINE(CVARRAY LAST CVV 10 V(VARRY.LAST)5 12 DBMS(OUTPUT.PUT(LINE(CVARRAY PRIOR OF 2 CVV 1 V(VARRY.PRIOR(2))5 23 DBMS(OUTPUT.PUT(LINE(CVARRAY NE!T OF 2 CVV 21 V(VARRY.NE!T(2))5 22# END5 2) / 1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
NESTED TABLE FIRST 1 NESTED TABLE LAST ) NESTED TABLE PRIOR OF 2 1 NESTED TABLE NE!T OF 2 ) VARRAY FIRST 1 VARRAY LAST , VARRAY PRIOR OF 2 1 VARRAY NE!T OF 2 ) PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. E/TEND: 1 DECLARE 2 V(NESTEDTABLE NUMTAB %INUMTAB(1$2$)$,$.)5 ) V(VARRY NUMVAR %I NUMVAR(1$2$)$,$.)5 , BEGIN . BEGIN / V(NESTEDTABLE(2/)%I05 0 E!CEPTION 2 WHEN SUBSCRIPT(BEYOND(COUNT THEN DBMS(OUTPUT.PUT(LINE(S"LCODEVVS"LERRM)5 13 END5 11 V(NESTEDTABLE.E!TEND()3)5 12 V(NESTEDTABLE(2/)%I05 1) 1, 1. 1/ 10 12 BEGIN V(VARRY.E!TEND()3)5 E!CEPTION WHEN SUBSCRIPT(OUTSIDE(LIMIT THEN DBMS(OUTPUT.PUT(LINE(S"LCODEVVS"LERRM)5 END5

22/

1 V(VARRY.E!TEND(23)5 23 V(VARRY(2.)%I2.5 21# END5 S"L4 / &/.))ORA&3/.))% S?7F:;NB< 79ADK= :D?K< &/.)2ORA&3/.)2% S?7F:;NB< D?<FN=9 DT 8N>N< PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

DECLARE V(NESTEDTABLE NUMTAB %INUMTAB(1$2$)$,$.)5 V(VARRY NUMVAR %I NUMVAR(1$2$)$,$.)5 BEGIN FOR C IN 1..V(NESTEDTABLE.COUNT LOOP DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV V(NESTEDTABLE(C))5 END LOOP5 # END5 13 / V(NESTEDTABLE(1)1 V(NESTEDTABLE(2)2 V(NESTEDTABLE())) V(NESTEDTABLE(,),

1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
V(NESTEDTABLE(.). PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

220

DECLARE V(NESTEDTABLE NUMTAB %INUMTAB(13$23$)3$,3$.3)5 V(VARRY NUMVAR %I NUMVAR(1$2$)$,$.)5 BEGIN FOR C IN 1..V(NESTEDTABLE.COUNT LOOP DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV V(NESTEDTABLE(C))5 END LOOP5 # END5 S"L4 / V(NESTEDTABLE(1)13 V(NESTEDTABLE(2)23 V(NESTEDTABLE()))3 V(NESTEDTABLE(,),3 V(NESTEDTABLE(.).3 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. TRI): TRIM WILL REMOVE ELEMENTS FROM END. DECLARE V(NESTEDTABLE NUMTAB %INUMTAB(13$23$)3$,3$.3)5 V(VARRY NUMVAR %I NUMVAR(1$2$)$,$.)5 BEGIN FOR C IN 1..V(NESTEDTABLE.COUNT LOOP DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV V(NESTEDTABLE(C))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(COUTPUT AFTER TRIMC)5 13 V(NESTEDTABLE.TRIM5 11 FOR C IN 1..V(NESTEDTABLE.COUNT LOOP 12 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 1) V(NESTEDTABLE(C))5 1, END LOOP5 1.# END5 1/ / V(NESTEDTABLE(1)13 V(NESTEDTABLE(2)23 V(NESTEDTABLE()))3 V(NESTEDTABLE(,),3 V(NESTEDTABLE(.).3 OUTPUT AFTER TRIM V(NESTEDTABLE(1)13 V(NESTEDTABLE(2)23 V(NESTEDTABLE()))3 V(NESTEDTABLE(,),3 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 2 ) , . / 0 2

1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DECLARE V(NESTEDTABLE NUMTAB %INUMTAB(13$23$)3$,3$.3)5 V(VARRY NUMVAR %I NUMVAR(1$2$)$,$.)5 BEGIN FOR C IN 1..V(NESTEDTABLE.COUNT LOOP DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV V(NESTEDTABLE(C))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(COUTPUT AFTER TRIM.C)5 13 V(NESTEDTABLE.TRIM5 11 FOR C IN 1..V(NESTEDTABLE.COUNT LOOP 12 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 1) V(NESTEDTABLE(C))5 1, END LOOP5 1. DBMS(OUTPUT.PUT(LINE(COUTPUT AFTER TRIM())C)5 1/ V(NESTEDTABLE.TRIM())5 10 FOR C IN 1..V(NESTEDTABLE.COUNT LOOP 12 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 1 V(NESTEDTABLE(C))5 23 END LOOP5 21# END5 S"L4 / V(NESTEDTABLE(1)13 V(NESTEDTABLE(2)23 V(NESTEDTABLE()))3 V(NESTEDTABLE(,),3 V(NESTEDTABLE(.).3 OUTPUT AFTER TRIM. V(NESTEDTABLE(1)13 V(NESTEDTABLE(2)23 V(NESTEDTABLE()))3 V(NESTEDTABLE(,),3 OUTPUT AFTER TRIM()) V(NESTEDTABLE(1)13 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DELETE: DECLARE V(NESTEDTABLE NUMTAB %INUMTAB(13$23$)3$,3$.3)5 BEGIN FOR C IN 1..V(NESTEDTABLE.COUNT LOOP DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV V(NESTEDTABLE(C))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(COUTPUT AFTER DELETE.C)5 V(NESTEDTABLE.DELETE5 13 FOR C IN 1..V(NESTEDTABLE.COUNT LOOP 11 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 12 V(NESTEDTABLE(C))5 1) END LOOP5 1,# END5 1. / V(NESTEDTABLE(1)13 V(NESTEDTABLE(2)23 V(NESTEDTABLE()))3 V(NESTEDTABLE(,),3 V(NESTEDTABLE(.).3 OUTPUT AFTER DELETE. PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 V(NESTEDTABLE NUMTAB %INUMTAB(13$23$)3$,3$.3)5 1 2 ) , . / 0 2 1 2 ) , . / 0 2

222

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
BEGIN FOR C IN 1..V(NESTEDTABLE.COUNT LOOP DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV V(NESTEDTABLE(C))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(COUTPUT AFTER DELETE(2).C)5 V(NESTEDTABLE.DELETE(2)5 13 FOR C IN 1..V(NESTEDTABLE.COUNT LOOP 11 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 12 V(NESTEDTABLE(C))5 1) END LOOP5 1,# END5 S"L4 / V(NESTEDTABLE(1)13 V(NESTEDTABLE(2)23 V(NESTEDTABLE()))3 V(NESTEDTABLE(,),3 V(NESTEDTABLE(.).3 OUTPUT AFTER DELETE(2). V(NESTEDTABLE(1)13 DECLARE # ERROR 6< 8NK9 1% ORA&31,3)% KD =6<6 TD?K= ORA&3/.12% 6< 8NK9 11 DECLARE V(NESTEDTABLE NUMTAB %INUMTAB(13$23$)3$,3$.3)5 BEGIN FOR C IN 1..V(NESTEDTABLE.COUNT LOOP DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV V(NESTEDTABLE(C))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(COUTPUT AFTER DELETE(2$,).C)5 V(NESTEDTABLE.DELETE(2$,)5 13 FOR C IN 1..V(NESTEDTABLE.COUNT LOOP 11 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 12 V(NESTEDTABLE(C))5 1) END LOOP5 1,# END5 1. / V(NESTEDTABLE(1)13 V(NESTEDTABLE(2)23 V(NESTEDTABLE()))3 V(NESTEDTABLE(,),3 V(NESTEDTABLE(.).3 OUTPUT AFTER DELETE(2$,). V(NESTEDTABLE(1)13 DECLARE # ERROR 6< 8NK9 1% ORA&31,3)% KD =6<6 TD?K= ORA&3/.12% 6< 8NK9 11 DECLARE V(NESTEDTABLE NUMTAB %INUMTAB(13$23$)3$,3$.3$/3$03$23)5 BEGIN FOR C IN 1..V(NESTEDTABLE.COUNT LOOP DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV V(NESTEDTABLE(C))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(COUTPUT AFTER DELETE(2$,).C)5 V(NESTEDTABLE.DELETE(2$,)5 13 FOR C IN 1..V(NESTEDTABLE.COUNT LOOP 11 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 1 2 ) , . / 0 2 1 2 ) , . / 0 2 ) , . / 0 2

22

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
12 V(NESTEDTABLE(C))5 1) END LOOP5 1, E!CEPTION 1. WHEN NO(DATA(FOUND THEN 1/ FOR C IN ...V(NESTEDTABLE.COUNT LOOP 10 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 12 V(NESTEDTABLE(C))5 1 END LOOP5 23# END5 S"L4 / V(NESTEDTABLE(1)13 V(NESTEDTABLE(2)23 V(NESTEDTABLE()))3 V(NESTEDTABLE(,),3 V(NESTEDTABLE(.).3 V(NESTEDTABLE(/)/3 V(NESTEDTABLE(0)03 V(NESTEDTABLE(2)23 OUTPUT AFTER DELETE(2$,). V(NESTEDTABLE(1)13 V(NESTEDTABLE(.).3 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

2 3

DECLARE V(NESTEDTABLE NUMTAB %INUMTAB(13$23$)3$,3$.3$/3$03$23)5 BEGIN FOR C IN 1..V(NESTEDTABLE.COUNT LOOP DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV V(NESTEDTABLE(C))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(COUTPUT AFTER DELETE(2$,).C)5 V(NESTEDTABLE.DELETE(2$,)5 13 FOR C IN 1..V(NESTEDTABLE.COUNT LOOP 11 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 12 V(NESTEDTABLE(C))5 1) END LOOP5 1, E!CEPTION 1. WHEN NO(DATA(FOUND THEN 1/ FOR C IN ...V(NESTEDTABLE.COUNT LOOP 10 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 12 V(NESTEDTABLE(C))5 1 END LOOP5 23# END5 21 / V(NESTEDTABLE(1)13 V(NESTEDTABLE(2)23 V(NESTEDTABLE()))3 V(NESTEDTABLE(,),3 V(NESTEDTABLE(.).3 V(NESTEDTABLE(/)/3 V(NESTEDTABLE(0)03 V(NESTEDTABLE(2)23 OUTPUT AFTER DELETE(2$,). V(NESTEDTABLE(1)13 V(NESTEDTABLE(.).3 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 V(NESTEDTABLE NUMTAB %INUMTAB(13$23$)3$,3$.3$/3$03$23)5

1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
V(COUNT NUMBER %IV(NESTEDTABLE.COUNT5 BEGIN FOR C IN 1..V(NESTEDTABLE.COUNT LOOP DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV V(NESTEDTABLE(C))5 END LOOP5 DBMS(OUTPUT.PUT(LINE(COUTPUT AFTER DELETE(2$,).C)5 13 V(NESTEDTABLE.DELETE(2$,)5 11 FOR C IN 1..V(NESTEDTABLE.COUNT LOOP 12 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 1) V(NESTEDTABLE(C))5 1, END LOOP5 1. E!CEPTION 1/ WHEN NO(DATA(FOUND THEN 10 FOR C IN ...V(COUNT LOOP 12 DBMS(OUTPUT.PUT(LINE(CV(NESTEDTABLE(CVVCVVC)CVV 1 V(NESTEDTABLE(C))5 23 END LOOP5 21# END5 22 / V(NESTEDTABLE(1)13 V(NESTEDTABLE(2)23 V(NESTEDTABLE()))3 V(NESTEDTABLE(,),3 V(NESTEDTABLE(.).3 V(NESTEDTABLE(/)/3 V(NESTEDTABLE(0)03 V(NESTEDTABLE(2)23 OUTPUT AFTER DELETE(2$,). V(NESTEDTABLE(1)13 V(NESTEDTABLE(.).3 V(NESTEDTABLE(/)/3 V(NESTEDTABLE(0)03 V(NESTEDTABLE(2)23 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. ) , . / 0 2

2 1

STORED SUBPROGRA)S AND T.E DATA DICTIONARY:

S"L4 CREATE OR REPLACE PROCEDURE SIMPLE 2 AS ) V(COUNTER NUMBER5 , BEGIN . V(COUNTER%I05 / END5 0 / P;D:9=?;9 :;96<9=. S"L4 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS 2 FROM USER(OBJECTS ) WHERE OBJECT(NAMEICSIMPLEC5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& SIMPLE PROCEDURE VALID S"L4 SELECT TE!T FROM USER(SOURCE 2 WHERE NAMEICSIMPLEC5 TE!T &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
PROCEDURE SIMPLE AS V(COUNTER NUMBER5 BEGIN V(COUNTER%I05 END5 / ;DEF F989:<9=. S"L4 SELECT LINE$POSITION$TE!T 2 FROM USER(ERRORS ) WHERE NAMEICSIMPLEC , / KD ;DEF F989:<9= S"L4 CREATE OR REPLACE PROCEDURE SIMPLE 2 AS ) V(COUNTER NUMBER5 , BEGIN . V(COUNTER%I05 / END 0 / W6;KNKS% P;D:9=?;9 :;96<9= EN<R :D>BN86<NDK 9;;D;F. S"L4 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS 2 FROM USER(OBJECTS ) WHERE OBJECT(NAMEICSIMPLEC5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& SIMPLE PROCEDURE INVALID S"L4 SELECT TE!T FROM USER(SOURCE 2 WHERE NAMEICSIMPLEC5 TE!T &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& PROCEDURE SIMPLE AS V(COUNTER NUMBER5 BEGIN V(COUNTER%I05 END / ;DEF F989:<9=.

2 2

S"L4 SELECT LINE$POSITION$TE!T 2 FROM USER(ERRORS ) WHERE NAMEICSIMPLEC5 LINE POSITION &&&&&&&&&& &&&&&&&&&& TE!T &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& / ) PLS%8878=: E Bou tCDCE tFC !GHIol JC E%of%filCJ KFC CLMCBti $ o C of tFC folloKi $:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
? <# iEC tifiCD> <# EouIlC%NuotCE ECliHitCE%iEC tifiCD> EClCtC CLi!t! MDioD <# !i $lC%NuotCE SQL !tDi $> TFC !GHIol J?J K#! !uI!titutCE foD JC E%of%filCJ to Bo ti uC( CALLING UN CO)PILED STORED PROCEDURE: S"L4 BEGIN 2 SIMPLE5 ) END5 , / SIMPLE5 # ERROR 6< 8NK9 2% ORA&3/..3% 8NK9 2$ :D8?>K 1% PLS&33 3.% D7X9:< SCOTT.SIMPLE NF NKQ68N= ORA&3/..3% 8NK9 2$ :D8?>K 1% PL/S"L% S<6<9>9K< NSKD;9= LOCAL SUBPROGRA)S: A LOCAL SUBPROGRAM$DECLARED IN THE DECLARATIVE SECTION OF A PL/S"L BLOC'. DECLARE CURSOR C IS SELECT EMPNO$ENAME FROM EMP5 V(FORMATTEDNAME VARCHAR2(133)5 FUNCTION FORMATNAME(P(EMPNO NUMBER$P(ENAME VARCHAR2) RETURN VARCHAR2 IS BEGIN RETURN P(EMPNOVVC HAS NAME CVVP(ENAME5 END FORMATNAME5 13 BEGIN 11 FOR C1 IN C 12 LOOP 1) V(FORMATTEDNAME%IFORMATNAME(C1.EMPNO$C1.ENAME)5 1, DBMS(OUTPUT.PUT(LINE(V(FORMATTEDNAME)5 1. END LOOP5 1/# END5 S"L4 / 0)/ HAS NAME SMITH 0, HAS NAME ALLEN 0.21 HAS NAME WARD 0.// HAS NAME JONES 0/., HAS NAME MARTIN 0/ 2 HAS NAME BLA'E 0022 HAS NAME CLAR' 0022 HAS NAME SCOTT 02) HAS NAME 'ING 02,, HAS NAME TURNER 020/ HAS NAME ADAMS 0 33 HAS NAME JAMES 0 32 HAS NAME FORD 0 ), HAS NAME MILLER PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. LOCAL SUBPROGRA)S AS PART OF STORED SUBPROGRA)S: 1 2 ) , . CREATE OR REPLACE PROCEDURE LOCALPROC AS CURSOR C IS SELECT EMPNO$ENAME FROM EMP5 V(FORMATTEDNAME VARCHAR2(133)5 FUNCTION FORMATNAME(P(EMPNO NUMBER$P(ENAME VARCHAR2) 1 2 ) , . / 0 2

2 )

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
/ RETURN VARCHAR2 0 IS 2 BEGIN RETURN P(EMPNOVVC HAS NAME CVVP(ENAME5 13 END FORMATNAME5 11 BEGIN 12 FOR C1 IN C 1) LOOP 1, V(FORMATTEDNAME%IFORMATNAME(C1.EMPNO$C1.ENAME)5 1. DBMS(OUTPUT.PUT(LINE(V(FORMATTEDNAME)5 1/ END LOOP5 10# END5 12 / P;D:9=?;9 :;96<9=. S"L4 BEGIN 2 LOCALPROC5 ) END5 , / 0)/ HAS NAME SMITH 0, HAS NAME ALLEN 0.21 HAS NAME WARD 0.// HAS NAME JONES 0/., HAS NAME MARTIN 0/ 2 HAS NAME BLA'E 0022 HAS NAME CLAR' 0022 HAS NAME SCOTT 02) HAS NAME 'ING 02,, HAS NAME TURNER 020/ HAS NAME ADAMS 0 33 HAS NAME JAMES 0 32 HAS NAME FORD 0 ), HAS NAME MILLER PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. LOCATION OF LOCAL SUBPROGRA)S: ANY LOCAL SUBPROGRAM MUST BE DECLARED AT THE END OF THE DECLARATIVE SECTION. S"L4 DECLARE 2 CURSOR C IS SELECT EMPNO$ENAME FROM EMP5 ) V(FORMATTEDNAME VARCHAR2(133)5 , FUNCTION FORMATNAME(P(EMPNO NUMBER$P(ENAME VARCHAR2) . RETURN VARCHAR2 / IS 0 BEGIN 2 RETURN P(EMPNOVVC HAS NAME CVVP(ENAME5 END FORMATNAME5 13 BEGIN 11 FOR C1 IN C 12 LOOP 1) V(FORMATTEDNAME%IFORMATNAME(C1.EMPNO$C1.ENAME)5 1, DBMS(OUTPUT.PUT(LINE(V(FORMATTEDNAME)5 1. END LOOP5 1/ END5 10 / 0)/ HAS NAME SMITH 0, HAS NAME ALLEN 0.21 HAS NAME WARD 0.// HAS NAME JONES 0/., HAS NAME MARTIN 0/ 2 HAS NAME BLA'E 0022 HAS NAME CLAR' 0022 HAS NAME SCOTT

2 ,

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
02) HAS NAME 'ING 02,, HAS NAME TURNER 020/ HAS NAME ADAMS 0 33 HAS NAME JAMES 0 32 HAS NAME FORD 0 ), HAS NAME MILLER PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

2 .

HERE WE MOVED LOCAL SUBPROGRAM FROM BOTTOM TO TOP$RESULTS A COMPILE TIME ERROR. DECLARE FUNCTION FORMATNAME(P(EMPNO NUMBER$P(ENAME VARCHAR2) RETURN VARCHAR2 IS BEGIN RETURN P(EMPNOVVC HAS NAME CVVP(ENAME5 END FORMATNAME5 CURSOR C IS SELECT EMPNO$ENAME FROM EMP5 V(FORMATTEDNAME VARCHAR2(133)5 13 BEGIN 11 FOR C1 IN C 12 LOOP 1) V(FORMATTEDNAME%IFORMATNAME(C1.EMPNO$C1.ENAME)5 1, DBMS(OUTPUT.PUT(LINE(V(FORMATTEDNAME)5 1. END LOOP5 1/# END5 10 / CURSOR C IS SELECT EMPNO$ENAME FROM EMP5 # ERROR 6< 8NK9 2% ORA&3/..3% 8NK9 2$ :D8?>K 1% PLS&3313)% EK:D?K<9;9= <R9 FA>7D8 OCURSORO ER9K 9UB9:<NKS DK9 DT <R9 TD88DENKS% 79SNK T?K:<NDK B6:L6S9 B;6S>6 B;D:9=?;9 TD;> HERE WE HAVE DECLARED LOCAL SUBPROGRAM BEFORE ALL DECLARATIONS& THAT IS WRONG. FOR+ARD DECLARATION: 1 2 ) , . / 0 2

DECLARE V(TEMPVAL NUMBER(13)%I.5 PROCEDURE A(P(CTR IN OUT NUMBER) IS BEGIN DBMS(OUTPUT.PUT(LINE(CA(CVVP(CTRVVC)C)5 IF P(CTR 4 3 THEN B(P(CTR)5 P(CTR%IP(CTR&15 END IF5 13 END A5 11 &&LOCAL PROCEDURE B THAT CALLS PROCEDURE A IN TOP A CALLS B PROCEDURE. 12 PROCEDURE B(P(CTR IN OUT NUMBER) IS 1) BEGIN 1, DBMS(OUTPUT.PUT(LINE(CB(CVVP(CTRVVC)C)5 1. P(CTR%IP(CTR&15 1/ A(P(CTR)5 10 END B5 12 BEGIN 1 B(V(TEMPVAL)5 23# END5 S"L4 / B(P(CTR)5 # ERROR 6< 8NK9 0% ORA&3/..3% 8NK9 0$ :D8?>K 1% PLS&33231% N=9K<NTN9; CBC >?F< 79 =9:86;9=

1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ORA&3/..3% 8NK9 0$ :D8?>K 1% PL/S"L% S<6<9>9K< NSKD;9= DECLARE V(TEMPVAL NUMBER(13)%I.5 && TO SLOVE THE PROBLEM THAT WE ENCOUNTERED ABOVE. && FORWARD DECLARATION OF PROCEDURE B. PROCEDURE B(P(CTR IN OUT NUMBER)5 PROCEDURE A(P(CTR IN OUT NUMBER) IS BEGIN DBMS(OUTPUT.PUT(LINE(CA(CVVP(CTRVVC)C)5 IF P(CTR 4 3 THEN 13 B(P(CTR)5 11 P(CTR%IP(CTR&15 12 END IF5 1) END A5 1, &&LOCAL PROCEDURE B THAT CALLS PROCEDURE A IN TOP A CALLS B PROCEDURE. 1. PROCEDURE B(P(CTR IN OUT NUMBER) IS 1/ BEGIN 10 DBMS(OUTPUT.PUT(LINE(CB(CVVP(CTRVVC)C)5 12 P(CTR%IP(CTR&15 1 A(P(CTR)5 23 END B5 21 BEGIN 22 B(V(TEMPVAL)5 2)# END5 2, / B(.) A(,) B(,) A()) B()) A(2) B(2) A(1) B(1) A(3) PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 2 ) , . / 0 2

2 /

O*ERLOADING OF LOCAL SUBPROGRA)S:

1 DECLARE 2 && OVERLOADING OF LOCAL SUBPROGRAMS ) , . / PROCEDURE LOCALPROC(P(PARAMETER IN NUMBER) IS BEGIN DBMS(OUTPUT.PUT(LINE(P(PARAMETER)5 END LOCALPROC5

0 PROCEDURE LOCALPROC(P(PARAMETER IN VARCHAR2) IS 2 BEGIN DBMS(OUTPUT.PUT(LINE(P(PARAMETER)5 13 END LOCALPROC 5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
11 BEGIN 12 LOCALPROC(12),.)5 1) LOCALPROC(CPAVANC)5 1,# END5 S"L4 / 12),. PAVAN PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

2 0

SUBPROGRA)S DEPENDENCIES: S"L4 CREATE TABLE EMP1 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 CREATE TABLE TEMP(TABLE 2 (V(EMPNO NUMBER)5 T6789 :;96<9=.

1 CREATE OR REPLACE PROCEDURE RAISE(SAL 2 (P(EMPNO IN NUMBER) ) AS , BEGIN . UPDATE EMP1 / SET SALISALJ133 0 WHERE EMPNOIP(EMPNO5 2# END5 / P;D:9=?;9 :;96<9=.

S"L4 CREATE OR REPLACE PROCEDURE MAINPROC 2 AS ) CURSOR C IS SELECT EMPNO FROM EMP15 , BEGIN . FOR C1 IN C LOOP

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
/ RAISE(SAL(C1.EMPNO)5 0 INSERT INTO TEMP(TABLE VALUES (C1.EMPNO)5 2 END LOOP5 END5 13 / P;D:9=?;9 :;96<9=.

2 2

1 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS 2 FROM USER(OBJECTS )# WHERE OBJECT(NAME IN (CRAISE(SALC$CMAINPROCC) S"L4 / OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& MAINPROC PROCEDURE VALID RAISE(SAL PROCEDURE VALID

S"L4 ALTER TABLE EMP1 2 ADD ADDRESS VARCHAR2(13)5 T6789 68<9;9=. WHEN EVER YOU ALTERED THE TABLE EMP1 THAT WAS USED BY BOTH RAISE(SAL$ MAINPROC PROCEDURES BOTH PROCEDURES STATUS WAS CHANGED TO INVALID. S"L4 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS 2 FROM USER(OBJECTS ) WHERE OBJECT(NAME IN (CRAISE(SALC$CMAINPROCC)5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& MAINPROC PROCEDURE INVALID RAISE(SAL PROCEDURE INVALID

AUTO)ATIC RECO)PILATION: WHEN EVER YOU CALL BOTH PROCEDURES AT THAT TIME BOTH PROCEDURES ARE COMPILED AND THEIR STATUS CHANGED TO VALID. S"L4 BEGIN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 MAINPROC5 ) END5 , / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

S"L4 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS 2 FROM USER(OBJECTS ) WHERE OBJECT(NAME IN (CRAISE(SALC$CMAINPROCC)5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& MAINPROC PROCEDURE VALID RAISE(SAL PROCEDURE VALID

WHEN EVER YOU CALL THE PROCEDURE AT THAT TIME IT WILL BE RECOMPILED. PAC-AGES AND DEPENDENCIES: 1 CREATE TABLE DEPT1 2 AS )# SELECT # FROM DEPT S"L4 / T6789 :;96<9=. S"L4 DELETE FROM DEPT15 , ;DEF =989<9=. S"L4 CREATE OR REPLACE PAC'AGE DEPTPAC'AGE AS 2 PROCEDURE ADDDEPT(P(DEPTNO IN DEPT1.DEPTNO-TYPE$ ) P(DNAME IN DEPT1.DNAME-TYPE$ , P(LOC IN DEPT1.LOC-TYPE)5 . END DEPTPAC'AGE5 / / P6:L6S9 :;96<9=.

1 CREATE OR REPLACE PAC'AGE BODY DEPTPAC'AGE AS

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 PROCEDURE ADDDEPT(P(DEPTNO IN DEPT1.DEPTNO-TYPE$ ) P(DNAME IN DEPT1.DNAME-TYPE$ , P(LOC IN DEPT1.LOC-TYPE) . IS / BEGIN 0 INSERT INTO DEPT1 2 VALUES (P(DEPTNO$P(DNAME$P(LOC)5 13 END ADDDEPT5 11# END DEPTPAC'AGE5 12 / P6:L6S9 7D=A :;96<9=. 1 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS FROM USER(OBJECTS 2# WHERE OBJECT(NAME I CDEPTPAC'AGEC S"L4 / OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& DEPTPAC'AGE PAC'AGE VALID DEPTPAC'AGE PAC'AGE BODY VALID

)33

S"L4 DROP TABLE DEPT15 T6789 =;DBB9=. WHENEVER WE DROP TABLE DEPT1 BOTH PAC'AGE HEADER AND PAC'AGE BODY STATUS WAS CHANGED TO INVALID.BCOZ BOTH HEADER AND BODY WERE USING THE DEPT1 TABLE.

S"L4 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS FROM USER(OBJECTS 2 WHERE OBJECT(NAME I CDEPTPAC'AGEC5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& DEPTPAC'AGE PAC'AGE INVALID DEPTPAC'AGE PAC'AGE BODY INVALID

S"L4 CREATE TABLE DEPT1 2 AS ) SELECT # FROM DEPT5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
T6789 :;96<9=. 1 CREATE OR REPLACE PAC'AGE DEPTPAC'AGE AS 2 PROCEDURE ADDDEPT(P(DEPTNO IN NUMBER$ ) P(DNAME IN VARCHAR2$ , P(LOC IN VARCHAR2)5 .# END DEPTPAC'AGE5 S"L4 / P6:L6S9 :;96<9=. 1 CREATE OR REPLACE PAC'AGE BODY DEPTPAC'AGE AS 2 PROCEDURE ADDDEPT(P(DEPTNO IN NUMBER$ ) P(DNAME IN VARCHAR2$ , P(LOC IN VARCHAR2) . IS / BEGIN 0 INSERT INTO DEPT1 2 VALUES (P(DEPTNO$P(DNAME$P(LOC)5 13 END ADDDEPT5 11# END DEPTPAC'AGE5 S"L4 / P6:L6S9 7D=A :;96<9=.

)31

S"L4 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS FROM USER(OBJECTS 2 WHERE OBJECT(NAME I CDEPTPAC'AGEC5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& DEPTPAC'AGE PAC'AGE VALID DEPTPAC'AGE PAC'AGE BODY VALID

S"L4 DROP TABLE DEPT15 T6789 =;DBB9=. HERE I HAVE DROPED DEPT1 THEN PAC'AGE HEADERS STATUS WAS NOT CHANGED TO INVALID ONLY PAC'AGE BODY STATUS WAS CHANGED TO INVALID.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS FROM USER(OBJECTS 2 WHERE OBJECT(NAME I CDEPTPAC'AGEC5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& DEPTPAC'AGE PAC'AGE VALID DEPTPAC'AGE PAC'AGE BODY INVALID

)32

S"L4 CREATE TABLE SIMPLE(TABLE 2 (F1 NUMBER)5 T6789 :;96<9=. S"L4 CREATE OR REPLACE PAC'AGE DEPENDEE AS 2 PROCEDURE E!AMPLE(P(VAL IN NUMBER)5 ) END DEPENDEE5 , / P6:L6S9 :;96<9=. 1 CREATE OR REPLACE PAC'AGE BODY DEPENDEE AS 2 PROCEDURE E!AMPLE(P(VAL IN NUMBER) IS ) BEGIN , INSERT INTO SIMPLE(TABLE VALUES(P(VAL)5 . END E!AMPLE5 /# END DEPENDEE5 S"L4 / P6:L6S9 7D=A :;96<9=. S"L4 CREATE OR REPLACE PROCEDURE DEPENDER(P(VAL IN NUMBER) AS 2 BEGIN ) DEPENDEE.E!AMPLE(P(VALJ1)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
, END DEPENDER5 . / P;D:9=?;9 :;96<9=.

)3)

S"L4 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS 2 FROM USER(OBJECTS ) WHERE OBJECT(NAME IN (CDEPENDEEC$CDEPENDERC$CSIMPLE(TABLEC)5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& SIMPLE(TABLE TABLE VALID DEPENDER PROCEDURE DEPENDEE PAC'AGE DEPENDEE PAC'AGE BODY VALID VALID VALID

HERE I CHANGED PAC'AGE BODY. 1 CREATE OR REPLACE PAC'AGE BODY DEPENDEE AS 2 PROCEDURE E!AMPLE(P(VAL IN NUMBER) IS ) BEGIN , &&HERE I CHANGED TO P(VAL TO P(VAL&1 . INSERT INTO SIMPLE(TABLE VALUES(P(VAL&1)5 / END E!AMPLE5 0# END DEPENDEE5 S"L4 / P6:L6S9 7D=A :;96<9=. S"L4 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS 2 FROM USER(OBJECTS ) WHERE OBJECT(NAME IN (CDEPENDEEC$CDEPENDERC$CSIMPLE(TABLEC)5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& SIMPLE(TABLE TABLE VALID DEPENDER PROCEDURE DEPENDEE PAC'AGE DEPENDEE PAC'AGE BODY VALID VALID VALID

HERE DEPENDER IS STILL VALID. HERE PAC'AGE HEADER IS VALID.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
IF YOU DROP THE TABLE IT ONLY INVALIDATES THE PAC'AGE BODY. S"L4 DROP TABLE SIMPLE(TABLE5 T6789 =;DBB9=. S"L4 SELECT OBJECT(NAME$OBJECT(TYPE$STATUS 2 FROM USER(OBJECTS ) WHERE OBJECT(NAME IN (CDEPENDEEC$CDEPENDERC$CSIMPLE(TABLEC)5 OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE STATUS &&&&&&&&&&&&&&&&&& &&&&&&& DEPENDER PROCEDURE VALID DEPENDEE PAC'AGE DEPENDEE PAC'AGE BODY VALID INVALID

)3,

E/CEPTION PROPAGATION: E!CEPTIONS CAN OCCUR IN THE DECLARATIVE $ THE E!ECUTABLE$ OR THE E!CECUTABLE$ OR THE E!CEPTION SECTION OF A PL/S"L BLOC'. IF E!CEPTION IS RAISED IN THE E!ECUTABLE SECTION OF THE BLOC'$THEN IF HANDLER IS THERE THEN IT WILL BE HANDLED THERE. WHAT IF THERE IS NO HANDLER OR THE E!CEPTION IS RAISED FROM A DIFFERENTSECTION OF THE BLOC'. THE PROCESS THAT GOVERNS THIS IS 'NOWN AS E!CEPTION PROPAGATION. E/CEPTION RAISED IN T.E E/ECUTABLE SECTION: WHEN E!CEPTION IS RAISED IN THE E!ECUTABLE SECTION OF A BLOC'$ PL/S"L USES THE FOLLOWING ALGORITHM TO DETERMINE WHICH E!CEPTION HANDLER TO INVO'E% 1. 2. IF THE CURRENT BLOC' HAS A HANDLER FOR THE E!CEPTION$E!ECUTE IT AND COMPLETE THE BLOC' SUCESSFULLY.CONTROL THEN PASSES TO ENCLOSING BLOC'. IF THERE IS NO HANDLER FOR THE CURRENT E!CEPTION$PROPAGATE THE E!ECPTION BY RAISING IT IN THE ENCLOSING BLOC'. STEP 1 WILL THEN BE E!ECUTED FOR THE ENCLOSING BLOC'. IF THERE IS NO ENCLOSING BLOC'$ THE E!CEPTION WILL BE PROPAGATED OUT TO THE CALLING ENVIRONMENT$SUCH AS S"L#PLUS.

DECLARE *..BEGIN OUTER BLOC'. *.. BEGIN *. *. DECLARE *.BEGIN INNER BLOC' 1 . *. BEGIN *. *. END5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
*. BEGIN *.BEGIN INNER BLOC' 2. WHICH IS NOT HAVING DECLARATIVE BLOC'. *. *. END5 *. *.END OF OUTER BLOC'. END5 IN THE ABOVE BOTH INNER BLOC' 1 AND INNER BLOC' 2 ARE ENCLOSED BY OUTER BLOC'. IF ANY E!CEPTION RAISED IN INNER BLOC'S THAT WILL BE PROPAGATED TO OUTER BLOC'.

)3.

PROPAGATION E/A)PLE:7

DECLARE A E!CEPTION5 BEGIN

BEGIN RAISE A5 E!CEPTION WHEN A THEN * END5

RAISED HERE. HANDLED HERE ONLY.

I Soft Solutio ! "B# $%&'(


END5

STRUCTURED QUERY LANGUAGE

ORACLE

)3/

PROPAGATION E/A)PLE:6

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DECLARE A E!CEPTION5 B E!CEPTION5 BEGIN
BEGIN RAISE B5 E!CEPTION RAISED HERE WHEN A OTHERS NO HANDLER. *.. THROWNTO END5 OUTER BLOC'.

)30

IN THIS E!AMPLE $ RULE 2 IS APPLIED FOR THE SUB&BLOC'. THE E!CEPTION IS PROPAGATED TO THE ENCLOSING BLOC'$ WHERE RULE 1 IS APPLIED. THE ENCLOSING BLOC' THEN COMPLETES SUCEESFULLY.

HERE E!CEPTION HANDLED. E!CEPTION WHEN B THEN * END5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE

)32

PROPAGATION E/A)PLE:= HERE RULE 2 IS APPLIED FOR THE SUBBLOC'. THE E!CEPTION IS PROPAGATED TO THE ENCLOSING BLOC'$ WHERE THERE IS STILL NO HANDLER FOR IT. RULE 2 IS APPLIED AGAIN$ AND THE ENCLOSING BLOC' COMPLETES UNSUCCESSFULLY WITH AN UNHANDLED E!CEPTION.

DECLARE A E!CEPTION5 B E!CEPTION5 C E!CEPTION5 BEGIN

E!CEPTION C IS RAISED HERENO HANDLER. THROWN TOOUTER BLOC'.


BEGIN RAISE C5 E!CEPTION WHEN A OTHERS *.. HANDLER END5 FOR C .

HERE ALSO NO E!CEPTION E!CEPTION B THEN I Soft Solutio WHEN ! "B# $%&'( * END5

STRUCTURED QUERY LANGUAGE

ORACLE

)3

E/CEPTION RAISED IN T.E DECLARATI*E SECTION: IF AN ASSIGNMENT IN THE DECLARATIVE SECTION RAISES AN E!CEPTION$ THE E!CEPTION IS IMMEDIATELY PROPAGATED TO THE ENCLOSING BLOC'. ONCE THERE $ THE RULES IN GIVEN IN THE PREVIOUS SECTION ARE APPLIED TO PROPAGATE THE E!CEPTION FURTHER. EVEN IF THERE IS A HANDLER IN THE CURRENT BLOC'$ IT IS NOT E!ECUTED. PROPAGATION E/A)PLE:'

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DECLARE V(NUMBERS NUMBER()) %I GABC5 && E!CEPTION IS RAISED HERE.EVEN THOUGH BLOC' HAS WHEN OTHERS IT WONT HANDLE THIS E!CEPTION. THE BLOC' COMPLETES UNSUCCESSFULLY. BEGIN **. ** E!CEPTION WHEN OTHERS THEN ** END5

)13

PROPAGATION E/A)PLE:& SIMILAR TO E!AMPLE ,$ THE VALUE(ERROR E!CEPTION IS RAISED IN THE DECLARATIVE SECTIONOF THE INNER BLOC'. THE E!CEPTION IS THEN IMMEDIATELY PROPAGATED TO THE OUTER BLOC'. BECAUSE THE OUTER BLOC' HAS AN OTHERS E!CEPTION HANDLER$ THE E!CEPTION IS HANDLED AND THE OUTER BLOC' COMPLETES SUCCESSFULLY.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DECLARE BEGIN DECLARE V(NUMBERS NUMBER()) %IABC5 BEGIN *. E!CEPTION WHEN OTHERS THEN ** END5

)11

E!CEPTION WHEN OTHERS THEN *. END5

E/CEPTION RAISED IN T.E E/CEPTION SECTION: E!CEPTIONS CAN ALSO BE RAISED WHILE IN AN E!CEPTION HANDLER$ EITHER E!PLICITLY VIA THE RAISE STATEMENT OR IMPLICITLY VIA RUNTIME ERROR. IN THIS CASE THE E!CEPTION IS PROPAGATED TO THE ENCLOSING BLOC'.$ LI'E E!CEPTIONS RAISED IN THE DECLARATIVE SECTION. PROPAGATION E/A)PLE:O

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DECLARE A E!CEPTION5 B E!CEPTION5 BEGIN RAISE A5&& E!CEPTION IS RAISED HERE. E!CEPTION WHEN A THEN RAISE B5&&E!CEPTION IS HANDLED HERE AND B IS RAISED HERE. WHEN B THEN *.aEVEN THOUGH FOR B E!CEPTION HANDLER IS THERE IT WONT E!ECUTE. THE E!CEPTION IS PROPAGATED TO THE OUTER BLOC'. END5 && THE BLOC' COMPLETES UN SUCCESSFULLY WITH UNHANDLED E!CEPTION.

)12

PROPAGATION E/A)PLE:P

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DECLARE BEGIN DECLARE A E!CEPTION5 B E!CEPTION5 BEGIN RAISE A5&&E!CEPTION IS RAISED HERE. E!CEPTION WHEN A THEN 1 A IS HANDLED HERE AND B IS RAISED HERE. RAISE B5 EVEN THOUGH IT HAS HANDLER BLOC' IN THIS BLOC'. IT WONT BE E!ECUTED HERE. IT IS PROPAGATED TO THE OUTER BLOC'. WHEN B THEN *. END5

)1)

E!CEPTION B IS HANDLED IN THE OUTER BLOC'. E!CEPTION WHEN B THEN *. END5 THE BLOC' COMPLETES SUCCESSFULLY AND CONTROL PASSES TO THE CALLING ENVIRONMENT.

ENABLING A CONSTRAINT:

S"L4 CREATE TABLE E!CE(TAB 2 (ROW(ID ROWID$ ) OWNER VARCHAR2()3)$ , TABLE(NAME VARCHAR2()3)$ . CONSTRAINT VARCHAR2()3))5 T6789 :;96<9=. S"L4 CREATE TABLE ENABLE(E!EC 2 (EMPNO NUMBER(13) PRIMARY 'EY$ ) ENAME VARCHAR2(13) )5 T6789 :;96<9=. S"L4 INSERT INTO ENABLE(E!EC 2 VALUES ) (1$CPAVANC)5 1 ;DE :;96<9=. 1 INSERT INTO ENABLE(E!EC 2 VALUES )# (2$C'UMARC) S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 ;DE :;96<9=. 1 INSERT INTO ENABLE(E!EC 2 VALUES )# (2$C'UMARC) S"L4 / INSERT INTO ENABLE(E!EC # ERROR 6< 8NK9 1% ORA&33331% ?KNP?9 :DKF<;6NK< (D.SYS(C33202)) QND86<9= 1 ALTER TABLE ENABLE(E!EC 2# DISABLE PRIMARY 'EY ) / T6789 68<9;9=. S"L4 INSERT INTO ENABLE(E!EC 2 VALUES ) (2$CBALAJIC)5 1 ;DE :;96<9=. 1 INSERT INTO ENABLE(E!EC 2 VALUES )# (2$CGAYATRIC) , / 1 ;DE :;96<9=.

)1,

1 INSERT INTO ENABLE(E!EC 2 VALUES )# ()$CGAYATRIC) S"L4 / 1 ;DE :;96<9=. S"L4 ALTER TABLE ENABLE(E!EC 2 ENABLE PRIMARY 'EY5 ALTER TABLE ENABLE(E!EC # ERROR 6< 8NK9 1% ORA&32,)0% :6KKD< Q68N=6<9 (D.SYS(C33202)) & B;N>6;A L9A QND86<9= S"L4 ALTER TABLE ENABLE(E!EC 2 ENABLE PRIMARY 'EY ) E!CEPTIONS INTO E!CE(TAB5 ALTER TABLE ENABLE(E!EC # ERROR 6< 8NK9 1% ORA&32,)0% :6KKD< Q68N=6<9 (D.SYS(C33202)) & B;N>6;A L9A QND86<9= S"L4 SELECT # FROM E!CE(TAB5 ROW(ID OWNER TABLE(NAME &&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CONSTRAINT &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
AAAH/PAABAAAPCAAAB D SYS(C33202) AAAH/PAABAAAPCAAAC D SYS(C33202) AAAH/PAABAAAPCAAAD D SYS(C33202) ENABLE(E!EC ENABLE(E!EC ENABLE(E!EC

)1.

1 DELETE FROM ENABLE(E!EC 2# WHERE ROWID IN (SELECT ROW(ID FROM E!CE(TAB) S"L4 / ) ;DEF =989<9=. S"L4 SELECT # FROM ENABLE(E!EC5 EMPNO ENAME &&&&&&&&&& &&&&&&&&&& 1 PAVAN ) GAYATRI S"L4 ALTER TABLE ENABLE(E!EC 2 ENABLE PRIMARY 'EY5 T6789 68<9;9=. )ERGE STATE)ENT: 1 CREATE TABLE EMP(COMPANY 2 (ENAME VARCHAR2(13)$ ) CNAME VARCHAR2(13)$ ,# SAL NUMBER(13)) . / T6789 :;96<9=. 1 CREATE TABLE EMP(ALL 2 (ENAME VARCHAR2(13)$ )# SAL NUMBER(13)) , / T6789 :;96<9=. S"L4 INSERT INTO EMP(COMPANY 2 VALUES ) (CANILC$CACCC$1.33)5 1 ;DE :;96<9=. 1 INSERT INTO EMP(COMPANY 2 VALUES )# (CSHAN'ERC$CTATAC$2333) , / 1 ;DE :;96<9=. 1 INSERT INTO EMP(COMPANY 2 VALUES )# (CJAYAC$CCMCC$1233) S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 ;DE :;96<9=. 1 INSERT INTO EMP(COMPANY 2 VALUES )# (CSUNILC$CCMCC$1033) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO EMP(COMPANY 2 VALUES )# (CVIJAYC$CTATAC$.333) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO EMP(COMPANY 2 VALUES )# (CPRA'ASHC$CTATAC$)333) , / 1 ;DE :;96<9=. 1 INSERT INTO EMP(COMPANY 2 VALUES )# (CAJAYC$CACCC$2333) S"L4 / 1 ;DE :;96<9=. S"L4 COMMIT5 CD>>N< :D>B89<9. S"L4 INSERT INTO EMP(ALL 2 VALUES ) (CSHAN'ERC$2333)5 1 ;DE :;96<9=. 1 INSERT INTO EMP(ALL 2 VALUES )# (CJAYAC$1233) , / 1 ;DE :;96<9=. 1 INSERT INTO EMP(ALL 2 VALUES )# (CSUNILC$1033) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO EMP(ALL 2 VALUES )# (CVIJAYC$.333) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO EMP(ALL

)1/

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 VALUES )# (CPRA'ASHC$)333) S"L4 / 1 ;DE :;96<9=. S"L4 COMMIT5 CD>>N< :D>B89<9. S"L4 SELECT # FROM EMP(COMPANY5 ENAME CNAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& ANIL ACC 1.33 SHAN'ER TATA JAYA CMC 1233 SUNIL CMC 1033 VIJAY TATA .333 PRA'ASH TATA AJAY ACC 2333 0 ;DEF F989:<9=. SAL 2333

)10

)333

S"L4 SELECT # FROM EMP(ALL5 ENAME &&&&&&&&&& &&&&&&&&&& SHAN'ER JAYA SUNIL VIJAY PRA'ASH SAL 2333 1233 1033 .333 )333

S"L4 MERGE INTO EMP(ALL A 2 USING EMP(COMPANY B ) ON(A.ENAMEIB.ENAME) , WHEN MATCHED THEN . UPDATE SET A.SALIB.SALJ133 / WHEN NOT MATCHED THEN 0 INSERT(ENAME$SAL) 2 VALUES (ENAME$SAL)5 0 ;DEF >9;S9=.

S"L4 SELECT # FROM EMP(COMPANY5 ENAME CNAME SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& ANIL ACC 1.33 SHAN'ER TATA JAYA CMC 1233 SUNIL CMC 1033 VIJAY TATA .333 PRA'ASH TATA AJAY ACC 2333 0 ;DEF F989:<9=. S"L4 SELECT # FROM EMP(ALL5

2333

)333

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ENAME SAL &&&&&&&&&& &&&&&&&&&& SHAN'ER 2133 JAYA 1 33 SUNIL 1233 VIJAY .133 PRA'ASH )133 AJAY 2333 ANIL 1.33 0 ;DEF F989:<9=.

)12

HERE DATA FROM TABLE EMP(COMPANY IS MERGED WITH DATA OF TABLE EMP(ALL.AS A RESULT THE TABLE EMP(ALL HAS BEEN CHANGED. ANIL IS NOT PRESENT IN THE TABLE EMP(ALL ACCORDING TO MATCH CONDITION$ THEN THE ROW IS INSERTED INTO EMP(ALL TABLE USING INSERT STATEMENT. SHAN'ER IS PRESENT IN THE BOTH THE TABLES THAT IS WHY ACCORDING TO CONDITION IT WAS UPDATED.

FLAS. BAC- QUERIES:

1 CREATE TABLE CHILD 2 (A NUMBER(13)$ )# B NUMBER(13)) S"L4 / T6789 :;96<9=. S"L4 BEGIN 2 FOR I IN 1...3 LOOP ) INSERT INTO CHILD VALUES(1$I)5 , END LOOP5 . END5 / / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 COMMIT5 CD>>N< :D>B89<9. S"L4 SELECT COUNT(#) FROM CHILD5 COUNT(#) &&&&&&&&&& .3 S"L4 DELETE FROM CHILD5 .3 ;DEF =989<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 COMMIT5 CD>>N< :D>B89<9. S"L4 SELECT COUNT(#) FROM CHILD5 COUNT(#) &&&&&&&&&& 3 S"L4 E!ECUTE DBMS(FLASHBAC'.ENABLE(AT(TIME(SYSDATE & 13/1,,3)5 BEGIN DBMS(FLASHBAC'.ENABLE(AT(TIME(SYSDATE & 13/1,,3)5 END5 # ERROR 6< 8NK9 1% ORA&3/..3% 8NK9 1$ :D8?>K 0% PLS&33231% N=9K<NTN9; CDBMS(FLASHBAC'C >?F< 79 =9:86;9= ORA&3/..3% 8NK9 1$ :D8?>K 0% PL/S"L% S<6<9>9K< NSKD;9= S"L4 CONN EK<9; ?F9;&K6>9% SYS AS SYSDBA CDKK9:<9=. S"L4 GRANT ALL ON DBMS(FLASHBAC' TO D5 G;6K< F?::99=9=. S"L4 CONN EK<9; ?F9;&K6>9% D CDKK9:<9=. S"L4 E!ECUTE DBMS(FLASHBAC'.ENABLE(AT(TIME(SYSDATE & 13/1,,3)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT COUNT(#) FROM CHILD5 COUNT(#) &&&&&&&&&& .3 S"L4 INSERT INTO CHILD VALUES 2 (11$11)5 INSERT INTO CHILD VALUES # ERROR 6< 8NK9 1% ORA&32122% DB9;6<NDK KD< F?BBD;<9= ERN89 NK F86FR76:L >D=9 S"L4 E!ECUTE DBMS(FLASHBAC'.DISABLE5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT COUNT(#) FROM CHILD5 COUNT(#) &&&&&&&&&& 3 S"L4 INSERT INTO CHILD VALUES 2 (11$11)5 1 ;DE :;96<9=.

)1

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
GENERATING PRI)ARY -EY USING TRIGGER: S"L4 CREATE TABLE DEPT(DUP 2 AS ) SELECT # FROM DEPT5 T6789 :;96<9=. S"L4 DELETE FROM DEPT(DUP5 , ;DEF =989<9=. S"L4 COMMIT5 CD>>N< :D>B89<9. 1 CREATE SE"UENCE DEPT(DUP(SE" 2 INCREMENT BY 13 )# START WITH 13 S"L4 / S9P?9K:9 :;96<9=. S"L4 CREATE OR REPLACE TRIGGER DEPTNO(GENERATION 2 BEFORE INSERT ) ON DEPT(DUP , FOR EACH ROW . DECLARE / PRIMARY('EY(VALUE VARCHAR2(13)5 0 BEGIN 2 SELECT DEPT(DUP(SE".NE!TVAL INTO PRIMARY('EY(VALUE FROM DUAL5 %NEW.DEPTNO %I CDC VV TO(CHAR(PRIMARY('EY(VALUE)5 13 END5 11 / T;NSS9; :;96<9=. S"L4 INSERT INTO DEPT(DUP 2 (DNAME$LOC) ) VALUES , (CACCOUNTINGC$CNEWYOR'C)5 INSERT INTO DEPT(DUP # ERROR 6< 8NK9 1% ORA&3/.32% PL/S"L% K?>9;N: D; Q68?9 9;;D;% :R6;6:<9; <D K?>79; :DKQ9;FNDK 9;;D; ORA&3/.12% 6< OD.DEPTNO(GENERATIONO$ 8NK9 . ORA&3,322% 9;;D; =?;NKS 9U9:?<NDK DT <;NSS9; CD.DEPTNO(GENERATIONC S"L4 ALTER TABLE DEPT(DUP

)23

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 MODIFY DEPTNO VARCHAR2(13)5 T6789 68<9;9=. S"L4 INSERT INTO DEPT(DUP 2 (DNAME$LOC) ) VALUES , (CACCOUNTINGC$CNEWYOR'C)5 1 ;DE :;96<9=. S"L4 SELECT # FROM DEPT(DUP5 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& D23 ACCOUNTING NEWYOR' S"L4 INSERT INTO DEPT(DUP 2 (DNAME$LOC) ) VALUES , (CACCOUNTINGC$CNEWYOR'C) . 1 INSERT INTO DEPT(DUP 2 (DNAME$LOC) ) VALUES ,# (CSALESC$CNEWYOR'C) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO DEPT(DUP 2 (DNAME$LOC) ) VALUES ,# (CCOMPUTERSC$CNEWYOR'C) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT # FROM DEPT(DUP5 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& D23 ACCOUNTING NEWYOR' D)3 SALES NEWYOR' D,3 COMPUTERS NEWYOR' S"L4 DELETE FROM DEPT(DUP5 ) ;DEF =989<9=. +OR-ING +IT. LARGE OBJECTS:

)21

FOUR LOB DATATYPES ARE: BLOB( CLOB( NCLOB( BFILE(

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
BLOB: BINARY LARGE OBJECT( IT IS USED TO STORE LARGE BINARY OBJECTS IN THE DATABASE. MA!SIZE THAT CAN BE STORED IS , GB. CLOB: C.ARACTER LARGE OBJECT( IT IS SIMILAR TO LONG DATATYPE. MA!IMUM SIZE IS , GB.CLOB IS USED TO STORE LARGE BLOC'S OF SINGLE 1 BYTE CHARACTER DATA IN THE DATABASE. NCLOB: NATIONAL C.ARACTER LARGE OBJECT( THE NCLOB DATA TYPE IS USED TO STORE LARGE BLOC'S OF FI!ED WIDTH SINGLE&BYTE OR MULTI 1 BYTE CHARACTER DATA IN THE DATABASE BASED ON THE NATIONAL LANGUAGE CHARACTER. MA!SIZE , GB. BFILE:

)22

IS USED TO STORE LARGE BINARY OBJECTS IN OPERATING SYSTEM FILES OUTSIDE THE DATABASE. BFILE COLUMN STORES A FILE LOCATOR$WHICH POINTS TO THE LARGE BINARY FILE ON THE SERVER. THESE FILES ARE READ ONLY. VIDEOS MAY BE STORED IN THIS WAY.

CREATING TABLE +IT. LOB COLU)NS: S"L4 CREATE TABLE AIRBUS(DESC 2 (AIRBUSNO CHAR(13)$ ) AIRBUS(DET BFILE$ , AIRBUS(PROFILE CLOB)5 T6789 :;96<9=. CREATING DIRECTORY FOR BFILE COLU)N: S"L4 CREATE OR REPLACE DIRECTORY GOD AS 2 CC%ZBALAJIC5 DN;9:<D;A :;96<9=. INSERTING *ALUES IN TO TABLE +IT. LOB COLU)NS: 1 INSERT INTO AIRBUS(DESC 2 VALUES )# (CAB31C$BFILENAME(CGODC$CAIRBUS(DESC1.DOCC)$CTHE DESCRIPTION OF THE PLANE IS AS FOLLOWS%C) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO AIRBUS(DESC 2 VALUES )# (CAB32C$BFILENAME(CGODC$CAIRBUS(DESC2.DOCC)$CTHE DESCRIPTION OF THE PLANE IS AS FOLLOWS%C) , / 1 ;DE :;96<9=. 1 INSERT INTO AIRBUS(DESC 2 VALUES

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
)# (CAB3)C$BFILENAME(CGODC$CAIRBUS(DESC).DOCC)$CTHE DESCRIPTION OF THE PLANE IS AS FOLLOWS%C) S"L4 / 1 ;DE :;96<9=. S"L4 COMMIT5 CD>>N< :D>B89<9.

)2)

SELECTING *ALUES FRO) T.E TABLE +IT. LOB COLU)NS: THE DATA FROM LOBCS CANNOT BE DISPLAYED BY USING SELECT STATEMENT$E!CEPT FOR THE CLOBDATATYPE. S"L4 SELECT AIRBUSNO$AIRBUS(PROFILE FROM AIRBUS(DESC5 AIRBUSNO AIRBUS(PROFILE &&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& AB31 THE DESCRIPTION OF THE PLANE IS AS FOLLOWS% AB32 THE DESCRIPTION OF THE PLANE IS AS FOLLOWS% AB3) THE DESCRIPTION OF THE PLANE IS AS FOLLOWS% NORMALLY WHEN YOU UPDATE A VALUE THE ROW BEING UPDATED GETS AUTOMATICALLY LOC'ED IN THE BAC'GROUND. THE TRANSACTION IS PERFORMED AND THEN THE LOC' IS RELEASED BY ORACLE. BUT$IF YOU HAVE TO UPDATE A LOB VALUE THEN YOU HAVE TO E!PLICITLY LOC' THE ROWS. FOR THE PURPOSE YOU CAN MA'E USE OF THE FOR UPDATE CLAUSE IN THE SELECT STATEMENT. S"L4SELECT AIRBUS(PROFILE FROM AIRBUS(DESC 2 WHERE AIRBUSNOICAB31C ) FOR UPDATE5 AIRBUS(PROFILE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THE DESCRIPTION OF THE PLANE IS AS FOLLOWS% AS THE RECORD FOR AIRBUSNO AB31 HAS BEEN SELECTED FOR UPDATE THE ROW HAS BEEN E!CLUSIVELY LOC'ED. NOW THE ROW CAN BE UPDATED FOR A NEW AIRBUS(PROFILE VALUE.

1 UPDATE AIRBUS(DESC 2 SET AIRBUS(PROFILE I CTHE DESCRIPTION OF THE PLANE IS AS FOLLOWS%LU!URY SEATS IN ) ECONOMY CLASSC ,# WHERE AIRBUSNOICAB31C S"L4 / 1 ;DE ?B=6<9=. TO RELEASE THE LOC'$ FIRE A COMMIT STATEMENT. THIS TYPE OF E!PLICIT LOC'ING IS RE"UIRED ONLY FOR INTERNALLY STORED LOBS USING DBMS(LOB PAC'AGE% THE DBMS(LOB PAC'AGE PROVIDES ROUTINES TO ACCESS BLOBS$CLOBS$NCLOBS AND BFILES. YOU CAN USE DBMS(LOB FOR ACCESS AND MANIPULATION OF SPECIFIC PARTS OF A LOB$ AS WELL AS COMPLETE LOBS. DBMS(LOB CAN READ AS WELL AS MODIFY BLOBS$CLOBS$ AND NCOLBS AND PROVIDE READ ONLY OPERATIONSON BFILES. THE STRING COMPARISON AND MANIPULATION PROCEDURES AND FUNCTIONS AVAILABLE WITHIN DBMS(LOB PAC'AGE ARE LISTED BELOW. READ(

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE

)2,

SUBSTR( INSTR( GETLENGT.( CO)PARE( +RITE( APPEND( ERASE( TRI)( COPY(

ADDITIONAL PROCEDURES AND FUNCTIONS SPECIFIC TO BFILE ARE LISTED BELO+: DB)S2LOB(READ: T.E PARA)ETERS TO BE SPECIFIED IN T.E READ PROCEDURE ARE: FILEOPEN( FILECLOSE( FILECLOSEALL( FILE/ISTS( FILEGETNA)E( FILEOPEN.

LOCATOR FOR THE LOB TO READ. NUMBER OF BYTES OR CHARACTERS TO BE READ. OFFSET IN BYTES(FOR BLOBS) OR CHARACTERS (FOR CLOBS) FROM THE START OF THE LOB.(ORIGIN%1). OUTPUT BUFFER FOR THE READ OPERATION.

T.E FOLLO+ING SELECTS FIRST 7& C.ARACTERS FRO) T.E AIRBUS2PROFILE COLB COLU)N( 1 DECLARE 2 LOC(VAR CLOB5 ) NUM INTEGER5 , OFFSET INTEGER5 . OUTPUT(VAR VARCHAR2(23)5 / BEGIN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
0 NUM%I1.5 2 OFFSET %I15 SELECT AIRBUS(PROFILE INTO LOC(VAR 13 FROM AIRBUS(DESC 11 WHERE AIRBUSNOICAB31C5 12 DBMS(LOB.READ(LOC(VAR$NUM$OFFSET$OUTPUT(VAR)5 1) DBMS(OUTPUT.PUT(LINE(CSTART OF AIRBUS PROFILE C VV OUTPUT(VAR)5 1,# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON S"L4 / START OF AIRBUS PROFILE THE DESCRIPTION PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT AIRBUS(PROFILE FROM AIRBUS(DESC 2 WHERE AIRBUSNO I CAB31C5 AIRBUS(PROFILE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THE DESCRIPTION OF THE PLANE IS AS FOLLOWS%LU!URY SEATS IN ECONOMY CLASS

)2.

DB)S2LOB(SUBSTR:

T.E PARA)ETERS TO BE SPECIFIED IN T.E SUBSTR FUNCTION ARE:

LOCATOR FOR THE LOB TO READ. NUMBER OF BYTES OR CHARACTERS TO BE READ. OFFSET IN BYTES(FOR BLOBS) OR CHARACTERS (FOR CLOBS) FROM THE START OF THE LOB.(ORIGIN%1).

T.E FOLLO+ING CODE SELECTS 76 C.RACTERS FRO) T.E AIRBUS2PROFILE COLU)N STARTING AT T.E 7P T. C.ARACTER(

1 DECLARE 2 LOC(VAR CLOB5 ) NUM INTEGER5 , OFFSET INTEGER5 . OUTPUT(VAR VARCHAR2(23)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
/ BEGIN 0 NUM%I125 2 OFFSET %I105 SELECT AIRBUS(PROFILE INTO LOC(VAR 13 FROM AIRBUS(DESC 11 WHERE AIRBUSNOICAB31C5 12 OUTPUT(VAR%IDBMS(LOB.SUBSTR(LOC(VAR$NUM$OFFSET)5 1) DBMS(OUTPUT.PUT(LINE(CSUBSTRING OF AIRBUS PROFILE C VV OUTPUT(VAR)5 1,# END5 S"L4 / SUBSTRING OF AIRBUS PROFILE OF THE PLANE PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DB)S2LOB(INSTR:

)2/

T.E PARA)ETERS TO BE SPECIFIED IN T.E INSTR FUNCTION ARE:

LOCATOR FOR THE LOB TO READ. PATTERN TO BE TESTED FOR. ABSOLUTE OFFSET IN BYTES(FOR BLOBS) OR CHARACTERS (FOR CLOBS) FROM THE START OF THE LOB. OCCURRENCE NUMBER$START AT 1.

T.E FOLLO+ING CODE SEARC.ES 3AS4 IN T.E CLOB COLU)N( 1 DECLARE 2 LOC(VAR CLOB5 ) PATTERN VARCHAR2(13)5 , OFFSET INTEGER5 . OCCUR(VAR INTEGER5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
/ POSITION INTEGER5 0 BEGIN 2 PATTERN%ICASC5 OFFSET %I15 13 OCCUR(VAR %I15 11 SELECT AIRBUS(PROFILE INTO LOC(VAR 12 FROM AIRBUS(DESC 1) WHERE AIRBUSNOICAB31C5 1, POSITION%IDBMS(LOB.INSTR(LOC(VAR$PATTERN$OFFSET$OCCUR(VAR)5 1. DBMS(OUTPUT.PUT(LINE(CSTRING FOUND AT POSITION% C VV POSITION)5 1/# END5 S"L4 / STRING FOUND AT POSITION% )) PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT AIRBUS(PROFILE FROM AIRBUS(DESC 2 WHERE AIRBUSNO I CAB31C5 AIRBUS(PROFILE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THE DESCRIPTION OF THE PLANE IS AS FOLLOWS%LU!URY SEATS IN ECONOMY CLASS

)20

DB)S2LOB(GETLENGT.: T.E PARA)ETERS TO BE SPECIFIED IN T.E GETLENGT. FUNCTION ARE:

LOCATOR FOR THE LOB WHOSE LENGTH IS TO BE RETURNED.

S"L4 DECLARE 2 LOC(VAR CLOB5 ) LEN INTEGER5 , BEGIN . SELECT AIRBUS(PROFILE INTO LOC(VAR / FROM AIRBUS(DESC 0 WHERE AIRBUSNOICAB31C5 2 LEN%IDBMS(LOB.GETLENGTH(LOC(VAR)5 DBMS(OUTPUT.PUT(LINE(CLENGTH OF THE LOB IS %C VVLEN)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
13 END5 11 / LENGTH OF THE LOB IS %02 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT AIRBUS(PROFILE FROM AIRBUS(DESC 2 WHERE AIRBUSNO I CAB31C5 AIRBUS(PROFILE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THE DESCRIPTION OF THE PLANE IS AS FOLLOWS%LU!URY SEATS IN ECONOMY CLASS

)22

DB)S2LOB(CO)PARE: T.E PARA)ETERS TO BE SPECIFIED IN T.E CO)PARE FUNCTION ARE:

LOB LOCATOR OF FIRST LOB FOR COMPARISON. LOB LOCATOR OF SECOND LOB FOR COMPARISON. NUMBER OF BYTES OR CHRACTERS TO COMPARE OVER. OFFSET IN BYTES(FOR BLOBS) OR CHARACTERS (FOR CLOBS) ON THE FIRST LOB(ORIGIN%1) FOR THE COMPARISON.

OFFSET IN BYTES(FOR BLOBS) OR CHARACTERS (FOR CLOBS) ON THE SECOND LOB(ORIGIN%1) FOR THE COMPARISON.

1 DECLARE 2 LOC1(VAR CLOB5 ) LOC2(VAR CLOB5 , NUM INTEGER5 . OFFSET1 INTEGER5 / OFFSET2 INTEGER5 0 OUTPUT(VAR INTEGER5 2 BEGIN NUM%I)35 13 OFFSET1%I15

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
11 OFFSET2%I15 12 SELECT AIRBUS(PROFILE INTO LOC1(VAR 1) FROM AIRBUS(DESC 1, WHERE AIRBUSNOICAB31C5 1. SELECT AIRBUS(PROFILE INTO LOC2(VAR 1/ FROM AIRBUS(DESC 10 WHERE AIRBUSNOICAB32C5 12 OUTPUT(VAR%IDBMS(LOB.COMPARE(LOC1(VAR$LOC2(VAR$NUM$OFFSET1$OFFSET2)5 1 DBMS(OUTPUT.PUT(LINE(CCOMPARISON VALUE ( 3 IF THE SAME ) IS % C VV OUTPUT(VAR)5

)2

23# END5 21 / COMPARISON VALUE ( 3 IF THE SAME ) IS % 3 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT AIRBUS(PROFILE FROM AIRBUS(DESC 2 WHERE AIRBUSNO IN (CAB31C$CAB32C)5 AIRBUS(PROFILE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THE DESCRIPTION OF THE PLANE IS AS FOLLOWS%LU!URY SEATS IN ECONOMY CLASS THE DESCRIPTION OF THE PLANE IS AS FOLLOWS%

DB)S2LOB(+RITE: T.E PARA)ETERS TO BE SPECIFIED IN T.E +RITE PROCEDURE ARE:

LOB LOCATOR OF INTERNAL LOB TO BE WRITTEN TO. NUMBER OF BYTES OR CHRACTERS TO WRITE OR THAT WERE WRITTEN.. OFFSET IN BYTES(FOR BLOBS) OR CHARACTERS (FOR CLOBS) FROM THE START OF THE LOB(ORIGIN%1) FOR WRITE OPERATION.

INPUT BUFFER FOR THE WRITE OPERATION.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
THE FOLLOWING CODE UPDATES THE VALUE IN THE AIRBUS(PROFILE COLUMN FOR AIRBUSNO GAB32 WITH GLU!URY SEATS. S"L4 DECLARE 2 LOC(VAR CLOB5 ) NUM INTEGER5 , OFFSET INTEGER5 . BUFFER(VAR VARCHAR2(23)5 / BEGIN 0 NUM%I1)5 2 OFFSET %I,)5 BUFFER(VAR%IC%LU!URY SEATSC5 13 SELECT AIRBUS(PROFILE INTO LOC(VAR 11 FROM AIRBUS(DESC 12 WHERE AIRBUSNOICAB32C 1) FOR UPDATE5 1, DBMS(LOB.WRITE(LOC(VAR$NUM$OFFSET$BUFFER(VAR)5 1. COMMIT5 1/ END5 10 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT AIRBUS(PROFILE FROM AIRBUS(DESC 2 WHERE AIRBUSNOICAB32C5 AIRBUS(PROFILE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THE DESCRIPTION OF THE PLANE IS AS FOLLOWS%LU!URY SEATS

))3

DB)S2LOB(APPEND: T.E PARA)ETERS TO BE SPECIFIED IN T.E APPEND PROCEDURE ARE:

LOCATOR FOR THE INTERNAL LOB TO WHICH THE DATA IS TO BE APPENDED. LOCATOR FOR THE INTERNAL LOB FROM WHICH THE DATA IS TO BE READ.

THE FOLLOWING CODE APPENDS THE VALUE IN THE AIRBUS(PROFILE COLUMN IN THE AIRBUS(DESC TABLE FOR AIRBUSNO GABO2 WITH THE VALUE FOR AB31. S"L4 DECLARE

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 DEST(LOC(VAR CLOB5 ) SRC(LOC(VAR CLOB5 , BEGIN . SELECT AIRBUS(PROFILE INTO DEST(LOC(VAR / FROM AIRBUS(DESC 0 WHERE AIRBUSNOICAB32C 2 FOR UPDATE5 SELECT AIRBUS(PROFILE INTO SRC(LOC(VAR 13 FROM AIRBUS(DESC 11 WHERE AIRBUSNOICAB31C5 12 DBMS(LOB.APPEND(DEST(LOC(VAR$SRC(LOC(VAR)5 1) COMMIT5 1, END5 1. / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT AIRBUS(PROFILE FROM AIRBUS(DESC 2 WHERE AIRBUSNOICAB31C5 AIRBUS(PROFILE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THE DESCRIPTION OF THE PLANE IS AS FOLLOWS%LU!URY SEATS IN ECONOMY CLASS S"L4 SELECT AIRBUS(PROFILE FROM AIRBUS(DESC 2 WHERE AIRBUSNOICAB32C5 AIRBUS(PROFILE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THE DESCRIPTION OF THE PLANE IS AS FOLLOWS%LU!URY SEATSTHE DESCRIPTION OF THE PL DB)S2LOB(ERASE: T.E PARA)ETERS TO BE SPECIFIED IN T.E ERASE PROCEDURE ARE:

))1

LOCATOR FOR THE LOB TO BE ERASED. NUMBER OF BYTES(FOR BLOBS) OR CHARACTERS (FOR CLOBS) TO BE ERASED. ABSOLUTE OFFSET FROM THE BEGINNING OF THE LOB IN BYTES(FOR BLOBS) OR CHARACTERS(CLOBS).

THE FOLLOWING CODE ERASES 23 CHARACTERS FROM THE VALUE IN THE GAIRBUS(PROFILE COLUMN IN THE AIRBUS(DESC TABLE FOR GAIRBUSNO ABO2 STARTING WITH THE 13TH CHARACTER. S"L4 DECLARE 2 LOC(VAR CLOB5 ) NUM INTEGER5 , OFFSET INTEGER5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
. BEGIN / NUM%I235 0 OFFSET %I135 2 SELECT AIRBUS(PROFILE INTO LOC(VAR FROM AIRBUS(DESC 13 WHERE AIRBUSNOICAB32C 11 FOR UPDATE5 12 DBMS(LOB.ERASE(LOC(VAR$NUM$OFFSET)5 1) COMMIT5 1, END5 1. / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT AIRBUS(PROFILE FROM AIRBUS(DESC 2 WHERE AIRBUSNOICAB32C5 AIRBUS(PROFILE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THE DESCR IS AS FOLLOWS%LU!URY SEATSTHE DESCRIPTION OF THE PL DB)S2LOB(TRI):

))2

T.E PARA)ETERS TO BE SPECIFIED IN T.E TRI) PROCEDURE ARE:

LOCATOR FOR THE INTERNAL WHOSE LENGTH IS TO BE TRIMMED. NEW$TRIMMED LENGTH OF THE LOB VALUE IN BYTES FOR BLOBS OR CHARACTERS FOR CLOBS.

THE FOLLOWING CODE TRIMS THE VALUE IN THE AIRBUS(PROFILE COLUMN IN THE AIRBUS(DESC TABLE FOR AIRBUSNO ABO2 TO ,3 CHRACTERS. S"L4 DECLARE 2 LOC(VAR CLOB5 ) NEWLEN INTEGER5 , BEGIN . NEWLEN %I,35 / SELECT AIRBUS(PROFILE INTO LOC(VAR 0 FROM AIRBUS(DESC 2 WHERE AIRBUSNOICAB32C FOR UPDATE5 13 DBMS(LOB.TRIM(LOC(VAR$NEWLEN)5 11 COMMIT5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
12 END5 1) / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT AIRBUS(PROFILE FROM AIRBUS(DESC 2 WHERE AIRBUSNOICAB32C5 AIRBUS(PROFILE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THE DESCR IS AS FOLLO DB)S2LOB(COPY:

)))

T.E PARA)ETERS TO BE SPECIFIED IN T.E COPY PROCEDURE ARE:

LOB LOCATOR OF THE COPY TARGET. LOB LOCATOR OF SOURCE FOR THE COPY. NUMBER OF BYTES OR CHARACTERS TO COPY. OFFSET IN BYTES OR CHARACTERS IN THE DESTINATION LOB(ORIGIN%1) FOR THE START OF THE COPY. OFFSET IN BYTES OR CHARACTERS IN THE SOURCE LOB(ORIGIN%1) FOR THE START OF THE COPY.

THE FOLLOWING CODE COPIES THE VALUES IN THE AIRBUS(PROFILE COLUMN IN THE AIRBUS(DESC TABLE FOR AIRBUSNO AB31 TO AB32.

1 DECLARE 2 DEST(LOC(VAR CLOB5 ) SRC(LOC(VAR CLOB5 , NUM INTEGER5 . DEST(OFFSET INTEGER5 / SRC(OFFSET INTEGER5 0 BEGIN 2 NUM%I0)5 DEST(OFFSET %I15 13 SRC(OFFSET %I15 11 SELECT AIRBUS(PROFILE INTO DEST(LOC(VAR 12 FROM AIRBUS(DESC 1) WHERE AIRBUSNOICAB32C 1, FOR UPDATE5 1. SELECT AIRBUS(PROFILE INTO SRC(LOC(VAR 1/ FROM AIRBUS(DESC

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
10 WHERE AIRBUSNOICAB31C5 12 DBMS(LOB.COPY(DEST(LOC(VAR$SRC(LOC(VAR$NUM$DEST(OFFSET$SRC(OFFSET)5 1 COMMIT5 23# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT AIRBUS(PROFILE FROM AIRBUS(DESC 2 WHERE AIRBUSNO IN (CAB31C$CAB32C)5 AIRBUS(PROFILE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& THE DESCRIPTION OF THE PLANE IS AS FOLLOWS%LU!URY SEATS IN ECONOMY CLASS THE DESCRIPTION OF THE PLANE IS AS FOLLOWS%LU!URY SEATS IN ECONOMY CLASS.

)),

USING BFILE RELATED ROUTINES:

1 DECLARE 2 LOC(VAR BFILE5 ) FE!ISTS(VAR INTEGER5 , FOPEN(VAR INTEGER5 . NUM INTEGER5 / OFFSET INTEGER5 0 LEN INTEGER5 2 DIR(ALIAS(VAR VARCHAR2(2.)5 FNAME VARCHAR2(1.)5 13 OUTPUT(VAR LONG5 11 BEGIN 12 SELECT AIRBUS(DET INTO LOC(VAR

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1) FROM AIRBUS(DESC 1, WHERE AIRBUSNOICAB31C5 1. FE!ISTS(VAR %I DBMS(LOB.FILEE!ISTS(LOC(VAR)5 1/ IF FE!ISTS(VARI1 THEN 10 DBMS(OUTPUT.PUT(LINE(CTHE FILE E!ISTSC)5 12 ELSE 1 DBMS(OUTPUT.PUT(LINE(CTHE FILE COULD NOT BE FOUNDC)5

)).

23 END IF5 21# END5 22 / S"L4 / THE FILE E!ISTS PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

1 DECLARE 2 LOC(VAR BFILE5 ) FE!ISTS(VAR INTEGER5 , FOPEN(VAR INTEGER5 . NUM INTEGER5 / OFFSET INTEGER5 0 LEN INTEGER5 2 DIR(ALIAS(VAR VARCHAR2(2.)5 FNAME VARCHAR2()3)5 13 OUTPUT(VAR LONG5 11 BEGIN 12 SELECT AIRBUS(DET INTO LOC(VAR 1) FROM AIRBUS(DESC 1, WHERE AIRBUSNOICAB31C5 1. FE!ISTS(VAR %I DBMS(LOB.FILEE!ISTS(LOC(VAR)5 1/ IF FE!ISTS(VARI1 THEN 10 DBMS(OUTPUT.PUT(LINE(CTHE FILE E!ISTSC)5 12 ELSE 1 DBMS(OUTPUT.PUT(LINE(CTHE FILE COULD NOT BE FOUNDC)5

23 END IF5 21 DBMS(LOB.FILEGETNAME(LOC(VAR$DIR(ALIAS(VAR$FNAME)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
22 DBMS(OUTPUT.PUT(LINE(CFILE NAME IS%C VV DIR(ALIAS(VAR VV C CVV FNAME)5 2)# END5 S"L4 / THE FILE E!ISTS FILE NAME IS%GOD AIRBUS(DESC1.DOC PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 LOC(VAR BFILE5 ) FE!ISTS(VAR INTEGER5 , FOPEN(VAR INTEGER5 . NUM INTEGER5 / OFFSET INTEGER5 0 LEN INTEGER5 2 DIR(ALIAS(VAR VARCHAR2(2.)5 FNAME VARCHAR2()3)5 13 OUTPUT(VAR LONG5 11 BEGIN 12 SELECT AIRBUS(DET INTO LOC(VAR 1) FROM AIRBUS(DESC 1, WHERE AIRBUSNOICAB31C5 1. FE!ISTS(VAR %I DBMS(LOB.FILEE!ISTS(LOC(VAR)5 1/ IF FE!ISTS(VARI1 THEN 10 DBMS(OUTPUT.PUT(LINE(CTHE FILE E!ISTSC)5 12 ELSE 1 DBMS(OUTPUT.PUT(LINE(CTHE FILE COULD NOT BE FOUNDC)5

))/

23 END IF5 21 DBMS(LOB.FILEGETNAME(LOC(VAR$DIR(ALIAS(VAR$FNAME)5 22 DBMS(OUTPUT.PUT(LINE(CFILE NAME IS%C VV DIR(ALIAS(VAR VV C CVV FNAME)5 2)# END5 S"L4 S"L4 / THE FILE E!ISTS FILE NAME IS%GOD AIRBUS(DESC1.DOC PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 DECLARE 2 LOC(VAR BFILE5 ) FE!ISTS(VAR INTEGER5 , FOPEN(VAR INTEGER5 . NUM INTEGER5 / OFFSET INTEGER5 0 LEN INTEGER5 2 DIR(ALIAS(VAR VARCHAR2(2.)5 FNAME VARCHAR2()3)5 13 OUTPUT(VAR LONG5 11 BEGIN 12 SELECT AIRBUS(DET INTO LOC(VAR 1) FROM AIRBUS(DESC 1, WHERE AIRBUSNOICAB31C5 1. FE!ISTS(VAR %I DBMS(LOB.FILEE!ISTS(LOC(VAR)5 1/ IF FE!ISTS(VARI1 THEN 10 DBMS(OUTPUT.PUT(LINE(CTHE FILE E!ISTSC)5 12 ELSE 1 DBMS(OUTPUT.PUT(LINE(CTHE FILE COULD NOT BE FOUNDC)5

))0

23 END IF5 21 DBMS(LOB.FILEGETNAME(LOC(VAR$DIR(ALIAS(VAR$FNAME)5 22 DBMS(OUTPUT.PUT(LINE(CFILE NAME IS%C VV DIR(ALIAS(VAR VV C CVV FNAME)5 2)# END5 2, / THE FILE E!ISTS FILE NAME IS%GOD AIRBUS(DESC1.DOC PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 LOC(VAR BFILE5 ) FE!ISTS(VAR INTEGER5 , FOPEN(VAR INTEGER5 . NUM INTEGER5 / OFFSET INTEGER5 0 LEN INTEGER5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 DIR(ALIAS(VAR VARCHAR2(2.)5 FNAME VARCHAR2()3)5 13 OUTPUT(VAR LONG5 11 BEGIN 12 SELECT AIRBUS(DET INTO LOC(VAR 1) FROM AIRBUS(DESC 1, WHERE AIRBUSNOICAB31C5 1. FE!ISTS(VAR %I DBMS(LOB.FILEE!ISTS(LOC(VAR)5 1/ IF FE!ISTS(VARI1 THEN 10 DBMS(OUTPUT.PUT(LINE(CTHE FILE E!ISTSC)5 12 ELSE 1 DBMS(OUTPUT.PUT(LINE(CTHE FILE COULD NOT BE FOUNDC)5

))2

23 END IF5 21 DBMS(LOB.FILEGETNAME(LOC(VAR$DIR(ALIAS(VAR$FNAME)5 22 DBMS(OUTPUT.PUT(LINE(CFILE NAME IS%C VV DIR(ALIAS(VAR VV C C VVFNAME)5 2) FOPEN(VAR %I DBMS(LOB.FILEISOPEN(LOC(VAR)5 2, IF FOPEN(VAR I 1 THEN 2. DBMS(OUTPUT.PUT(LINE(CTHE FILE IS OPENC)5 2/ ELSE 20 DBMS(OUTPUT.PUT(LINE(CTHE FILE IS BEING OPENEDC)5 22 DBMS(LOB.FILEOPEN(LOC(VAR)5 2 END IF5

)3 NUM%I235 )1 OFFSET %I 15 )2 DBMS(LOB.READ(LOC(VAR$NUM$OFFSET$OUTPUT(VAR)5 )) DBMS(OUTPUT.PUT(LINE(CTHE FIRST 23 CHARACTERS ARE% C VV OUTPUT(VAR)5 ), DBMS(LOB.FILECLOSE(LOC(VAR)5 ).# END5 S"L4 / THE FILE E!ISTS FILE NAME IS%GOD AIRBUS(DESC1.DOC THE FILE IS BEING OPENED THE FIRST 23 CHARACTERS ARE% bcdefg PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 LOC(VAR BFILE5 ) FE!ISTS(VAR INTEGER5 , FOPEN(VAR INTEGER5 . NUM INTEGER5 / OFFSET INTEGER5 0 LEN INTEGER5 2 DIR(ALIAS(VAR VARCHAR2(2.)5 FNAME VARCHAR2()3)5 13 OUTPUT(VAR VARCHAR2(233)5 11 BEGIN 12 SELECT AIRBUS(DET INTO LOC(VAR 1) FROM AIRBUS(DESC 1, WHERE AIRBUSNOICAB31C5 1. FE!ISTS(VAR %I DBMS(LOB.FILEE!ISTS(LOC(VAR)5 1/ IF FE!ISTS(VARI1 THEN 10 DBMS(OUTPUT.PUT(LINE(CTHE FILE E!ISTSC)5 12 ELSE 1 DBMS(OUTPUT.PUT(LINE(CTHE FILE COULD NOT BE FOUNDC)5

))

23 END IF5 21 DBMS(LOB.FILEGETNAME(LOC(VAR$DIR(ALIAS(VAR$FNAME)5 22 DBMS(OUTPUT.PUT(LINE(CFILE NAME IS%C VV DIR(ALIAS(VAR VV C C VVFNAME)5 2) FOPEN(VAR %I DBMS(LOB.FILEISOPEN(LOC(VAR)5 2, IF FOPEN(VAR I 1 THEN 2. DBMS(OUTPUT.PUT(LINE(CTHE FILE IS OPENC)5 2/ ELSE 20 DBMS(OUTPUT.PUT(LINE(CTHE FILE IS BEING OPENEDC)5 22 DBMS(LOB.FILEOPEN(LOC(VAR)5 2 END IF5

)3 NUM%I235 )1 OFFSET %I 15 )2 DBMS(LOB.READ(LOC(VAR$NUM$OFFSET$OUTPUT(VAR)5 )) DBMS(OUTPUT.PUT(LINE(CTHE FIRST 23 CHARACTERS ARE% C VV OUTPUT(VAR)5 ), DBMS(LOB.FILECLOSE(LOC(VAR)5 ).# END5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
)/ / THE FILE E!ISTS FILE NAME IS%GOD AIRBUS(DESC1.DOC THE FILE IS BEING OPENED THE FIRST 23 CHARACTERS ARE% D3CF11E3A1B11AE1333333333333333333333333 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

),3

1 DECLARE 2 LOC(VAR BFILE5 ) FE!ISTS(VAR INTEGER5 , FOPEN(VAR INTEGER5 . NUM INTEGER5 / OFFSET INTEGER5 0 LEN INTEGER5 2 DIR(ALIAS(VAR VARCHAR2(2.)5 FNAME VARCHAR2()3)5 13 OUTPUT(VAR LONG5 11 BEGIN 12 SELECT AIRBUS(DET INTO LOC(VAR 1) FROM AIRBUS(DESC 1, WHERE AIRBUSNOICAB31C5 1. FE!ISTS(VAR %I DBMS(LOB.FILEE!ISTS(LOC(VAR)5 1/ IF FE!ISTS(VARI1 THEN 10 DBMS(OUTPUT.PUT(LINE(CTHE FILE E!ISTSC)5 12 ELSE 1 DBMS(OUTPUT.PUT(LINE(CTHE FILE COULD NOT BE FOUNDC)5

23 END IF5 21 DBMS(LOB.FILEGETNAME(LOC(VAR$DIR(ALIAS(VAR$FNAME)5 22 DBMS(OUTPUT.PUT(LINE(CFILE NAME IS%C VV DIR(ALIAS(VAR VV C C VVFNAME)5 2) FOPEN(VAR %I DBMS(LOB.FILEISOPEN(LOC(VAR)5 2, IF FOPEN(VAR I 1 THEN 2. DBMS(OUTPUT.PUT(LINE(CTHE FILE IS OPENC)5 2/ ELSE

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
20 DBMS(OUTPUT.PUT(LINE(CTHE FILE IS BEING OPENEDC)5 22 DBMS(LOB.FILEOPEN(LOC(VAR)5 2 END IF5 )3 NUM%I235 )1 OFFSET %I 15 )2 DBMS(LOB.READ(LOC(VAR$NUM$OFFSET$OUTPUT(VAR)5 )) DBMS(OUTPUT.PUT(LINE(CTHE FIRST 23 CHARACTERS ARE% C VV TO(CHAR(OUTPUT(VAR))5 ), DBMS(LOB.FILECLOSE(LOC(VAR)5 ).# END5 S"L4 / THE FILE E!ISTS FILE NAME IS%GOD AIRBUS(DESC1.DOC THE FILE IS BEING OPENED THE FIRST 23 CHARACTERS ARE% bcdefg PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 LOC(VAR BFILE5 ) FE!ISTS(VAR INTEGER5 , FOPEN(VAR INTEGER5 . NUM INTEGER5 / OFFSET INTEGER5 0 LEN INTEGER5 2 DIR(ALIAS(VAR VARCHAR2(2.)5 FNAME VARCHAR2()3)5 13 OUTPUT(VAR VARCHAR2(233)5 11 BEGIN 12 SELECT AIRBUS(DET INTO LOC(VAR 1) FROM AIRBUS(DESC 1, WHERE AIRBUSNOICAB31C5 1. FE!ISTS(VAR %I DBMS(LOB.FILEE!ISTS(LOC(VAR)5 1/ IF FE!ISTS(VARI1 THEN 10 DBMS(OUTPUT.PUT(LINE(CTHE FILE E!ISTSC)5 12 ELSE 1 DBMS(OUTPUT.PUT(LINE(CTHE FILE COULD NOT BE FOUNDC)5

),1

23 END IF5 21 DBMS(LOB.FILEGETNAME(LOC(VAR$DIR(ALIAS(VAR$FNAME)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
22 DBMS(OUTPUT.PUT(LINE(CFILE NAME IS%C VV DIR(ALIAS(VAR VV C C VVFNAME)5 2) FOPEN(VAR %I DBMS(LOB.FILEISOPEN(LOC(VAR)5 2, IF FOPEN(VAR I 1 THEN 2. DBMS(OUTPUT.PUT(LINE(CTHE FILE IS OPENC)5 2/ ELSE 20 DBMS(OUTPUT.PUT(LINE(CTHE FILE IS BEING OPENEDC)5 22 DBMS(LOB.FILEOPEN(LOC(VAR)5 2 END IF5

),2

)3 NUM%I235 )1 OFFSET %I 15 )2 DBMS(LOB.READ(LOC(VAR$NUM$OFFSET$OUTPUT(VAR)5 )) DBMS(OUTPUT.PUT(LINE(CTHE FIRST 23 CHARACTERS ARE% C VV TO(CHAR(OUTPUT(VAR))5 ), DBMS(LOB.FILECLOSE(LOC(VAR)5 ).# END5 )/ / THE FILE E!ISTS FILE NAME IS%GOD AIRBUS(DESC1.DOC THE FILE IS BEING OPENED THE FIRST 23 CHARACTERS ARE% D3CF11E3A1B11AE1333333333333333333333333 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 / THE FILE E!ISTS FILE NAME IS%GOD AIRBUS(DESC1.DOC THE FILE IS BEING OPENED THE FIRST 23 CHARACTERS ARE% D3CF11E3A1B11AE1333333333333333333333333 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 LOC(VAR BFILE5 ) FE!ISTS(VAR INTEGER5 , FOPEN(VAR INTEGER5 . NUM INTEGER5 / OFFSET INTEGER5 0 LEN INTEGER5 2 DIR(ALIAS(VAR VARCHAR2(2.)5 FNAME VARCHAR2()3)5 13 OUTPUT(VAR VARCHAR2(233)5 11 BEGIN 12 SELECT AIRBUS(DET INTO LOC(VAR

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1) FROM AIRBUS(DESC 1, WHERE AIRBUSNOICAB31C5 1. FE!ISTS(VAR %I DBMS(LOB.FILEE!ISTS(LOC(VAR)5 1/ IF FE!ISTS(VARI1 THEN 10 DBMS(OUTPUT.PUT(LINE(CTHE FILE E!ISTSC)5 12 ELSE 1 DBMS(OUTPUT.PUT(LINE(CTHE FILE COULD NOT BE FOUNDC)5

),)

23 END IF5 21 DBMS(LOB.FILEGETNAME(LOC(VAR$DIR(ALIAS(VAR$FNAME)5 22 DBMS(OUTPUT.PUT(LINE(CFILE NAME IS%C VV DIR(ALIAS(VAR VV C C VVFNAME)5 2) FOPEN(VAR %I DBMS(LOB.FILEISOPEN(LOC(VAR)5 2, IF FOPEN(VAR I 1 THEN 2. DBMS(OUTPUT.PUT(LINE(CTHE FILE IS OPENC)5 2/ ELSE 20 DBMS(OUTPUT.PUT(LINE(CTHE FILE IS BEING OPENEDC)5 22 DBMS(LOB.FILEOPEN(LOC(VAR)5 2 END IF5

)3 NUM%I235 )1 OFFSET %I 15 )2 DBMS(LOB.READ(LOC(VAR$NUM$OFFSET$OUTPUT(VAR)5 )) DBMS(OUTPUT.PUT(LINE(CTHE FIRST 23 CHARACTERS ARE% C VV OUTPUT(VAR)5 ), DBMS(LOB.FILECLOSE(LOC(VAR)5 ).# END5 S"L4 / THE FILE E!ISTS FILE NAME IS%GOD AIRBUS(DESC1.DOC THE FILE IS BEING OPENED THE FIRST 23 CHARACTERS ARE% D3CF11E3A1B11AE1333333333333333333333333 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 LOC(VAR BFILE5 ) FE!ISTS(VAR INTEGER5 , FOPEN(VAR INTEGER5 . NUM INTEGER5 / OFFSET INTEGER5 0 LEN INTEGER5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 DIR(ALIAS(VAR VARCHAR2(2.)5 FNAME VARCHAR2()3)5 13 OUTPUT(VAR VARCHAR2(233)5 11 BEGIN 12 SELECT AIRBUS(DET INTO LOC(VAR 1) FROM AIRBUS(DESC 1, WHERE AIRBUSNOICAB31C5 1. FE!ISTS(VAR %I DBMS(LOB.FILEE!ISTS(LOC(VAR)5 1/ IF FE!ISTS(VARI1 THEN 10 DBMS(OUTPUT.PUT(LINE(CTHE FILE E!ISTSC)5 12 ELSE 1 DBMS(OUTPUT.PUT(LINE(CTHE FILE COULD NOT BE FOUNDC)5

),,

23 END IF5 21 DBMS(LOB.FILEGETNAME(LOC(VAR$DIR(ALIAS(VAR$FNAME)5 22 DBMS(OUTPUT.PUT(LINE(CFILE NAME IS%C VV DIR(ALIAS(VAR VV C C VVFNAME)5 2) FOPEN(VAR %I DBMS(LOB.FILEISOPEN(LOC(VAR)5 2, IF FOPEN(VAR I 1 THEN 2. DBMS(OUTPUT.PUT(LINE(CTHE FILE IS OPENC)5 2/ ELSE 20 DBMS(OUTPUT.PUT(LINE(CTHE FILE IS BEING OPENEDC)5 22 DBMS(LOB.FILEOPEN(LOC(VAR)5 2 END IF5

)3 NUM%I235 )1 OFFSET %I 15 )2 DBMS(LOB.READ(LOC(VAR$NUM$OFFSET$OUTPUT(VAR)5 )) DBMS(OUTPUT.PUT(LINE(CTHE FIRST 23 CHARACTERS ARE% C VV OUTPUT(VAR)5 ), LEN%IDBMS(LOB.GETLENGTH(LOC(VAR)5 ). DBMS(OUTPUT.PUT(LINE(LEN)5 )/ DBMS(LOB.FILECLOSE(LOC(VAR)5 )0# END5 )2 / THE FILE E!ISTS FILE NAME IS%GOD AIRBUS(DESC1.DOC THE FILE IS BEING OPENED THE FIRST 23 CHARACTERS ARE% D3CF11E3A1B11AE1333333333333333333333333 1 /2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. TYPES OF APPLICATION ARC.ITECURES:

),.

APPLICATIONS ARE DEVELOPED TO SUPPORT ORGANIZATIONS IN THEIR BUSSINESS OPERATIONS. APPLICATIONS ACCEPT INPUT$PROCESS THE DATA BASED ON BUSSINESS RULES$ AND PROVIDE DATA AS OUTPUT. THE FUNCTIONS PERFORMED BY AN APPLICATION CAN BE DIVIDED INTO THREE CATEGORIES. USER SERVICES. BUSSINESS SERVICES. DATA SERVICES. EACH CATEGEORY IS IMPLEMENTED AS A LAYER IN AN APPLICATION. THE USER SERVICES LAYER CONSTITUTES THE FRONT&END OF A SOLUTION. IT IS ALSO CALLED A PRESENTATION LAYER BECAUSE IT PROVIDES AN INTERACTIVE USER INTERFACE. THE BUSSINESS SERVICES LAYER CONTROLS THE ENFORCEMENT OF BUSSINESS RULES ON THE DATA OF AN ORGANIZATION. FOR E!AMPLE$ AN ORAGANIZATION MAY HAVE DECIDED THAT THE CREDIT LIMIT OF CLIENTS CANNOT E!CEED `233333. THE BUSSINESS SERVICE LAYER PERFORMS VALIDATIONS PERTAINING TO BUSSINESS RULES. IT ENSURES THAT BAC' END DOESNT RECEIVE INCORRECT DATA. THE DATA SERVICES LAYER COMPRISES THE DATA AND THE FUNCTIONS FOR MANIPULATING THIS DATA. APPLICATIONS MAY VARY FROM SINGLE 1TIER DES'TOP APPLICATIONS (APPLICATIONS THAT FOLLOW THE SINGLE 1TIER ARCHITECTURE) TO MULTI&TIER APPLICATIONS( APPLICATIONS THE FOLLOW THE TWO $THREE$OR N TIER ARCHITECTURE.

SINGLE2TIER ARC.ITECTURE: IN THE CASE OF THE SINGLE 1 TIER ARCHITECTURE$ A SINGLE E!ECUTABLE FILE HANDLES ALL FUNCTIONS RELATING TO THE USER$BUSSINE AND DATA SERVICE LAYERS. SUCH AN APPLICATION IS ALSO CALLED A MONOLITHIC APPLICATION. SOME OF THE VERY EARLY COBOL PROGRAMS PERFORMING E!TREMELY MISSION 1 CRITICAL OPERATIONS FALL UNDER THIS CATEGORY.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
MONOLITHIC APPLICATIONS USER SERVICES BUSSINESS SERVICES

),/

DATA SERVICES

T+O%TIER ARC.ITECTURE: THE TWO 1 TIER ARCHITECTURE DIVIDES AN APPLICATION IN TO THE FOLLOWING TWO COMPONENTS% CLIENT % IMPLEMENTS THE USER INTERFACE. SERVER % STORES DATA. THUS $ IN THE CASE OF THE TWO&TIER ARCHITECTURE $ THE USER AND DATA SERVICES ARE LOCATED SEPARATELY$ EITHER ON THE SAME MACHINE OR ON SEPARATE MACHINES. FOR E!AMPLE YOU MIGHT HAVE A VISUAL BASIC APPLICATION$ WHICH PROVIDES THE USER INTERFACE AND S"L SERVER 0.3 WHICH MANAGES DATA. IN THE TWO&TIER ARCHITECTURE$ THE BUSSINESS SERVICES LAYER MAY BE IMPLEMENTED IN ONE OF THE FOLLOWING WAYS% BY USING FAT CLIENT. BY USING FAT SERVER. BY DIVIDING THE BUSSINESS SERVICES BETWEEN THE USER SERVICES AND THE DATA SERVICES.

FAT CLIENT : IN THE CASE OF FAT CLIENTS$THE BUSSINESS SERVICES LAYER IS COMBINED WITH THE USER SERVICES LAYER. CLIENTS E!ECUTE THE PRESENTATION LOGIC AND ENFORCES BUSSINESS RULES. THE SERVER STORES DATA AND PROCESSESS TRANSACTIONS. THE FAT CLIENT MODEL IS USED WHEN THE SERVER IS OVERLOADED WITH TRASACTION PROCESSING ACTIVITIES AND IS NOT E"UIPPED TO PROCESS BUSSINESS LOGIC.

SERVER

DATA TIER.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
FAT CLIENT CLIENT USER TIER BUSSINESS LOGIC.

),0

FAT SER*ER: IN A TWO 1TIER ARCHITECTURE WITH A FAT SERVER$ THE BUSSINESS SERVICES LAYER IS COMBINED WITH THE DATA SERVICES LAYER. AS BUSSINESS SERVICES ARE STORED ON THE SERVER$MOST OF THE PROCESSING TA'ES PLACE ON THE SERVER.

CLIENT. USER TIER.

FAT SERVER. BUSSINESS LOGIC.

SERVER. DATA TIER.

DI*IDING BUSSINESS SER*ICES BET+EEN T.E USER AND DATA SER*ICES: YOU CAN ALSO IMPLEMENT A TWO&TIER MODEL IN WHICH THE BUSSINESS SERVICES ARE DISTRIBUTED BETWEEN THE USER AND DATA SERVICES. IN THIS CASE $ THE PROCESSING OF BUSSINESS LOGIC IS DISTRIBUTED BETWEEN THE USER AND DATA SERVICES.

T.REE%TIER ARC.ITECTURE:

IN THE CASE OF THE THREE&TIER ARCHITECTURE$ ALL THE THREE SERVICES LAYERS RESIDE SEPARETLEY$ EITHER ON THE SAME MACHINE OR ON DIFFERENT MACHINES. THE USER INTERFACE INTERACTS WITH THE BUSSINESS LOGIC. THE BUSSINESS LOGIC VALIDATES THE DATA SENT BY THE INTERFACES AND FORWARDS IT TO THE DATABASE IF IT CONFORMS TO THE RE"UIREMENTS. THE FRONT END ONLY INTERACTS WITH BUSINESS LOGIC$ WHICH IN TURN$ INTERACTS WITH THE DATABASE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CLIENT. USER SERVICES. BUSSINESS LOGIC. BUSSINESS SERVICES.

),2

SERVER. DATA SERVICES.

N%TIER ARC.ITECTURE(

AN N&TIER APPLICATIONS USES BUSSINESS OBJECTS FOR HANDLING BUSSINESS RULES AND DATA ACCESS. IT HAS MULTIPLE SERVERS HANDLING THE BUSSINESS SERVICES. THIS APPLICATION ARCHITECTURE PROVIDES VARIOUS ADVANTAGES OVER OTHER TYPES OF APPLICATION ARCHITECTURES. SOME OF THE ADVANTAGES INCLUDES E!TENSIBILITY$ RESILIENCE TO CHANGE . MAINTAINABILITY$ AND SCALABILITY OF THE APPLICATION.

SUBPROGRA)S: S"L4 DROP TABLE DEPT15 T6789 =;DBB9=. 1 CREATE TABLE DEPT1 2 AS )# SELECT # FROM DEPT , / T6789 :;96<9=. S"L4 DELETE FROM DEPT15 , ;DEF =989<9=. S"L4 CREATE OR REPLACE PROCEDURE ADDDEPT 2 (P(DEPTNO IN DEPT1.DEPTNO-TYPE$ ) P(DNAME IN DEPT1.DEPTNO-TYPE$ , P(LOC IN DEPT1.DEPTNO-TYPE) . AS / BEGIN 0 INSERT INTO DEPT1 VALUES 2 (P(DEPTNO$P(DNAME$P(LOC)5 END5 13 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
P;D:9=?;9 :;96<9=.

),

S"L4 DECLARE 2 V(DEPTNO DEPT1.DEPTNO-TYPE%I135 ) V(DNAME DEPT1.DNAME-TYPE%ICACCOUNTINGC5 , V(LOC DEPT1.LOC-TYPE%ICNEW YOR'C5 . BEGIN / ADDDEPT(V(DEPTNO$V(DNAME$V(LOC)5 0 END5 2 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT # FROM DEPT15 DEPTNO DNAME LOC &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 ACCOUNTING NEW YOR' THE VARIABLES DECLARED IN THE PRECEDING BLOC' V(DEPTNO$V(DNAME$V(LOC ARE PASSED AS ARGUMENTS TO ADDDEPT. IN THIS CONTE!T$ THEY ARE 'NOWN AS ACTUAL PARAMETERS. WHERE AS PARAMETERS IN THE PROCEDURE DECLARATION OF ADDDEPT(P(DEPTNO$P(DNAME$P(LOC) ARE 'NOWN AS FORMAL PARAMETERS. ACTUAL PARAMETERS CONTAINS THE VALUES PASSED TO THE PROCEDURE WHEN IT IS CALLED$ AND THEY RECEIVE RESULTS FROM THE PROCEDURE WHEN IT RETURNS (DEPENDING UPON MODE). THE VALUES OF THE ACTUAL PARAMETERS ARE THE ONES THAT WILL BE USED IN PROCEDURE. THE FORMAL PARAMETERS ARE THE PLACE HOLDERS FOR THE VALUES OF THE ACTUAL PARAMETERS. WHEN THE PROCEDURE IS CALLED$ THE FORMAL PARAMETERS ARE ASSIGNED THE VALUES OF THE ACTUAL PARAMETERS. WHEN THE PROCEDURE RETURNS$ THE ACTUAL PARAMETERS ARE ASSIGNED THE VALUES OF THE FORMAL PARAMETERS.

1 CREATE OR REPLACE PROCEDURE MODETEST

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 (P(INPARAMETER IN NUMBER$ ) P(OUTPARAMETER OUT NUMBER$ , P(INOUTPARAMETER IN OUT NUMBER) IS . V(LOCALVARIABLE NUMBER %I35 / BEGIN 0 DBMS(OUTPUT.PUT(LINE(CINSIDE MODE TESTC)5 2 IF (P(INPARAMETER IS NULL) THEN DBMS(OUTPUT.PUT(LINE(CP(INPARAMETER IS NULLC)5 13 ELSE 11 DBMS(OUTPUT.PUT(LINE(CP(INPARAMETER I C VVP(INPARAMETER)5 12 END IF5 1) IF (P(OUTPARAMETER IS NULL) THEN 1, DBMS(OUTPUT.PUT(LINE(CP(OUTPARAMETER IS NULLC)5 1. ELSE 1/ DBMS(OUTPUT.PUT(LINE(CP(OUTPARAMETER I C VVP(OUTPARAMETER)5 10 END IF5 12 IF (P(INOUTPARAMETER IS NULL) THEN 1 DBMS(OUTPUT.PUT(LINE(CP(INOUTPARAMETER IS NULLC)5

).3

23 ELSE 21 DBMS(OUTPUT.PUT(LINE(CP(INOUTPARAMETER I C VVP(INOUTPARAMETER)5 22 END IF5 2) /# ASSIGN P(INPARAMTER TO V(LOCALVARIABLE. THIS IS LEGAL #/ 2, V(LOCALVARIABLE %I P(INPARAMETER5 && LEGAL5 2. /# ASSIGN TO P(INPARAMTER.THIS IS ILLEGAL #/

2/ &&P(INPARAMETER%I 5&&ILLEGAL 20 /# ASSIGN TO P(OUTPARAMTER.THIS IS LEGAL #/

22 P(OUTPARAMETER%I05&&LEGAL 2 /# ASSIGN P(OUTPARAMTER TO V(LOCAL VARIBALE .THIS IS LEGAL #/

)3 V(LOCALVARIABLE %IP(OUTPARAMETER5&&LEGAL )1 /# ASSIGN P(INOUTPARAMTER TO V(LOCAL VARIBALE .THIS IS LEGAL #/ )2 V(LOCALVARIABLE %IP(INOUTPARAMETER5&&LEGAL )) /# ASSIGN TO P(INOUTPARAMTER.THIS IS LEGAL #/

), P(INOUTPARAMETER%I 5&&LEGAL ). DBMS(OUTPUT.PUT(LINE(CAT END OF MODETESTC)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
)/ IF (P(INPARAMETER IS NULL) THEN )0 DBMS(OUTPUT.PUT(LINE(CP(INPARAMETER IS NULLC)5 )2 ELSE ) DBMS(OUTPUT.PUT(LINE(CP(INPARAMETER I C VVP(INPARAMETER)5 ,3 END IF5 ,1 IF (P(OUTPARAMETER IS NULL) THEN ,2 DBMS(OUTPUT.PUT(LINE(CP(OUTPARAMETER IS NULLC)5 ,) ELSE ,, DBMS(OUTPUT.PUT(LINE(CP(OUTPARAMETER I C VVP(OUTPARAMETER)5 ,. END IF5 ,/ IF (P(INOUTPARAMETER IS NULL) THEN ,0 DBMS(OUTPUT.PUT(LINE(CP(INOUTPARAMETER IS NULLC)5 ,2 ELSE , DBMS(OUTPUT.PUT(LINE(CP(INOUTPARAMETER I C VVP(INOUTPARAMETER)5

).1

.3 END IF5 .1# END MODETEST5 .2 / P;D:9=?;9 :;96<9=.

PASSING *ALUES BET+EEN FOR)AL AND ACTUAL PARA)ETERS: S"L4 DECLARE 2 V(IN NUMBER%I15 ) V(OUT NUMBER%I25 , V(INOUT NUMBER%I)5 . BEGIN / DBMS(OUTPUT.PUT(LINE(CBEFORE CALLING MODETESTC)5 0 DBMS(OUTPUT.PUT(LINE(CV(IN I C VV V(IN VV C V(OUT I C VV V(OUT VV C V(INOUT I C VV V(INOUT) 2 5 MODETEST(V(IN$V(OUT$V(INOUT)5 13 DBMS(OUTPUT.PUT(LINE(CAFTER CALLING MODETESTC)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
11 DBMS(OUTPUT.PUT(LINE(C V(IN I C VV V(IN VV C V(OUT I C VV V(OUT VV C V(INOUT I C VV V(INOUT) 12 5 1) END5 1, / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. BEFORE CALLING MODETEST V(IN I 1 V(OUT I 2 V(INOUT I ) INSIDE MODE TEST P(INPARAMETER I 1 P(OUTPARAMETER IS NULL P(INOUTPARAMETER I ) AT END OF MODETEST P(INPARAMETER I 1 P(OUTPARAMETER I 0 P(INOUTPARAMETER I AFTER CALLING MODETEST V(IN I 1 V(OUT I 0 V(INOUT I PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

).2

THE OUTPUT SHOWS THAT THE OUT PARAMETER HAS BEEN INITIALIZED TO NULL INSIDE THE PROCEDURE.ALSO THE VALUES OF THE IN AND IN OUT FORMAL PARAMETERS AT THE END OF THE PROCEDURE HAVE BEEN COPIED BAC' TO THE ACTUAL PARAMETERS WHEN THE PROCEDURE ENDS. LITERALS OR CONSTANTS AS ACTUAL PARA)ETERS: HERE WE REPALCED IN PARAMETER WITH LITERAL. 1 DECLARE 2 V(OUT NUMBER %I25 ) V(INOUT NUMBER %I)5 , BEGIN . MODETEST(1$V(OUT$V(INOUT)5 /# END5 S"L4 / INSIDE MODE TEST P(INPARAMETER I 1 P(OUTPARAMETER IS NULL P(INOUTPARAMETER I ) AT END OF MODETEST

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
P(INPARAMETER I 1 P(OUTPARAMETER I 0 P(INOUTPARAMETER I PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. HERE IF WE REPLACE V(OUT WITH LITERAL. 1 DECLARE 2 V(INOUT NUMBER %I)5 ) BEGIN , MODETEST(1$2$V(INOUT)5 .# END5 / / MODETEST(1$2$V(INOUT)5 # ERROR 6< 8NK9 ,% ORA&3/..3% 8NK9 ,$ :D8?>K 12% PLS&33)/)% 9UB;9FFNDK C2C :6KKD< 79 ?F9= 6F 6K 6FFNSK>9K< <6;S9< ORA&3/..3% 8NK9 ,$ :D8?>K 1% PL/S"L% S<6<9>9K< NSKD;9= CO)PILATION C.EC-S: THE PL/S"L COMPILER WILL CHEC' FOR LEGAL ASSIGNMENTS WHEN THE PROCEDURE IS CREATED.

).)

FOR E!AMPLE$ IF WE REMOVE THE COMMENTS ON THE ASSIGNMENT TO P(INPARAMETER$MODE TEST GENERATES THE FOLLOWING ERROR IF WE ATTEMPT TO COMPILE IT. PLS&)/)% E!PRESSION GP(INPARAMETER CANNOT BE USED AS AN ASSIGNMENT TARGET. READING FRO) OUT PARA)ETERS: PRIOR TO VERSION 0.)., AND IN 2.3.)$ IT IS ILLEGAL TO READ FROM AN OUT PARAMETER IN A PROCEDURE. IF YOU ATTEMPT TO COMPILE MODETEST AGAINST AN 2.3.) DATABASE$WE RECEIVE THE FOLLOWING ERROR MESSAGE. PLS&33)/.% GP(OUTPARAMETER IS AN OUT PARAMETER AND CANNOT READ. ORACLE VERSION PRIOR TO 0.)., 0.)., 2.3.) 2.3., AND HIGHER YES. LEGAL TO READ OUT PARAMETERS@ NO YES NO

CONSTRAINTS ON FOR)AL PARA)ETERS: 1 CREATE OR REPLACE PROCEDURE PARAMETERLENGTH

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 (P(PARAMETER1 IN OUT VARCHAR2(13)$ ) P(PARAMETER2 IN OUT NUMBER()$1)) AS , BEGIN . P(PARAMETER1%ICABCDEFGHIJ'LMC5 / P(PARAMETER2 %I12.)5 0# END5 T.E CORRECT DECLARATION FOR T.IS PROCEDURE +OULD BE(

).,

1 CREATE OR REPLACE PROCEDURE PATAMETERLENGTH 2 (P(PARAMETER1 IN OUT VARCHAR2$ ) P(PARAMETER2 IN OUT NUMBER) AS , BEGIN . P(PARAMETER1%ICABCDEFGHIJ'LMC5 / P(PARAMETER2 %I12.)5 0# END5 S"L4 / P;D:9=?;9 :;96<9=.

SO$WHAT ARE THE CONSTRAINTS ON P(PARAMETER1 AND P(PARAMETER2@ THEY COME FROM THE ACTUAL PARAMETERS. IF WE CALL PARAMETERLENGTH WITH. 1 DECLARE 2 V(VARIABLE1 VARCHAR2(,3)5 ) V(VARIABLE2 NUMBER(0$))5 , BEGIN . PARAMETERLENGTH(V(VARIABLE1$V(VARIABLE2)5 /# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 DECLARE 2 V(VARIABLE1 VARCHAR2(13)5 ) V(VARIABLE2 NUMBER(0$))5 , BEGIN . PARAMETERLENGTH(V(VARIABLE1$V(VARIABLE2)5 / END5 0 / DECLARE # ERROR 6< 8NK9 1% ORA&3/.32% PL/S"L% K?>9;N: D; Q68?9 9;;D;% :R6;6:<9; F<;NKS 7?TT9; <DD F>688 ORA&3/.12% 6< OSCOTT.PARAMETERLENGTHO$ 8NK9 . ORA&3/.12% 6< 8NK9 . THE ONLY DIFFERENCE BETWEEN THIS BLOC' AND THE PRIOR ONE IS THE V(VARIABLE1$AND HENCE P(PARAMETER1 HAS A LENGTH OF 13 RATHER THAN ,3. BECAUSE PARAMETERLENGTH ASSIGNS A CHARACTER STRING OF LENGTH 1. TO P(PARAMETER1(AND HENCE V(VARIABLE1)$ THERE IS NOT ENOUGH ROOM IN THE STRING.

)..

HERE P(PARAMETER1 WILL HAVE A MA!IMUM LENGHT OF ,3(COMING FROM THE ACTUAL PARAMETER V(VARIABLE1) AND P(PARAMETER2 WILL HAVE PRECISION 0 AND SCALE )(COMING FROM THE ACTUALPARAMETER V(VARIABLE2. IT IS VERY IMPORTANT.

THE SOURCE OF THE ERROR IS NOT IN THE PROCEDURE& IT IS IN THE CODE THAT CALLS THE PROCEDURE.IN ADDITION $THE ORA&/.32 IS RUNTIME ERROR$ NOT COMPILE TIME ERROR.THUS PROCEDURE CREATED SUCCESFULLY. HERE ERROR WAS ACTUALLY RAISED WHEN THE PROCEDURE RETURNED AND THE PL/S"L ENGINE ATTEMPTED TO COPY THE ACTUAL VALUE CABCDEFGHIJ'LMNOC INTO THE FORMAL PARAMETER. 5TYPE AND PROCEDURE PARA)ETERS: S"L4 CREATE TABLE TEST 2 (NO NUMBER()))5 1 CREATE OR REPLACE PROCEDURE PARAMETERLENGHT1 2 (P(PARAMETER1 IN OUT VARCHAR2$ ) P(PARAMETER2 IN OUT TEST.NO-TYPE) , AS . BEGIN / P(PARAMETER2 %I12),.5 0# END5 2 / P;D:9=?;9 :;96<9=. HERE P(PARAMETER2 WILL BE CONSTRAINED WITH PRECISION OF )$ BECAUSE THAT IS THE PRECISION OF THE TEST TABLE NO COLUMN.EVEN IF WE CALL PARAMETERLENGTH WITH AN ACTUAL PARAMETER OF ENOUGH PRECISION$THE FORMAL PRECISION IS TA'EN.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 DECLARE 2 V(VARIABLE1 VARCHAR2(1)5 ) V(VARIABLE2 NUMBER5 && DECLARED VARIABLE WITH NO CONSTRAINTS. , BEGIN . /# HERE EVEN THOUGH THE ACTUAL PARAMETER HAS ROOM FOR 12),.$ THE CONSTRAINT ON THE FORMAL / PARAMETER IS TA'EN AND WE GET ORA&/.32 ON THIS PROCEDURE CALL. #/ 0 PARAMETERLENGHT1(V(VARIABLE1$V(VARIABLE2)5 2# END5 S"L4 /

)./

DECLARE # ERROR 6< 8NK9 1% ORA&3/.32% PL/S"L% K?>9;N: D; Q68?9 9;;D;% K?>79; B;9:NFNDK <DD 86;S9 ORA&3/.12% 6< OSCOTT.PARAMETERLENGHT1O$ 8NK9 / ORA&3/.12% 6< 8NK9 0 CREATING" ALTERING AND DROPING STORTED PROCEDURES: THERE ARE TWO MAIN WAYS TO CREATE PROCEDURE% 1.USING THE CREATE PROCEDURE COMMAND IN A PL/S"L COMMAND SCRIPT THAT E!ECUTES IN THE S"L#PLUS COMMAND LINE INTERFACE. 2. USING GUI TOOLS$SUCH AS PROCEDURE BUILDER. POINTS TO RE)E)BER +.ILE CREATING STORED PROCEDURES:

CREATE OR [REPLACE\ PROCDURE PROCEDURE(NAME [(ARGUMENT[]INVOUTVIN OUT^\ TYPE$ ** [(ARGUMENT[]INVOUTVIN OUT^\ TYPE\ ] ISVAS^ PROCEDURE BODY. CREATE OR REPLACE PROCEDURE PROCEDURE(NAME [ PARAMETER LIST\ IS/AS /# DECLARATIVE SECTION#/ BEGIN /# E!ECUTABLE SECTION#/ E!CEPTION /# E!EPTION SECTION#/ END [PROCEDURE(NAME\5 THE RESERVED WORDS CREATE PROCEDURE. THE NAME OF STORED PROCEDURE CAN BE UP TO )3 CHARACTERS NO SPACES. THE RESERVED WORD IS OR THE RESERVED WORD AS 1 EITHER IS ACCEPTED. A VALID PL/S"L BLOC'.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
THE 'EY WORDS BEGIN AND END ARE RE"UIRED. E!CEPTION IS OPTIONAL. THE 'EY WORD DECLARE $HOWEVER NEVER USED. INSTEAD OF USING DECLARE TO BEGIN THE OPTIONAL DECLARATIVE SECTION OF THE BLOC'$ MA'E ANY DECLARATIONS AFTER THE RESERVED WORD IS AND BEFORE THE RESERVED WORD BEGIN. WE TYPE SLASH (/) AT THE END OF FILE. WE USE THAT TO SUBMIT THE PL/S"L BLOC' TO THE S"L#PLUS INTERFACE FOR PROCESSING. WHEN U SUBMIT A CREATE PROCEDURE COMMAND TO S"L#PLUS THE FOLLOWING HAPPENS% THE CODE STORED IN THE DATA DICTIONARY. THE CODE IS PARSED FOR SYNTA! AND DETERMINED TO BE EITHER VALID OR INVALID. IF THE CODE IS VALID$ YOU ARE PROVIDED WITH A PROCEDURE CREATED MESSAGE$AND PROCEDURE IS NOW GIVEN A STATUS OF VALID AND IS AVALIABLE FOR E!ECUTION.

).0

IF THE CODE IS INVALID$ YOU ARE PROVIDED WITH SOME SORT OF ERROR MESSAGE$ AND THE CODE$ WHICH IS NOW STORED IN THE DATA DICTIONARY$ IS GIVEN A STATUS OF INVALID AND NOT AVALIABLE FOR E!ECUTION. PLEASE NOTE THE WHETHER THE PROCEDURE IS SUCCESFULLY PARSED OR NOT$ IT WILL BE STORED IN THE DATA DICTIONARY. ONCE PROCEDURE IS STORED IN TH DATABASE$YOU CANNOT CREATE ANOTHER PROCEDURE WITH SAME NAME. U WILL GET ERROR. HOWEVER $ AN OPTION IN THE CREATE PROCEDURE COMMAND THAT IS GOR REPLACE ENABLES U TO AUTOMATICALLY OVERWRITE ANY PREE!ISTING PROCEDURE OF THE SAME NAME. THE OR REPLACE OPTION IN THE CREATE PROCEDURE COMMAND GUARANTEES THAT THE PROCEDURE IS CREATED AND STORED $WHETHER AN E!ISTING PROCEDURE OF THE SAME NAME IS ALREADY STORED IN DATABASE OR NOT. PROCEDURES OPTIONALLY INCLUDE SOMETHING CALLED AN END LABEL.WHICH IS THE NAME OF THE PROCEDURE REPEATED AFTER THE END STATEMENT. CREATE OR REPLACE PROCEDURE GAYATRI IS BEGIN && CLEAN OUT THE DEPT TABLE5 DELETE FROM DEPT5 COMMIT5 END GAYATRI5 / THE ADVANTAGE TO AN END LABEL BECOMES MORE IMPORTANT ONCE YOU BEGIN COMBINING MANY PROCEDURES IN TO A PAC'AGE$WHEN SEVERAL PROCEDURES ARE INCLUDED ONE AFTER ANOTHER. AT THAT TIME IT MAY BE DIFFICULT TO BE SURE WHERE ONE PROCEDURE ENDS AND ANOTHER PROGRAM BEGINS.THE USE OF THE END LABEL CAN HELP PREVENT CONFUSSION. ALTERING PROCEDURES: ONCE PROCEDURE HAS BEEN CREATED$ YOU CAN USE TWO METHODS TO MALTERH THE PROCEDURE. IF YOU ARE REPLACING THE ORIGINAL SOURCE CODE WITH NEW SET OF SOURCE CODE$ USE THE OR REPLACE OPTION. IF HOWEVER YOU ARE RECOMPILING THE PROCEDURE WITHOUT CHANGING THE CODE$THEN USE THE ALTER PROCEDURE COMMAND.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 DROP TABLE DEPT(DUP5 T6789 =;DBB9=. S"L4 CREATE TABLE DEPT(DUP 2 AS ) SELECT # FROM DEPT5 T6789 :;96<9=. S"L4 CREATE OR REPLACE PROCEDURE GAYATRI 2 AS ) BEGIN , DELETE FROM DEPT(DUP . WHERE DEPTNOI135 / COMMIT5 0 END5 2 / P;D:9=?;9 :;96<9=. S"L4 DESC USER(OBJECTS N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(NAME VARCHAR2(122) SUBOBJECT(NAME VARCHAR2()3) OBJECT(ID NUMBER DATA(OBJECT(ID NUMBER OBJECT(TYPE VARCHAR2(12) CREATED DATE LAST(DDL(TIME DATE TIMESTAMP VARCHAR2(1 ) STATUS VARCHAR2(0) TEMPORARY VARCHAR2(1) GENERATED VARCHAR2(1) SECONDARY VARCHAR2(1) S"L4 SELECT STATUS FROM USER(OBJECTS 2 WHERE OBJECT(NAMEICGAYATRIC AND OBJECT(TYPEICPROCEDUREC5 STATUS &&&&&&& VALID S"L4 DROP TABLE DEPT(DUP5 T6789 =;DBB9=. S"L4 SELECT STATUS FROM USER(OBJECTS 2 WHERE OBJECT(NAMEICGAYATRIC AND OBJECT(TYPEICPROCEDUREC5 STATUS &&&&&&& INVALID S"L4 CREATE TABLE DEPT(DUP 2 AS ) SELECT # FROM DEPT5 T6789 :;96<9=. S"L4 SELECT STATUS FROM USER(OBJECTS

).2

WE USE ALTER PROCEDURE WHEN ANY OBJECT WHICH IS REFERENCED FROM WITHIN YOUR PROCEDURE SUCH AS TABLE HAS BEEN CHANGED.THIS AUTOMATICALLY CAUSES PROCEDURE TO BE FLAGGED TO INVALID.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 WHERE OBJECT(NAMEICGAYATRIC AND OBJECT(TYPEICPROCEDUREC5 STATUS &&&&&&& INVALID S"L4 ALTER PROCEDURE GAYATRI 2 COMPILE5 P;D:9=?;9 68<9;9=. S"L4 SELECT STATUS FROM USER(OBJECTS 2 WHERE OBJECT(NAMEICGAYATRIC AND OBJECT(TYPEICPROCEDUREC5 STATUS &&&&&&& VALID S"L4 DROP PROCEDURE GAYATRI5 P;D:9=?;9 =;DBB9=.

).

IN*O-ING PROCEDURES:

ONCE A PROCEDURE HAS BEEN CREATED AND STORED IN THE DATABASE$ IT CAN BE INVO'ED FROM AN E!ECUTABLE STATEMENT OF A PL/S"L BLOC'. A COMMAND ENTERED IN THE S"L#PLUS COMMAND LINE INTERFACE.

1ST WAY% BEGIN GAYATRI5 END5 BEGIN CALL GAYATRI5&& IT IS A STORED PROCEDURE. IF CONDTION IS TRUE THEN CALL PRATHIMA && IT IS A STORED PROCEDURE. ELSE CALL SRI5&& IT IS A STORED PROCEDURE. END IF5 WHEN A PL/S"L BLOC' CALLS A PROCEDURE THE CALLING BLOC' TEMPORARILY SUSPENDS E!ECUTION AT THE POINT OF THE PROCEDURE CALL AND WAITS WHILE THE CALLED PROCEDURE E!ECUTES. ONCE THE CALLED PROCEDURE COMPLETES E!ECUTION$ CONTROL PASSES BAC' TO THE CALLING PL/S"L BLOC'$ WHICH THEN PIC'S UP WITH NE!T E!ECUTABLE STATEMENT AFTER PROCEDURE CALL AND CONTINUES E!ECUTION.

6ND +AY: E!ECUTE GAYATRI5 E!EC GAYATRI5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DATA DICTIONARY RESOURCES FOR PROCEDURES: USER2DEPENDENCIES:

)/3

IS A VIEW IN THE DATA DICTIONARY IS WHERE YOU WILL FIND THE RELATIONSHIPS THAT YOUR PROGRAM UNITS HAVE WITH THE DATABASE OBJECTS IN THE SAME SCHEMA AS WELL AS THOSE DATABASE OBJECTS IN OTHER SCHEMAS.

USER2OBJECTS: THIS VIEW CONTAINS A MASTER LIST OF ALL OBJECTS$INCLUDING TABLES $VIEWS$SE"UENCES$SYNONYMS AND FOR OUR PURPOSES PL/S"L PROGRAM UNITS. USER2OBJECT2SIQE: THIS VIEW CONTAINS INFORMATION ABOUT THE SIZE OF THE OBJECTS THAT ARE LISTED IN USER(OBJECTS. USER2SOURCE: THIS IS WHERE ACTUAL SOURCE CODE OF THE PL/S"L PROGRAM UNITS IS FOUND. USER2ERRORS: THIS IS WHERE ERRORS RESULTING FROM COMPILATION ARE STORED. T.E E/ECUTE I))EDIATE STATE)ENT: THE E!ECUTE IMMDEDIATE STATEMENT PARSES A DYNAMIC STATEMENT OR A PL/S"L BLOC' FOR IMMEDIATE E!ECUTION AND HAS THE STRUCTURE SHOWN BELOW. E!ECUTE IMMEDIATE DYNAMIC(S"L(STRING [INTO DEFINED(VARIABLE1$DEFINED(VARIABLE2$*\ [USING [IN V OUT V IN OUT \ BIND(ARGUMENT1$BIND(ARGUMENT2$*.\ RETURNING INTO V RETURN BIND(ARGUMENT1$BIND(ARGUMENT2$*.\

PL/S"L USES EARLY BINDING TO E!ECUTE S"L STATEMENTS. THIS HASTHE CONSE"UENCE THAT ONLY DML STATEMENTS CAN BE INCLUDED DIRECTLY IN PL/S"L BLOC'S.THIS CAN BE RECTIFIED$HOWEVER$ S"L4 THROUGH DYNAMIC S"L.RATHER THAN BEING PARSED ALONG WITH THE PL/S"L BLOC'$DYNAMIC S"L IS PARSED AND SUBSE"UENTLY E!ECUTED AT RUNTIME. THERE ARE TWO TECHNI"UES FOR E!ECUTING DYNAMIC S"L IN PL/S"L. THE FIRST IS THE DBMS(S"L PAC'AGE. THE SECOND TECHNI"UE$ INTRODUCED IN ORACLE 2I$ IS NATIVE DYNAMIC S"L.IT IS SIGNIFICANTLY SIMPLER TO USE AND FASTER THAN DBMS(S"L. S"L4 CREATE TABLE NATIVE 2 (EMPNO NUMBER(13))5 T6789 :;96<9=. S"L4 DROP TABLE NATIVE5 T6789 =;DBB9=. S"L4 BEGIN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 CREATE TABLE NATIVE ) (EMPNO NUMBER(13))5 , END5 . / CREATE TABLE NATIVE # ERROR #t li C 6: ORA%8O&&8: li C 6" BoluH 7: PLS%8878=: E Bou tCDCE tFC !GHIol JCREATEJ KFC CLMCBti $ o C of tFC folloKi $: IC$i B#!C ECBl#DC CLit foD $o to if looM HoE ull MD#$H# D#i!C DCtuD !ClCBt uME#tC KFilC KitF <# iEC tifiCD> <# EouIlC%NuotCE ECliHitCE%iEC tifiCD> <# Ii E R#Di#IlC> << Blo!C BuDDC t EClCtC fCtBF loBS i !CDt oMC DollI#BS !#RC Moi t !Ct !ol CLCButC BoHHit foD #ll HCD$C <# !i $lC%NuotCE SQL !tDi $> MiMC

)/1

DECLARE V(S"LSTRING VARCHAR2(233)5 V(PLS"LBLOC' VARCHAR2(233)5 BEGIN &&FIRST CREATE A TEMPORARY TABLE$USING A LITERAL. NOTE THAT &&THERE IS NO TRAILING SEMICOLON IN THE STRING. E!ECUTE IMMEDIATE CCREATE TABLE NATIVE (EMPNO NUMBER(13))C5 &&INSERT SOME ROWS USING A STRING.AGAIN$ THERE IS NO TRAILING SEMICOLON INSIDE THE STRING. 13 FOR V(COUNTER IN 1..13 LOOP 11 V(S"LSTRING %ICINSERT INTO NATIVE VALUES (C VV V(COUNTER VV C)C5 12 E!ECUTE IMMEDIATE V(S"LSTRING5 1) END LOOP5 1, && PRINT OUT THE CONTENTS OF THE TABLE USING AN ANONYMOUS PL/S"L BLOC'. HERE 1. &&WE PUT THE ENTIRE BLOC' INTO A SINGLE STRING(INCLUDING THE SEMICOLON). 1/ V(PLS"LBLOC'%I 10 CBEGIN 12 FOR V(REC IN (SELECT # FROM NATIVE) LOOP 1 DBMS(OUTPUT.PUT(LINE(V(REC.EMPNO)5 23 END LOOP5 21 END5C5 22 && AND NOW WE E!ECUTE THE ANONYMOUS BLOC'. 2) E!ECUTE IMMEDIATE V(PLS"LBLOC'5 2, &&FINALLY $ DROP THE TABLE. 2. E!ECUTE IMMEDIATE CDROP TABLE NATIVEC5 2/# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON S"L4 / 1 2 ) , . / 0 2 13 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 V(S"LSTRING VARCHAR2(233)5

1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
V(PLS"LBLOC' VARCHAR2(233)5 BEGIN &&FIRST CREATE A TEMPORARY TABLE$USING A LITERAL. NOTE THAT &&THERE IS NO TRAILING SEMICOLON IN THE STRING. E!ECUTE IMMEDIATE CCREATE TABLE NATIVE (EMPNO NUMBER(13))C5 &&INSERT SOME ROWS USING A STRING.AGAIN$ THERE IS NO TRAILING SEMICOLON INSIDE THE STRING. 13 FOR V(COUNTER IN 1..13 LOOP 11 V(S"LSTRING %ICINSERT INTO NATIVE VALUES (C VV V(COUNTER VV C)C5 12 E!ECUTE IMMEDIATE V(S"LSTRING5 1) END LOOP5 1, && PRINT OUT THE CONTENTS OF THE TABLE USING AN ANONYMOUS PL/S"L BLOC'. HERE 1. &&WE PUT THE ENTIRE BLOC' INTO A SINGLE STRING(INCLUDING THE SEMICOLON). 1/ V(PLS"LBLOC'%I 10 CBEGIN 12 FOR V(REC IN (SELECT # FROM NATIVE) LOOP 1 DBMS(OUTPUT.PUT(LINE(V(REC.EMPNO)5 23 END LOOP5 21 END5C5 22 && AND NOW WE E!ECUTE THE ANONYMOUS BLOC'. 2) E!ECUTE IMMEDIATE V(PLS"LBLOC'5 2, &&FINALLY $ DROP THE TABLE. 2. &&E!ECUTE IMMEDIATE CDROP TABLE NATIVEC5 2/# END5 S"L4 / 1 2 ) , . / 0 2 13 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 DESC NATIVE N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(13) S"L4 SELECT # FROM NATIVE5 EMPNO &&&&&&&&&& 1 2 ) , . / 0 2 13 13 ;DEF F989:<9=. 1 2 ) , . / 0 DECLARE V(S"LSTRING VARCHAR2(233)5 V(PLS"LBLOC' VARCHAR2(233)5 BEGIN &&FIRST CREATE A TEMPORARY TABLE$USING A LITERAL. NOTE THAT &&THERE IS NO TRAILING SEMICOLON IN THE STRING. E!ECUTE IMMEDIATE ) , . / 0 2

)/2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 CCREATE TABLE NATIVE1 (EMPNO VARCHAR(13))C5 &&INSERT SOME ROWS USING A STRING.AGAIN$ THERE IS NO TRAILING SEMICOLON INSIDE THE STRING. 13 FOR V(COUNTER IN 1..13 LOOP 11 V(S"LSTRING %ICINSERT INTO NATIVE1 VALUES (CCROWC VV V(COUNTER VV CCC)C5 12 E!ECUTE IMMEDIATE V(S"LSTRING5 1) END LOOP5 1, && PRINT OUT THE CONTENTS OF THE TABLE USING AN ANONYMOUS PL/S"L BLOC'. HERE 1. &&WE PUT THE ENTIRE BLOC' INTO A SINGLE STRING(INCLUDING THE SEMICOLON). 1/ V(PLS"LBLOC'%I 10 CBEGIN 12 FOR V(REC IN (SELECT # FROM NATIVE1) LOOP 1 DBMS(OUTPUT.PUT(LINE(V(REC.EMPNO)5 23 END LOOP5 21 END5C5 22 && AND NOW WE E!ECUTE THE ANONYMOUS BLOC'. 2) E!ECUTE IMMEDIATE V(PLS"LBLOC'5 2, &&FINALLY $ DROP THE TABLE. 2. &&E!ECUTE IMMEDIATE CDROP TABLE NATIVE1C5 2/# END5 S"L4 / ROW1 ROW2 ROW) ROW, ROW. ROW/ ROW0 ROW2 ROW ROW13 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 DESC NATIVE1 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO VARCHAR2(13) S"L4 SELECT # FROM NATIVE15 EMPNO &&&&&&&&&& ROW1 ROW2 ROW) ROW, ROW. ROW/ ROW0 ROW2 ROW ROW13 13 ;DEF F989:<9=.

)/)

S"L4 SELECT # FROM MY(EMPLOYEE5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 02) 'ING PRESIDENT 10&NOV&21 .333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 COMM 13 13 13 DEPTNO S"L4 DECLARE 2 S"L(STMT VARCHAR2(133)5 ) PLS"L(BLOC' VARCHAR2()33)5 , V(DEPTNO NUMBER(13) %I135 . V(TOTAL(EMPLOYEES NUMBER5 / V(NEW(DEPTNO NUMBER(13)5 0 BEGIN 2 &&CREATE TABLE MY(EMPLOYEE S"L(STMT %I CCREATE TABLE MY(EMPLOYEE C VV 13 CAS SELECT # FROM EMP WHERE DEPTNO I C VV V(DEPTNO5 11 E!ECUTE IMMEDIATE S"L(STMT5 12 &&INSERT RECORD INTO MY(EMPLOYEE TABLE 1) S"L(STMT%I 1, CINSERT INTO MY(EMPLOYEE 1. (EMPNO$ENAME$DEPTNO) 1/ VALUES 10 (%EMPNO$%ENAME$%DEPTNO)C5 12 E!ECUTE IMMEDIATE S"L(STMT USING 1$CPAVANC$135 1 &&SELECT TOTAL NUMBER OF RECORDS FROM MY(EMPLOYEE TABLE AND DISPLAY RESULTS 23 &&ON THE SCREEN 21 E!ECUTE IMMEDIATE CSELECT COUNT(#) FROM MY(EMPLOYEEC INTO V(TOTAL(EMPLOYEES5 22 DBMS(OUTPUT.PUT(LINE(CEMPLOYEES% C VV V(TOTAL(EMPLOYEES)5 2) &&UPDATE RECORD IN MY(EMPLOYEE TABLE 2, S"L(STMT%I 2. CUPDATE MY(EMPLOYEE SET DEPTNOI WHERE EMPNO I %1 CVV 2/ CRETURNING DEPTNO INTO %2C5 20 E!ECUTE IMMEDIATE S"L(STMT USING 1 RETURNING INTO V(NEW(DEPTNO5 22 DBMS(OUTPUT.PUT(LINE(CNEW DEPTNO%C VVV(NEW(DEPTNO)5 2 END5 )3 / EMPLOYEES% , NEW DEPTNO% PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. 1 DECLARE 2 S"L(STMT VARCHAR2(133)5 ) BEGIN , &&CREATE TABLE MY(EMPLOYEE1 . S"L(STMT %I CCREATE TABLE MY(EMPLOYEE1 C VV / CAS SELECT # FROM EMP WHERE DEPTNO I %DEPTNO C5 0 E!ECUTE IMMEDIATE S"L(STMT USING 135 2# END5 / DECLARE # ERROR 6< 8NK9 1% ORA&31320% 7NK= Q6;N6789F KD< 688DE9= TD; =6<6 =9TNKN<NDK DB9;6<NDKF ORA&3/.12% 6< 8NK9 0

)/,

A CREATE TABLE STATEMENT IS A DATA DEFINITION STATEMENT AND AS A RESULT IT CANNOT ACCEPTANY BIND ARGUMENTS

1 DECLARE 2 S"L(STMT VARCHAR2(133)5 ) V(DEPTNO NUMBER(13) %I135

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
, . / 0 2

)/.

V(TOTALEMPLOYEES NUMBER(13)5 BEGIN &&CREATE TABLE MY(EMPLOYEE2 S"L(STMT %I CCREATE TABLE MY(EMPLOYEE2 C VV CAS SELECT # FROM EMP C VV 13 CWHERE DEPTNO I C VV V(DEPTNO5 11 E!ECUTE IMMEDIATE S"L(STMT5 12 &&SELECT TOTAL NUMBER OF RECORDS FROM MY(EMPLOYEE2 TABLE 1) E!ECUTE IMMEDIATE CSELECT COUNT(#) FROM %MY(TABLEC INTO V(TOTALEMPLOYEES USING CMY(EMPLOYEE2C 1, 5 1. DBMS(OUTPUT.PUT(LINE(V(TOTALEMPLOYEES)5 1/# END5 S"L4 / DECLARE # ERROR 6< 8NK9 1% ORA&33 3)% NKQ68N= <6789 K6>9 ORA&3/.12% 6< 8NK9 1) S"L4 DESC MY(EMPLOYEE2 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,) ENAME VARCHAR2(13) JOB VARCHAR2( ) MGR NUMBER(,) HIREDATE DATE SAL NUMBER(0$2) COMM NUMBER(0$2) DEPTNO NUMBER(2) YOU CANNOT PASS NAMES OF SCHEMA OBJECTS TO DYNAMIC S"L STATEMENTS AS BIND ARGUMENTS.

1 DECLARE 2 S"L(STMT VARCHAR2(133)5 ) V(DEPTNO NUMBER(13) %I135 , V(TOTALEMPLOYEES NUMBER(13)5 . BEGIN / &&CREATE TABLE MY(EMPLOYEE2 0 S"L(STMT %I 2 CCREATE TABLE MY(EMPLOYEE2 C VV CAS SELECT # FROM EMP C VV 13 CWHERE DEPTNO I C VV V(DEPTNO5 11 E!ECUTE IMMEDIATE S"L(STMT5 12 &&SELECT TOTAL NUMBER OF RECORDS FROM MY(EMPLOYEE2 TABLE 1) E!ECUTE IMMEDIATE CSELECT COUNT(#) FROM C VV MY(EMPLOYEE2 INTO V(TOTALEMPLOYEES 1, 5 1. DBMS(OUTPUT.PUT(LINE(V(TOTALEMPLOYEES)5 1/# END5 S"L4 / E!ECUTE IMMEDIATE CSELECT COUNT(#) FROM C VV MY(EMPLOYEE2 INTO V(TOTALEMPLOYEES # ERROR 6< 8NK9 1)% ORA&3/..3% 8NK9 1)$ :D8?>K ,/% PLS&33).0% T6789$VN9E O; S9P?9K:9 ;9T9;9K:9 CMY(EMPLOYEE2C KD< 688DE9= NK <RNF :DK<9U< ORA&3/..3% 8NK9 1)$ :D8?>K 1% PL/S"L% S<6<9>9K< NSKD;9=

S"L4 DECLARE 2 S"L(STMT VARCHAR2(133)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) , . / 0 2 13 11 12 1) 1, 1. 1/ ) V(DEPTNO NUMBER(13) %I135 V(TOTALEMPLOYEES NUMBER(13)5 BEGIN &&CREATE TABLE MY(EMPLOYEE2 S"L(STMT %I CCREATE TABLE MY(EMPLOYEE2 C VV CAS SELECT # FROM EMP C VV CWHERE DEPTNO I C VV V(DEPTNO5 E!ECUTE IMMEDIATE S"L(STMT5 &&SELECT TOTAL NUMBER OF RECORDS FROM MY(EMPLOYEE2 TABLE E!ECUTE IMMEDIATE CSELECT COUNT(#) FROM C VV CMY(EMPLOYEE2C INTO V(TOTALEMPLOYEES 5 DBMS(OUTPUT.PUT(LINE(V(TOTALEMPLOYEES)5 END5 /

)//

PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

S"L4 DECLARE 2 S"L(STMT VARCHAR2(133)5 ) V(DEPTNO NUMBER(13) %I135 , V(TOTALEMPLOYEES NUMBER(13)5 . BEGIN / &&CREATE TABLE MY(EMPLOYEE2 0 S"L(STMT %I 2 CCREATE TABLE MY(EMPLOYEE2 C VV CAS SELECT # FROM EMP C VV 13 CWHERE DEPTNO I C VV V(DEPTNO5 11 E!ECUTE IMMEDIATE S"L(STMT5 12 &&SELECT TOTAL NUMBER OF RECORDS FROM MY(EMPLOYEE2 TABLE 1) E!ECUTE IMMEDIATE CSELECT COUNT(#) FROM MY(EMPLOYEE25C INTO V(TOTALEMPLOYEES 5 1, DBMS(OUTPUT.PUT(LINE(V(TOTALEMPLOYEES)5 1. END5 1/ / DECLARE # ERROR 6< 8NK9 1% ORA&33 11% NKQ68N= :R6;6:<9; ORA&3/.12% 6< 8NK9 1) THE SEMICOLON ADDED TO THE SELECT STATEMENT IS TREATED AS AN INVALID CHARACTER WHEN THE STATEMENT IS CREATED DYNAMICALLY. NESTED TABLES:

S"L4 CREATE TYPE BOO'S(TYPE AS OBJECT 2 (BOO'(NO NUMBER(,)$ ) BOO'(TITLE VARCHAR2(23)$ , AUTHOR VARCHAR2(13))5 . / TAB9 :;96<9=. S"L4 CREATE TYPE BOO'S AS TABLE OF BOO'(TYPE5 2 / W6;KNKS% TAB9 :;96<9= EN<R :D>BN86<NDK 9;;D;F. S"L4 SHOW ERRORS E;;D;F TD; TYPE BOO'S% LINE/COL ERROR

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 3/3 PL/S"L% CD>BN86<NDK ?KN< 6K68AFNF <9;>NK6<9= 1/2, PLS&33231% N=9K<NTN9; CBOO'(TYPEC >?F< 79 =9:86;9= S"L4 CREATE OR REPLACE TYPE BOO'S AS TABLE OF BOO'S(TYPE5 2 / TAB9 :;96<9=. CREATING TABLE USING NESTED TABLE? S"L4 CREATE TABLE STUDENT 2 (STUDENT(NO NUMBER(13) CONSTRAINT STUDENT(P' PRIMARY 'EY$ ) STUDENT(NAME VARCHAR2(13)$ , BOO'S(ISSUED BOO'S) . NESTED TABLE BOO'S(ISSUED STORE AS BOO'(TABLE5 T6789 :;96<9=.

)/0

BOO'S(ISSUED IS A COLUMN OF TABLE TYPE BOO'S AND BOO'(TABLE IS THE SYSTEM GENERATED TABLE WHICH WILL CONTAIN THE DATA ACTUALLY STORED IN THE NESTED TABLE.

EACH ROW OF THE TABLE CONTAINS A NESTED TABLE. TO INSERT ROWS IN THE NESTED TABLE$ WE NEED TO USE THE CONSTRUCTOR METHOD PROVIDED BY ORACLE.

1 INSERT INTO STUDENT 2 VALUES ) (133$CPAVANC$BOO'S(BOO'S(TYPE(31$CORACLE IN 21 DAYSC$C'EVINC)$ ,# BOO'S(TYPE(32$CORACLE IN DAYSC$CSMITHC))) S"L4 / 1 ;DE :;96<9=. S"L4 ED W;D<9 TN89 6TN9=<.7?T 1 INSERT INTO STUDENT 2 VALUES ) (131$C'UMARC$BOO'S(BOO'S(TYPE(31$CORACLE IN 21 DAYSC$C'EVINC)$ ,# BOO'S(TYPE(32$CORACLE IN DAYSC$CSMITHC))) . / 1 ;DE :;96<9=. BOO'S IS THE CONSTRUCTOR METHOD FOR TABLE TYPE BOO'S AND BOO'S(TYPE IS THE CONSTRUCTOR METHOD FOR OBJECT TYPE BOO'S(TYPE.

IN PL0SQL: S"L4 DECLARE 2 BOO'(VAR BOO'S5 ) BEGIN , BOO'(VAR%IBOO'S(BOO'S(TYPE(3)$CORACLE IN )DAYSC$CALLENC))5 . INSERT INTO STUDENT / VALUES 0 (132$CGAYATRIC$BOO'(VAR)5 2 END5 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT # FROM STUDENT5 STUDENT(NO STUDENT(NA &&&&&&&&&& &&&&&&&&&& BOO'S(ISSUED(BOO'(NO$ BOO'(TITLE$ AUTHOR) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 133 PAVAN BOO'S(BOO'S(TYPE(1$ CORACLE IN 21 DAYSC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN 131 'UMAR BOO'S(BOO'S(TYPE(1$ CORACLE IN 21 DAYSC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN 132 GAYATRI BOO'S(BOO'S(TYPE()$ CORACLE IN )DAYSC$ CALLENC))

)/2

DAYSC$ CSMITHC)) DAYSC$ CSMITHC))

IN PL0SQL: DECLARE MBOO' STUDENT.BOO'S(ISSUED-TYPE5 MNAME STUDENT.STUDENT(NAME-TYPE5 CURSOR C IS SELECT STUDENT(NAME$BOO'S(ISSUED FROM STUDENT5 BEGIN OPEN C5 LOOP FETCH C INTO MNAME$MBOO'5 E!IT WHEN C-NOTFOUND5 13 DBMS(OUTPUT.PUT(LINE(CBOO'S ISSUED TOC VV C C VVMNAME)5 11 &&LOOP OVER THE NESTED TABLE AND PRINT BOO'S DETAILS 12 FOR I IN 1..MBOO'.COUNT 1) LOOP 1, DBMS(OUTPUT.PUT(LINE(C C VVMBOO'(I).BOO'(TITLE)5 1. END LOOP5 1/ END LOOP5 10 CLOSE C5 12# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SET SERVEROUTPUT ON S"L4 / BOO'S ISSUED TO PAVAN ORACLE IN 21 DAYS ORACLE IN DAYS BOO'S ISSUED TO 'UMAR ORACLE IN 21 DAYS ORACLE IN DAYS BOO'S ISSUED TO GAYATRI ORACLE IN )DAYS PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. UPDATING T.E NESTED TABLE: THE OPERATOR ALLOWS NESTED TABLES TO BE MANIPULATED. S"L4 UPDATE THE ( 2 SELECT BOO'S(ISSUED FROM STUDENT WHERE STUDENT(NOI133) ) SET BOO'(TITLE I CVBC , WHERE BOO'(NO I 315 1 ;DE ?B=6<9=. 1 2 ) , . / 0 2

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM STUDENT5 STUDENT(NO STUDENT(NA &&&&&&&&&& &&&&&&&&&& BOO'S(ISSUED(BOO'(NO$ BOO'(TITLE$ AUTHOR) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 133 PAVAN BOO'S(BOO'S(TYPE(1$ CVBC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN DAYSC$ CSMITHC)) 131 'UMAR BOO'S(BOO'S(TYPE(1$ CORACLE IN 21 DAYSC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN 132 GAYATRI BOO'S(BOO'S(TYPE()$ CORACLE IN )DAYSC$ CALLENC)) DAYSC$ CSMITHC))

)/

IN PL0SQL: S"L4 DECLARE 2 BOO'(VAR BOO'S5 ) BEGIN , BOO'(VAR%IBOO'S(BOO'S(TYPE(,$CVB IN 1 DAYC$C'INGC)$BOO'S(TYPE(.$CPB IN 1 DAYC$CROLLENC))5 . UPDATE STUDENT / SET BOO'S(ISSUED I BOO'(VAR 0 WHERE STUDENT(NOI13)5 2 END5 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 SELECT # FROM STUDENT5 STUDENT(NO STUDENT(NA &&&&&&&&&& &&&&&&&&&& BOO'S(ISSUED(BOO'(NO$ BOO'(TITLE$ AUTHOR) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 133 PAVAN BOO'S(BOO'S(TYPE(1$ CVBC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN DAYSC$ CSMITHC)) 131 'UMAR BOO'S(BOO'S(TYPE(1$ CORACLE IN 21 DAYSC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN 132 GAYATRI BOO'S(BOO'S(TYPE()$ CORACLE IN )DAYSC$ CALLENC)) DAYSC$ CSMITHC))

1 DECLARE 2 BOO'(VAR BOO'S5 ) BEGIN , BOO'(VAR%IBOO'S(BOO'S(TYPE(,$CVB IN 1 DAYC$C'INGC)$BOO'S(TYPE(.$CPB IN 1 DAYC$CROLLENC))5 . UPDATE STUDENT / SET BOO'S(ISSUED I BOO'(VAR 0 WHERE STUDENT(NOI1325 2# END5 S"L4 / PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM STUDENT5 STUDENT(NO STUDENT(NA &&&&&&&&&& &&&&&&&&&& BOO'S(ISSUED(BOO'(NO$ BOO'(TITLE$ AUTHOR) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 133 PAVAN BOO'S(BOO'S(TYPE(1$ CVBC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN DAYSC$ CSMITHC)) 131 'UMAR BOO'S(BOO'S(TYPE(1$ CORACLE IN 21 DAYSC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN DAYSC$ CSMITHC))

)03

132 GAYATRI BOO'S(BOO'S(TYPE(,$ CVB IN 1 DAYC$ C'INGC)$ BOO'S(TYPE(.$ CPB IN 1 DAYC$ CROLLENC)) S"L4 INSERT INTO THE (SELECT BOO'S(ISSUED FROM STUDENT 2 WHERE STUDENT(NO I 131) ) VALUES , (BOO'S(TYPE(/$CJAVA IN 21 DAYSC$C'EVINC))5 1 ;DE :;96<9=. S"L4 SELECT # FROM STUDENT5 STUDENT(NO STUDENT(NA &&&&&&&&&& &&&&&&&&&& BOO'S(ISSUED(BOO'(NO$ BOO'(TITLE$ AUTHOR) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 133 PAVAN BOO'S(BOO'S(TYPE(1$ CVBC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN DAYSC$ CSMITHC)) 131 'UMAR BOO'S(BOO'S(TYPE(1$ CORACLE IN 21 DAYSC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN (TYPE(/$ CJAVA IN 21 DAYSC$ C'EVINC)) DAYSC$ CSMITHC)$ BOO'S

132 GAYATRI BOO'S(BOO'S(TYPE(,$ CVB IN 1 DAYC$ C'INGC)$ BOO'S(TYPE(.$ CPB IN 1 DAYC$ CROLLENC)) S"L4 DELETE FROM STUDENT 2 WHERE STUDENT(NOI1325 1 ;DE =989<9=.

S"L4 SELECT # FROM STUDENT5 STUDENT(NO STUDENT(NA &&&&&&&&&& &&&&&&&&&& BOO'S(ISSUED(BOO'(NO$ BOO'(TITLE$ AUTHOR) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 133 PAVAN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
BOO'S(BOO'S(TYPE(1$ CVBC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN DAYSC$ CSMITHC)) DAYSC$ CSMITHC)$ BOO'S 131 'UMAR BOO'S(BOO'S(TYPE(1$ CORACLE IN 21 DAYSC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN (TYPE(/$ CJAVA IN 21 DAYSC$ C'EVINC)) DELETING: FOR DELETING A ROW FROM THE NESTED TABLE USING THE CONDITION FROM THE NESTED TABLE. S"L4 DELETE FROM THE( 2 SELECT BOO'S(ISSUED FROM STUDENT WHERE STUDENT(NOI133) ) WHERE BOO'(NOI25 1 ;DE =989<9=. S"L4 SELECT # FROM STUDENT5 STUDENT(NO STUDENT(NA &&&&&&&&&& &&&&&&&&&& BOO'S(ISSUED(BOO'(NO$ BOO'(TITLE$ AUTHOR) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 133 PAVAN BOO'S(BOO'S(TYPE(1$ CVBC$ C'EVINC)) 131 'UMAR BOO'S(BOO'S(TYPE(1$ CORACLE IN 21 DAYSC$ C'EVINC)$ BOO'S(TYPE(2$ CORACLE IN (TYPE(/$ CJAVA IN 21 DAYSC$ C'EVINC)) DAYSC$ CSMITHC)$ BOO'S

)01

*ARRAYS:

CREATING *ARRAYS: S"L4 CREATE OR REPLACE TYPE BOO'S(ARRAY AS VARRAY(13) BOO'S(TYPE5 2 / W6;KNKS% TAB9 :;96<9= EN<R :D>BN86<NDK 9;;D;F. S"L4 SHOW ERRORS E;;D;F TD; TYPE BOO'S(ARRAY% LINE/COL ERROR &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 1/)2 PLS&3313)% EK:D?K<9;9= <R9 FA>7D8 OBOO'S(TYPEO ER9K 9UB9:<NKS DK9 DT <R9 TD88DENKS% DT TR9 FA>7D8 ODTO E6F F?7F<N<?<9= TD; OBOO'S(TYPEO <D :DK<NK?9. 1# CREATE OR REPLACE TYPE BOO'S(ARRAY AS VARRAY(13) OF BOO'S(TYPE5 S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
TAB9 :;96<9=. S"L4 CREATE TABLE STUDENTS 2 (STUDENT(NO NUMBER(13)$ ) STUDENT(NAME VARCHAR2(13)$ , BOO'S(ISSUED BOO'S(ARRAY)5 T6789 :;96<9=. 1 INSERT INTO STUDENTS 2 VALUES ) (133$CPAVANC$BOO'S(ARRAY(BOO'S(TYPE(1$CORACLE IN 21 DAYSC$C'EVINC)$BOO'S(TYPE(2$ ,# CVB IN 21 DAYSC$CLOLC))) S"L4 / 1 ;DE :;96<9=.

)02

1 INSERT INTO STUDENTS 2 VALUES ) (131$C'UMARC$BOO'S(ARRAY(BOO'S(TYPE(1$CORACLE IN 21 DAYSC$C'EVINC)$BOO'S(TYPE(2$ ,# CVB IN 21 DAYSC$CLOLC))) S"L4 / 1 ;DE :;96<9=.

1 INSERT INTO STUDENTS 2 VALUES ) (132$CGAYATRIC$BOO'S(ARRAY(BOO'S(TYPE(1$CORACLE IN 21 DAYSC$C'EVINC)$BOO'S(TYPE(2$ ,# CVB IN 21 DAYSC$CLOLC))) S"L4 / 1 ;DE :;96<9=. S"L4 SELECT # FROM STUDENTS5 STUDENT(NO STUDENT(NA &&&&&&&&&& &&&&&&&&&& BOO'S(ISSUED(BOO'(NO$ BOO'(TITLE$ AUTHOR) &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 133 PAVAN BOO'S(ARRAY(BOO'S(TYPE(1$ CORACLE IN 21 DAYSC$ C'EVINC)$ BOO'S(TYPE(2$ CVB IN 21 DAYSC$ CLOLC)) 131 'UMAR BOO'S(ARRAY(BOO'S(TYPE(1$ CORACLE IN 21 DAYSC$ C'EVINC)$ BOO'S(TYPE(2$ CVB IN 21 DAYSC$ CLOLC)) 132 GAYATRI BOO'S(ARRAY(BOO'S(TYPE(1$ CORACLE IN 21 DAYSC$ C'EVINC)$ BOO'S(TYPE(2$ CVB IN 21 DAYSC$ CLOLC)) USING *ARRAYS IN PL0SQL:

TO MODIFY A STORED VARRAY$IT HAS TO BE SELECTED IN TO PL/S"L VARIABLE AND THEN INSERTED BAC' IN TO THE TABLE. DECLARE LIST(OF(BOO'S BOO'S(ARRAY5 BEGIN SELECT BOO'S(ISSUED INTO LIST(OF(BOO'S FROM STUDENTS

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
WHERE STUDENT(NOI1335 DBMS(OUTPUT.PUT(LINE(G NO OF BOO'S ISSUED VV TO(CHAR (LIST(OF(BOO'S.COUNT))5 DBMS(OUTPUT.PUT(LINE(GARRAY LIMIT G VVLIST(OF(BOO'S.LIMIT)5 LIST(OF(BOO'S.E!TEND5 LIST(OF(BOO'S(LIST(OF(BOO'S.COUNT) %IBOO'(TYPE(/$PASCAL IN DAYS$'EVIN)5 UPDATE STUDENTS SET BOO'S(ISSUED I LIST(OF(BOO'S WHERE STUDENT(NOI1335 COMMIT5 END5 SI)ILARITIES OF *ARRAYS AND NESTED TABLES: BOTH VARRAYS AND NESTED TABLES ARE COLLECTIONS. BOTHE TYPES ALLOW ACCESS TO INDIVIDUAL ELEMENTS USING SUBSCRIPT NOTATION. BOTH TYPES CAN BE STORED IN DATABASE TABLES. DIFFERENCES OF *ARRAYS AND NESTED TABLES: VARRAYS HAVE MA!IMUM SIZE$ AS SPECIFIED AT TIME OF CREATION. WHILE NESTED TABLES DO NOT.

)0)

VARRAYS ARE STORED IN LINE WITH THE CONTAINING TABLE$ WHILE NESTED TABLES ARE STORED IN A SEPARATE TABLE$ WHICH CAN HAVE DIFFERENT STORAGE CHARACTERSTICS. ROWS IN THE NESTED TABLE CAN BE ACCESSED INDIVIDUALLY BY USING THE G THE G CLAUSE$ WHERE AS IN THE VARRAYS ALL THE ROWS SHOULD BE ACCESSED AS ONE OBJECT AND IS TO NE MANIPULATED BY USING PL/S"L BLOC'S. AD*ANTAGES: IMPLEMENTATIONS OF ONE&TO&MANY RELATIONSHIPS. TRIGGERS

S"L4 CREATE TABLE EMP(D 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 CREATE TABLE TRIG(INSERT 2 (ACTION VARCHAR2(133)$ ) TDATE TIMESTAMP(/))5 T6789 :;96<9=.

1 CREATE TABLE TRIG(UPDATE 2 (ACTION VARCHAR2(133)$ )# TDATE TIMESTAMP(/)) S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
T6789 :;96<9=. 1 CREATE TABLE TRIG(DELETE 2 (ACTION VARCHAR2(133)$ )# TDATE TIMESTAMP(/)) S"L4 / T6789 :;96<9=. INSERT TRIGGERS:

)0,

S"L4 CREATE OR REPLACE TRIGGER BFORE(INSERT(TAB 2 BEFORE INSERT ON EMP(D ) BEGIN , INSERT INTO TRIG(INSERT . VALUES / (CBFORE INSERT TAB LVLC$SYSTIMESTAMP)5 0 END5 2 / T;NSS9; :;96<9=.

1 CREATE OR REPLACE TRIGGER BFORE(INSERT(ROW 2 BEFORE INSERT ON EMP(D FOR EACH ROW ) BEGIN , INSERT INTO TRIG(INSERT . VALUES / (CBFORE INSERT ROW LVLC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER AFTER(INSERT(TAB 2 AFTER INSERT ON EMP(D ) BEGIN , INSERT INTO TRIG(INSERT . VALUES / (CAFTER INSERT TAB LVLC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER AFTER(INSERT(ROW 2 AFTER INSERT ON EMP(D FOR EACH ROW ) BEGIN , INSERT INTO TRIG(INSERT . VALUES / (CAFTER INSERT ROW LVLC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. SELECTING TRIGGERS IN USER2OBJECTS:

S"L4 SELECT OBJECT(NAME$OBJECT(TYPE FROM USER(OBJECTS 2 WHERE OBJECT(TYPEICTRIGGERC5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
OBJECT(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& OBJECT(TYPE &&&&&&&&&&&&&&&&&& AFTER(INSERT(ROW TRIGGER AFTER(INSERT(TAB TRIGGER BFORE(INSERT(ROW TRIGGER BFORE(INSERT(TAB TRIGGER S"L4 SELECT TRIGGER(NAME FROM USER(TRIGGERS5 TRIGGER(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& AFTER(INSERT(ROW AFTER(INSERT(TAB BFORE(INSERT(ROW BFORE(INSERT(TAB

)0.

S"L4 SELECT # FROM USER(TRIGGERS 2 WHERE TRIGGER(NAMEICBFORE(INSERT(TABC5 TRIGGER(NAME TRIGGER(TYPE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& TRIGGERING(EVENT &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TABLE(OWNER BASE(OBJECT(TYPE TABLE(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& COLUMN(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& REFERENCING(NAMES &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& WHEN(CLAUSE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STATUS &&&&&&&& DESCRIPTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ACTION(TYPE TRIGGER(BODY &&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BFORE(INSERT(TAB BEFORE STATEMENT INSERT SCOTT TABLE EMP(D REFERENCING NEW AS NEW OLD AS OLD ENABLED BFORE(INSERT(TAB BEFORE INSERT ON EMP(D PL/S"L BEGIN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
INSERT INTO TRIG(INSERT VALUES (CBFORE INSERT TAB LVLC$SYSTIMESTAMP)5 END5 S"L4 DESC USER(TRIGGERS N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TRIGGER(NAME VARCHAR2()3) TRIGGER(TYPE VARCHAR2(1/) TRIGGERING(EVENT VARCHAR2(220) TABLE(OWNER VARCHAR2()3) BASE(OBJECT(TYPE VARCHAR2(1/) TABLE(NAME VARCHAR2()3) COLUMN(NAME VARCHAR2(,333) REFERENCING(NAMES VARCHAR2(122) WHEN(CLAUSE VARCHAR2(,333) STATUS VARCHAR2(2) DESCRIPTION VARCHAR2(,333) ACTION(TYPE VARCHAR2(11) TRIGGER(BODY LONG

)0/

S"L4 SELECT TRIGGER(BODY FROM USER(TRIGGERS 2 WHERE TRIGGER(NAMEICBFORE(INSERT(TABC5 TRIGGER(BODY &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BEGIN INSERT INTO TRIG(INSERT VALUES (CBFORE INSERT TAB LVLC$SYSTIMESTAMP)5 END5 S"L4 SELECT # FROM TRIG(INSERT5 KD ;DEF F989:<9= S"L4 INSERT INTO EMP(D 2 (EMPNO$DEPTNO) ) VALUES , (1$13)5 1 ;DE :;96<9=. S"L4 SELECT # FROM TRIG(INSERT5 ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BFORE INSERT TAB LVL 1 &SEP&3. 12..2.) .333333 AM BFORE INSERT ROW LVL 1 &SEP&3. 12..2.) .333333 AM AFTER INSERT ROW LVL 1 &SEP&3. 12..2.) .333333 AM AFTER INSERT TAB LVL 1 &SEP&3. 12..2.) .333333 AM

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 DROP TRIGGER BFORE(INSERT(TAB5 T;NSS9; =;DBB9=. 1# DROP TRIGGER BFORE(INSERT(ROW S"L4 / T;NSS9; =;DBB9=. 1# DROP TRIGGER AFTER(INSERT(TAB 2 / T;NSS9; =;DBB9=. 1# DROP TRIGGER AFTER(INSERT(ROW S"L4 / T;NSS9; =;DBB9=.

)00

UPDATING:

1 CREATE OR REPLACE TRIGGER BFORE(UPDATE(TAB 2 BEFORE UPDATE ON EMP(D ) BEGIN , INSERT INTO TRIG(UPDATE . VALUES / (CBFORE UPDATE TAB LVLC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER BFORE(UPDATE(ROW 2 BEFORE UPDATE ON EMP(D FOR EACH ROW ) BEGIN , INSERT INTO TRIG(UPDATE . VALUES / (CBFORE UPDATE ROW LVLC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER AFTER(UPDATE(ROW 2 AFTER UPDATE ON EMP(D FOR EACH ROW ) BEGIN , INSERT INTO TRIG(UPDATE . VALUES / (CAFTER UPDATE ROW LVLC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=.

1 CREATE OR REPLACE TRIGGER AFTER(UPDATE(TAB 2 AFTER UPDATE ON EMP(D ) BEGIN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
, INSERT INTO TRIG(UPDATE . VALUES / (CAFTER UPDATE TAB LVLC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. S"L4 SELECT TRIGGER(NAME FROM USER(TRIGGERS5 TRIGGER(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& AFTER(UPDATE(ROW AFTER(UPDATE(TAB BFORE(UPDATE(ROW BFORE(UPDATE(TAB S"L4 SELECT # FROM TRIG(UPDATE5 KD ;DEF F989:<9= S"L4 UPDATE EMP(D 2 SET SALISALJ133 ) WHERE EMPNOI00225 1 ;DE ?B=6<9=. S"L4 SELECT # FROM TRIG(UPDATE5 ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BFORE UPDATE TAB LVL 1 &SEP&3. 31.3).23.333333 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3).23.333333 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3).23.333333 AM AFTER UPDATE TAB LVL 1 &SEP&3. 31.3).23.333333 AM S"L4 DELETE FROM TRIG(UPDATE5 , ;DEF =989<9=. S"L4 SELECT # FROM TRIG(UPDATE5 KD ;DEF F989:<9= S"L4 UPDATE EMP(D 2 SET SAL I SALJ1335 1. ;DEF ?B=6<9=. S"L4 SELECT # FROM TRIG(UPDATE5 ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BFORE UPDATE TAB LVL

)02

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM

)0

ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM BFORE UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE ROW LVL 1 &SEP&3. 31.3,.3/.333331 AM AFTER UPDATE TAB LVL 1 &SEP&3. 31.3,.3/.333331 AM )2 ;DEF F989:<9=. S"L4 DROP TRIGGER BFORE(UPDATE(TAB5 T;NSS9; =;DBB9=. 1# DROP TRIGGER BFORE(UPDATE(ROW S"L4 / T;NSS9; =;DBB9=. 1# DROP TRIGGER AFTER(UPDATE(ROW S"L4 / T;NSS9; =;DBB9=. 1# DROP TRIGGER AFTER(UPDATE(TAB S"L4 / T;NSS9; =;DBB9=. S"L4 SELECT TRIGGER(NAME FROM USER(TRIGGERS5

)23

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
KD ;DEF F989:<9=

)21

DELETION: S"L4 SELECT # FROM TRIG(DELETE5 KD ;DEF F989:<9= S"L4 CREATE OR REPLACE TRIGGER BFORE(DELETE(ROW 2 BEFORE DELETE ON EMP(D FOR EACH ROW ) BEGIN , INSERT INTO TRIG(DELETE . VALUES / (CBFORE DELETE ROW LVLC$SYSTIMESTAMP)5 0 END5 2 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER BFORE(DELETE(TAB 2 BEFORE DELETE ON EMP(D ) BEGIN , INSERT INTO TRIG(DELETE . VALUES / (CBFORE DELETE TAB LVLC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER AFTER(DELETE(TAB 2 AFTER DELETE ON EMP(D ) BEGIN , INSERT INTO TRIG(DELETE . VALUES / (CAFTER DELETE TAB LVLC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=.

1 CREATE OR REPLACE TRIGGER AFTER(DELETE(ROW 2 AFTER DELETE ON EMP(D FOR EACH ROW

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) BEGIN , INSERT INTO TRIG(DELETE . VALUES / (CAFTER DELETE ROW LVLC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. S"L4 SELECT TRIGGER(NAME FROM USER(TRIGGERS5 TRIGGER(NAME &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& AFTER(DELETE(ROW AFTER(DELETE(TAB BFORE(DELETE(ROW BFORE(DELETE(TAB S"L4 DELETE FROM EMP(D 2 WHERE EMPNOI00225 3 ;DEF =989<9=. S"L4 SELECT # FROM TRIG(DELETE5 ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BFORE DELETE TAB LVL 1 &SEP&3. 31.22.. .333331 AM AFTER DELETE TAB LVL 1 &SEP&3. 31.22.. .333331 AM HERE NO ROWS ARE DELETED BCOZ TABLE LEVEL TRIGGERS FIRED. S"L4 DELETE FROM TRIG(DELETE5 2 ;DEF =989<9=.

)22

S"L4 DELETE FROM EMP(D 2 WHERE EMPNOI0.//5 1 ;DE =989<9=. S"L4 SELECT # FROM TRIG(DELETE5 ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BFORE DELETE TAB LVL 1 &SEP&3. 31.2)..0.333333 AM

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
BFORE DELETE ROW LVL 1 &SEP&3. 31.2)..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2)..0.333333 AM AFTER DELETE TAB LVL 1 &SEP&3. 31.2)..0.333333 AM S"L4 DELETE FROM TRIG(DELETE5 , ;DEF =989<9=. S"L4 DELETE FROM EMP(D 2 5 12 ;DEF =989<9=. S"L4 SELECT # FROM TRIG(DELETE5 ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BFORE DELETE TAB LVL 1 &SEP&3. 31.2,..0.333333 AM BFORE DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM BFORE DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM BFORE DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM BFORE DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM BFORE DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM BFORE DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM

)2)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
BFORE DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM BFORE DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM BFORE DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM BFORE DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM BFORE DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM BFORE DELETE ROW LVL ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE ROW LVL 1 &SEP&3. 31.2,..0.333333 AM AFTER DELETE TAB LVL 1 &SEP&3. 31.2,..0.333333 AM 2/ ;DEF F989:<9=. REF CURSORS:

)2,

A PL/S"L PROGRAM CANNOT PASS A CURSOR AS A PARAMETER TO ANOTHER PROGRAM. A PL/S"L PROGRAM CAN ONLY OPEN THE CURSOR AND PROCESS THE CORRESPONDING INFORMATION WITHIN THE PROGRAM ITSELF. TO WOR' AROUND THE FUNCTIONAL LIMITATIONS OF CURSORS A PROGRAM CAN INSTEAD DECLARE TWO DIFFERENT CURSOR TYPES AND CORRESPONDING CURSOR VARIABLES. CURSOR CAN BE DECLARED AS EITHER STRONG OR WEA'. THESE TYPES OF CURSOR DECLARATIONS ARE USED TO PASS A CURSOR AS A PARAMETER TO A PROGRAM OR A PAC'AGE. WHETHER A CURSOR IS STRONG OR WEA' DEPENDS UPON THE WAY IT IS DECLARED. FOR E!AMPLE $ THE CURSOR TYPE DECLARED BELOW IS A STRONG CURSOR TYPE I.E.$ THE CURSOR TYPES DECLARATION INCLUDES A RETURN CLAUSE THAT SPECIFIES A SHAPE OR SET OF ATTRIBUTES FOR THE CURSOR TYPE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
TYPE CUR(EMP IS REF CURSOR RETURN EMP.EMPNO-TYPE5 EMP(CURSOR1 CUR(EMP5 &&&&&&&&&&&&&&&& CURSOR VARIABLE. EMP(CURSOR2 CUR(EMP5 &&&&&&&&&&&&&&&& CURSOR VARIABLE. EMP(CURSOR) CUR(EMP5 &&&&&&&&&&&&&&&& CURSOR VARIABLE.

)2.

A STRONG CURSOR TYPE CAN ONLY RETURN THE DATA TYPE SPECIFIED IN THE RETURN TYPE. THEREFORE$ A STRONG CURSOR TYPE RESTRICTSTHE DEFINITION OF SUBSE"UENT CURSOR VARIABLES THAT USE THE TYPE.

THE FOLLOWING CURSOR TYPE IS WEA' BECAUSE IT DOES NOT INCLUDE A SHAPE SPECIFICATION N.9.$ THERE IS NO RETURN CLAUSE.Z A PROGRAM CAN USE THE WEA' CURSOR TYPE TO DECLARE A CURSOR VARIABLE WITH AN Y SHAPE. A WEA' CURSOR TYPE CAN RETURN ANY DATATYPE AS THERE IS NO RETURN CLAUSE. SINCE THERE IS NO RETURN VALUE FOR THE CURSOR $ THE CURSOR VARIABLE IS SHAPE INDEPENDENT. THIS ADDS FLE!IBILITY TO THE CURSOR VARIABLES. FOR E!AMPLE% TYPE CUR(EMP IS REF CURSOR5 S"L4 CREATE OR REPLACE PAC'AGE DEPT(DATA AS 2 TYPE DEPTCURTYP IS REF CURSOR RETURN DEPT-ROWTYPE5 ) PROCEDURE OPEN(DEPT(CV(DEPT(CV IN OUT DEPTCURTYP)5 , END DEPT(DATA5 . / P6:L6S9 :;96<9=. S"L4 CREATE OR REPLACE PAC'AGE BODY DEPT(DATA AS 2 PROCEDURE OPEN(DEPT(CV(DEPT(CV IN OUT DEPTCURTYP) IS ) BEGIN , OPEN DEPT(CV FOR SELECT # FROM DEPT5 . END OPEN(DEPT(CV5 / END DEPT(DATA5 0 / P6:L6S9 7D=A :;96<9=. WHEN U DECLARE A CURSOR VARIABLE AS THE FORMAL PARAMETER OF A SUBPROGRAM THAT OPENS THE CURSOR VARIABLE. YOU MUST SPECIFY THE IN OUT MODE. THAT WAY$THE SUBPROGRAM CAN PASS A AN OPEN CURSOR BAC' TO THE CALLER. DECLARE A VARIABLE OF TYPE REFCURSOR AS SHOWN BELOW.

VARIABLE VARDEPTCV REFCURSOR

E/ECUTE T.E PAC-AGE +IT. T.E SPECIFIED PROCEDURE ALONG +IT. T.E CURSOR AS S.O+N BELO+: S"L4 E!ECUTE DEPT(DATA.OPEN(DEPT(CV(%VARDEPTCV)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 PRINT VARDEPTNO S"L4 PRINT VARDEPTCV DEPTNO DNAME &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 ACCOUNTING 23 RESEARCH )3 SALES ,3 OPERATIONS LOC NEW YOR' DALLAS CHICAGO BOSTON

)2/

ALTERNATIVELY$ YOU CAN USE THE SET AUTOPRINT ON COMMAND BEFORE E!ECUTING THE PAC'AGE$ TODISPLAY THE "UERY RESULTS AUTOMATICALLY. USE THE SET AUTOPRINT OFF COMMAND TO PUT AUTOPRINT OFF. THE PROCEDURE CAN BE E!ECUTED MULTIPLE TIMES USING THE SAME OR A DIFFERENT REFCURSOR BIND VARIABLE AS SHOWN BELOW% S"L4 VARIABLE PCV REFCURSOR S"L4 SET AUTOPRINT ON S"L4 E!ECUTE DEPT(DATA.OPEN(DEPT(CV(%PCV)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DEPTNO DNAME &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 ACCOUNTING 23 RESEARCH )3 SALES ,3 OPERATIONS S"L4 SET AUTOPRINT OFF ALTERNATIVELY$ YOU CAN USE A STANDALONE PROCEDURE TO OPEN THE CURSOR VARIABLE. SIMPLE DEFINE THE REFCURSOR TYPE IN A SEPARATE PAC'AGE$ THEN REFERENCE THAT TYPE IN THE STANDALONE PROCEDURE. FOR INSTANCE $ IF YOU CREATE THE FOLLOWING (BODILESS) PAC'AGE$ U CAN CREATE STANDALONE PROCEDURE THAT REFERENCE THE TYPES IT DEFINES% S"L4 CREATE OR REPLACE PAC'AGE CV(TYPES AS 2 TYPE GENERICCURTYPE IS REFCURSOR5 ) TYPE EMPCURTYP IS REF CURSOR RETURN EMP-ROWTYPE5 , TYPE DEPTCURTYP IS REF CURSOR RETURN DEPT-ROWTYPE5 . END CV(TYPES5 / / W6;KNKS% P6:L6S9 :;96<9= EN<R :D>BN86<NDK 9;;D;F. S"L4 SHOW ERRORS E;;D;F TD; PAC'AGE CV(TYPES% LINE/COL ERROR &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 2/2, PLS&3313)% EK:D?K<9;9= <R9 FA>7D8 OREFCURSORO ER9K 9UB9:<NKS DK9 DT <R9 TD88DENKS% ( 6;;6A 8N>N<9= K9E B;NQ6<9 ;6KS9 ;9:D;= VARRAY( :R6;(76F9 K?>79;(76F9 =9:N>68 =6<9(76F9 :8D7(76F9 78D7(76F9 7TN89(76F9 <6789 ;9T D7X9:< TNU9= Q6;ANKS DB6P?9 TR9 FA>7D8 O;6KS9O E6F F?7F<N<?<9= TD; OREFCURSORO <D :DK<NK?9. LOC NEW YOR' DALLAS CHICAGO BOSTON

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 CREATE OR REPLACE PAC'AGE CV(TYPES AS 2 TYPE GENERICCURTYPE IS REF CURSOR5 ) TYPE EMPCURTYP IS REF CURSOR RETURN EMP-ROWTYPE5 , TYPE DEPTCURTYP IS REF CURSOR RETURN DEPT-ROWTYPE5 .# END CV(TYPES5 S"L4 / P6:L6S9 :;96<9=.

)20

IN THE FOLLOWING E!AMPLE $ YOU CREATE A STANDLONE PROCEDURE THAT REFERENCES THE REF CURSOR TYPE EMPCURTYP$ WHICH IS DEFINED IN THE PAC'AGE CV(TYPES% S"L4 CREATE PROCEDURE OPEN(EMP(CV 2 (EMP(CV IN OUT CV(TYPES.EMPCURTYP) AS ) BEGIN , OPEN EMP(CV FOR SELECT # FROM EMP5 . END OPEN(EMP(CV5 / / P;D:9=?;9 :;96<9=. S"L4 VARIABLE P REFCURSOR S"L4 E!ECUTE OPEN(EMP(CV(%P)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. S"L4 PRINT P EMPNO ENAME JOB MGR HIREDATE &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 1, ;DEF F989:<9=. SAL )33 .33 1,33 COMM )3 )3 23 )3 )3 13 23 13 3 23 13 )3 23 )3 DEPTNO 23

S"L4 CREATE OR REPLACE PAC'AGE EMP(DATA AS 2 TYPE GENERICCURTYP IS REF CURSOR5 ) TYPE EMPCURTYP IS REF CURSOR RETURN EMP-ROWTYPE5 , PROCEDURE OPEN(EMP(CV(EMP(CV IN OUT EMPCURTYP$ CHOICE IN NUMBER)5 . END EMP(DATA5 / / P6:L6S9 :;96<9=. S"L4 CREATE OR REPLACE PAC'AGE BODY EMP(DATA AS 2 PROCEDURE OPEN(EMP(CV(EMP(CV IN OUT EMPCURTYP$ CHOICE IN NUMBER) ) IS , BEGIN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
IF CHOICE I 1 THEN OPEN EMP(CV FOR SELECT # FROM EMP WHERE COMM IS NOT NULL5 ELSIF CHOICE I 2 THEN OPEN EMP(CV FOR 13 SELECT # FROM EMP WHERE SAL 4 2.335 11 ELSIF CHOICE I ) THEN 12 OPEN EMP(CV FOR 1) SELECT # FROM EMP WHERE DEPTNOI235 1, END IF5 1. END OPEN(EMP(CV5 1/ END EMP(DATA5 10 / P6:L6S9 7D=A :;96<9=. S"L4 VARIABLE EMPCUR REFCURSOR S"L4 SET AUTOPRINT ON S"L4 E!ECUTE EMP(DATA.OPEN(EMP(CV(%EMPCUR$))5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0.// JONES MANAGER 02) 32&APR&21 2 0. 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 S"L4 E!ECUTE EMP(DATA.OPEN(EMP(CV(%EMPCUR$2)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. EMPNO ENAME JOB MGR HIREDATE &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0.// JONES MANAGER 02) 32&APR&21 0/ 2 BLA'E MANAGER 02) 31&MAY&21 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 S"L4 E!ECUTE EMP(DATA.OPEN(EMP(CV(%EMPCUR$1)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 SAL 2 0. 22.3 23 13 23 COMM 23 )3 DEPTNO COMM 23 23 23 23 DEPTNO . / 0 2

)22

FOR MORE FLE!IBILITY $ YOU CAN PASS A CURSOR VARIABLE AND SELECTOR TO A STORED PROCEDURE THAT E!ECUTES "UERIES WITH DIFFERENT RETURN TYPES. S"L4 CREATE OR REPLACE PAC'AGE EMP(DATA AS 2 TYPE GENERICCURTYP IS REF CURSOR5 ) TYPE EMPCURTYP IS REF CURSOR RETURN EMP-ROWTYPE5 , PROCEDURE OPEN(CV(GENERIC(CV IN OUT GENERICCURTYP$ CHOICE IN NUMBER)5 . END EMP(DATA5 / / P6:L6S9 :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 CREATE OR REPLACE PAC'AGE BODY EMP(DATA AS 2 PROCEDURE OPEN(CV(GENERIC(CV IN OUT GENERICCURTYP$ CHOICE IN NUMBER) ) IS , BEGIN . IF CHOICEI1 THEN / OPEN GENERIC(CV FOR SELECT # FROM EMP5 0 ELSIF CHOICE I 2 THEN 2 OPEN GENERIC(CV FOR SELECT # FROM DEPT5 ELSIF CHOICEI) THEN 13 OPEN GENERIC(CV FOR SELECT # FROM SALGRADE5 11 END IF5 12 END OPEN(CV5 1) END EMP(DATA5 1, / P6:L6S9 7D=A :;96<9=. S"L4 VARIABLE CUR REFCURSOR S"L4 SET AUTOPRINT ON S"L4 E!ECUTE EMP(DATA.OPEN(CV(%CUR$))5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. GRADE LOSAL HISAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 1 033 1233 2 1231 1,33 ) 1,31 2333 , 2331 )333 . )331 S"L4 E!ECUTE EMP(DATA.OPEN(CV(%CUR$2)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=. DEPTNO DNAME &&&&&&&&&& &&&&&&&&&&&&&& &&&&&&&&&&&&& 13 ACCOUNTING 23 RESEARCH )3 SALES ,3 OPERATIONS LOC NEW YOR' DALLAS CHICAGO BOSTON

)2

S"L4 E!ECUTE EMP(DATA.OPEN(CV(%CUR$1)5 PL/S"L B;D:9=?;9 F?::9FFT?88A :D>B89<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMPNO ENAME JOB MGR HIREDATE SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 0.// JONES MANAGER 02) 32&APR&21 2 0. 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 1, ;DEF F989:<9=. ORACLE 9I FEATURES: ORACLE OFFERS A COMPREHENSIVE HIGH&PERFORMANCE INFRASTRUCTURE FOR E& BUSSINESS. ORACLE I INCLDES EVERYTHING NEEDED TO DEVELOP$ DEPLOY AND MANAGE INTERNET APPLICATIONS. IN ORACLE I THERE ARE TWO PRODUCTS$ THEY ARE ORACLE I APPLICATION SERVER. ORACLE I DATABASE SERVER. BOTH PROVIDE COMPLETE AND SIMPLE INFRASTRUCTURE FOR INTERNET APPLICATIONS. THE ORACLE I APPLICATION SERVER RUNS ALL YOUR APPLICATIONS. THE ORACLE I DATABASE STORES ALL YOUR DATA. BASIC SELECT STATE)ENT: COMM 23 )3 )3 23 )3 )3 13 23 13 )3 23 )3 23 13 DEPTNO

) 3

SELECT #V ] [DISTINCT\ COLUMNVE!PRESION [ALIAS\$**..^ FROM TABLE(NAME5

+RITING SQL STATE)ENTS:

S"L STATEMENTS ARE NOT CASE SENSITIVE. CAN BE ON ONE OR MORE LINES. 'EYWORDS CANNOT BE ABBRIVATED OR SPLIT ACROSS LINES. CLAUSES ARE USUALLY PLACED ON SEPARATE LINES.

CHARACTER STRINGS AND DATE VALUES ARE ENCLOSED IN SINGLE "UATATION MAR'S. CHARACTER VALUES ARE CASE SENSITIVE AND DATE VALUES ARE FORMAT SENSITIVE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
THE DEFAULT DATE FORMAT IS DD&MON&YY$DD&MM&YY$DD&MM&RR. COLU)N .EADING DEFAULTS: ISQL*PLUS: DEFAULT HEADING JUSTIFICATION 1 CENTRE. HEADING DISPLAY 1 UPPERCASE. SQL*PLUS: CHRACTER AND DATE COLUMNS HEADINGS LEFT JUSTIFIED. NUMBER COLUMNS HEADINGS ARE RIGHT JUSTIFIED. DEFAULT HEADING DISPLAY& UPPERCASE

) 1

ISQL*PLUS: AN ENVIRONMENT. ORACLE PROPRIETARY. COMMANDS DO NOT ALLOW MANIPULATION OF VALUES IN DATABASE. RUNS ON BROWSER. CENTALLY LOADED $ DOES NOT HAVE TO BE IMPLEMENTED ON EACH MACHINE. ARIT.E)ITIC E/PRESSIONS:

OPERATOR. J & # / OPERATOR PRECEDENCE: # / J &

DESCRIPTION. ADD. SUBTRACT. MULTIPLY. DIVIDE.

CO)PARISION OPERATORS:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
I E"UAL TO. 4 GRATER THAN. 4 I GRATER THAN OR E"UAL TO. W LESS THAN. W I LESS THAN OR E"UAL TO. W4 NOT E"UAL TO.

) 2

BETWEEN *.. AND*. IN(SET) LI'E IS NULL

BETWEEN TWO VALUES(INCLUSIVE). MATCH ANY OF A LIST OF VALUES. MATCH A CHARACTER PATTERN. IS A NULL VALUE.

LOGICAL CONDITIONS: AND OR NOT RULES OF PRECENDENCE: RETURN TRUE IF BOTH COMPONENT CONDITIONS ARE TRUE. RETURN TRUE IF EITHER COMPONENT CONDITION IS TRUE. RETURNS TRUE IF THE FOLLOWING CONDITION IS FALSE.

ORDER EVALUATED. 1 2 ) , . / 0 2

OPERATOR. ARITHEMITIC OPERATORS. CONCATENATION OPERATOR. COMPARISION OPERATORS. IS[NOT\ NULL$ LI'E[NOT\ IN. [NOT\ BETWEEN. NOT LOGICAL CONDITION. AND LOGICAL CONDITION. OR LOGICAL CONDITION.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SQL FUNCTIONS: S"L FUNCTIONS ARE OF TWO TYPES. SINGLE&ROW&FUNCTIONS. MULTIPLE&ROW&FUNCTIONS.

) )

SINGLE%RO+%FUNCTIONS( CHARACTER. NUMBER. DATE. CONVERSION. GENERAL.

C.RACTER FUNCTIONS: CASE )ANIPULATION FUNCTIONS: LOWER. UPPER. INITCAP.

C.RACTER )ANIPULATION FUNCTIONS: CONCAT. SUBSTR. LEGTH. INSTR. LPAD/RPAD. TRIM. REPLACE. NU)BER FUNCTIONS: ROUND. TRUNC. MOD. DATE FUNCTIONS: MONTHS(BETWEEN.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ADD(MONTHS. NE!T(DAY. LAST(DAY. ROUND. TRUNC. VALID ORACLE DATE BETWEEN JAN 1 $ ,012 BC TO DEC )1 AD

) ,

ARIT.E)ITIC +IT. DATES: DATE J NUMBER DATE 1 NUMBER DATE 1 DATE DATEJ NUMBER/2, DATE. DATE. NO OF DAYS. DATE.(ADD A NUMBER OF HOURS TO DATE).

CON*ERSION FUNCTIONS: DATA TYPE CON*ERSIONS:

IMPLICIT DATA&TYPE CONVERSION. E!PLICIT DATA&TYPE CONVERSION.

I)PLICIT DATA%TYPE CON*ERSIONS:

FOR ASSIGNMENT $ THE ORACLE SERVER CAN AUTOMATICALLY CONVERT THE FOLLOWING. FROM VARCHAR2 OR CHAR VARCHAR2 OR CHAR NUMBER DATE. TO NUMBER. DATE. VARCHAR2. VARCHAR2.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
FROM VARCHAR2 OR CHAR VARCHAR2 OR CHAR E/PLICIT DATA%TYPE CON*ERSIONS: CHARACTER &&&&&&&&& TO(NUMBER &&&&&&&&& NUMBER &&&&&&&&& TO(CHAR &&&&&&&&& CHARACTER. CHARACTER &&&&&&&&& TO(DATE &&&&&&&&& DATE &&&&&&&&& TO(CHAR &&&&&&&&& CHARACTER. TO NUMBER. DATE.

) .

FOR E/PRESSION E*ALUATION" T.E ORACLE SER*ER CAN AUTO)ATICALLY CON*ERT FOLLO+ING(

ELE)ENTS OF T.E DATE FOR)AT )ODEL:

YYYY YEAR MM MONTH MON DY DAY DD GENERAL FUNCTIONS:

FULL YEAR IN NUMBER. YEAR SPELLED OUT. TWO&DIGIT VALUE OF MONTH. FULL NAME OF THE MONTH. THREE&LETTER ABBREVATION OF THE MONTH. THREE&LETTER ABBREVATION OF THE WEE'. FULL NAME OF THE DAY OF THE WEE'. NUMERIC DAY OF THE MONTH.

NVL. NVL2. NULLIF. COALESCE. NVL(COMM$3)5 NVL(HIREDATE$31&JAN& 0)5 NVL(JOB(ID$NO JOB YET)5 GROUP FUNCTIONS: AVG. COUNT.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
MA!. MIN. STDDEV. VARIANCE. SELECT COLUMN *. [COLUMN\$GROUP FUNCTION FROM TABLE [WHERE CONDITION\ [GROUP BY GROUP BY E!PRESSION\ [ HAVING GROUP CONDITION\ [ORDER BY COLUMN\5

) /

TYPES OF SUBQUERIES: SINGLE RO+ SUBQUERIES: "UERIES THAT RETURNS ONLY ONE ROW FROM THE INNER SELECT STATEMENT. )ULTIPLE RO+ SUBQUERIES: "UERIES THAT RETURN MORE THAN ONE&ROW FROM THE INNER SELECT STATEMENTS. DATA BASE OBJECTS: TABLES. VIEWS. SE"UENCES. INDE!ES. SYNONYM.

TABLE NA)ES AND COLU)N NA)ES: MUST BEGIN WITH A LETTER. MUST BE 1 TO )3 CHARACTER LONG. MUST CONTAIN ONLY A&Z$ 6&h$3& $&$` 6K= i. MUST NOT DUPLICATE THE NAME OF ANOTHER OBJECT OWNED BY SAME USER. MUST NOT BE AN ORACLE SERVER RESERVED WORD. AUTO)ATIC CO))IT: WHEN EVER DDL$DCL STATEMENTS ISSUED. WHEN EVER IS"L#PLUS$S"L#PLUS E!ITED NORMALLY$ WITHOUT E!PLICITLY ISSUSING COMMIT OR ROLLBAC'.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
AUTO)ATIC ROLLBAC-: ABNORMAL TERIMINATION OF IS"L#PLUS OR SYSTEM FAILURE. TABLES IN T.E ORACLE DATABASE: USER TABLES: ARE COLLECTION OF TABLES CREATED AND MAINTAINED BY THE USER. CONTAINS USER INFORMATION. DATA DICTIONARY: IS COLLECTION OF TABLES CREATED AND MAINTAINED BY THE ORACLE SERVER. CONTAIN DATABASE INFORMATION. USER TABLES ARE TABLES CREATED BY THE USER$ SUCH AS EMP. THERE ARE

) 0

ANOTHER COLLECTION OF TABLES AND VIEWS IN THE ORACLE DATABASE 'NOWN AS THE DATA DICTIONARY. THIS COLLECTION IS CREATED AND MAINTAINED BY THE ORACLE SERVER AND CONTAINS INFORMATION ABOUT THE DATABASE. ALL DATA DICTIONARY TABLES ARE OWNED BY THE SYS USER. THE BASE TABLES ARE RARELY ACCESSED BY THE USER BECAUSE THE INFORMATION IN THEM IS NOT EASY TO UNDERSTAND. INFORMATION STORED IN THE DATA DICTIONARY INCLUDES NAMES OF THE ORACLE SERVER USERS$ PRIVILEGES GRANTED TO USERS$ DATABASE OBJECT NAMES$ TABLES CONSTRAINTS AND AUDITING INFORMATION. THERE ARE FOUR CATEGORIES OF DATA DICTIONARY VIEWS5 EACH CATEGORY HAS A DISTINCT PREFI! THAT REFLECTS ITS INTENDED USE. PREFI! USER( ALL( DESCRIPTION THESE VIEWS CONTAIN OWNED BY THE USER. INFORMATION ABOUT OBJECTS

THESE VIEWS CONTAINS INFORMATION ABOUT ALL OF THE TABLES(OBJECT TABLES AND RELATIONAL TABLES) ACCESSIBLE TO THE USER. THESE VIEWS ARE RESTRICTED VIEWS$ WHICH CAN BE ACCESSED ONLY BY PEOPLE WHO HAVE BEEN ASSIGNED THE DBA ROLE. THESE VIEWS ARE DYNAMIC PERFORMANCE VIEWS$ DATABASE SERVER PERFORMANCE$ MEMORY $ AND LOC'ING.

DBA( V`

QUERYING T.E DATA DICTIONARY: SEE T.E NA)ES OF TABLES O+NED BY T.E USER( SELECT # FROM USER(TABLES5 *IE+ DISTINCT OBJECT2TYPES O+NED BY T.E USER( SELECT DISTINCT OBJECT(TYPE FROM USER(OBJECTS. *IE+ TABLES" *IE+S"SYNONY)S AND SEQUENCES O+NED BY T.E USER( SELECT # FROM CATALOG5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
USER(CATALOG HAS A SYNONYM CALLED CAT. YOU CAN USE THIS SYNONYM INSTEAD OF USER(CATALOG IN S"L STATEMENT. SELECT # FROM CAT5

) 2

DATATYPES:

DATA TYPE VARCHAR2(SIZE) CHAR NUMBER(P$S)

DESCRIPTION VARIABLE&LENGTH CHARACTER DATA( A MA!IMUM SIZE MUST BE SPECIFIED% MINIMUM SIZE IS 1%MA!IMUM SIZE IS ,333). FI!ED 1LENGTH CHARACTER DATA OF LENGTH SIZE BYTES (DEFAULT AND MINIMUM SIZE IS 15 MA!IMUM SIZE IS 2333). NUMBER HAVING PRECISION P AND SCALE S(PRECISION IS THE TOTAL NUMBER OF DECIMAL DIGITS$ AND THE SCALE IS THE NUMBER OF DIGITS TO THE RIGHT OF THE DECIMAL POINT5 THE PRECISION CAN RANGE FROM 1 TO )2 AND SCALE CAN RANGE FROM &2, TO 120).

DATE LONG CLOB RAW(SIZE) LONG RAW BLOB BFILE ROWID

DATE AND TIME VALUES TO THE NEAREST SECOND BETWEEN JANUARY 1$ ,012 B.C.$ AND A.D. DECEMBER )1$ . VARIABLE LENGTH CHARACTER DATA UP TO 2 GB. CHRACTER DATA UP TO , GIGABYTES. RAW BINARY DATA OF LENGTH SIZE( A MA!IMUM SIZE MUST BE SPECIFIED. MA!IMUM SIZE IS 2333). RAW BINARY DATA OF VARIABLE LENGTH UP TO 2 GB. BINARY DATA UP TO , GB. BINARY DATA STORED IN AN E!TERNAL FILE%UP TO , GB. HE!ADECIMAL STRING REPRESENTING THE UNI"UE ADDRESS OF A ROW IN ITS TABLE. THIS DATA TYPE IS PRIMARILY FOR VALUES RETURNED BY THE ROWID PSEUDOCOLUMN.

A LONG COLUMN IS NOT COPIED WHEN A TABLE IS CREATED USING ASUB"UERY. A LONG COLUMN CANNOT BE INCLUDED IN A GROUP BY OR ORDER BY CLAUSE. ONLY ONE LONG COLUMN CAN BE USED PER TABLE. NO CONSTRAINT CAN BE DEFINED ON A LONG COLUMN. YOU MAY WANT TO USE A CLOB COLUMN RATHER THAN A LONG COLUMN. DATETI)E DATA TYPES: DATETIME ENHANCEMENTS WITH ORACLE I% TIMESTAMP. DATE WITH FRACTIONAL SECONDS.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
THIS IS E!TENSION OF THE DATE DATA TYPE. IT STORES THE YEAR$ MONTH$AND DAY OF THE DATE DATA TYPE PLUS HOUR$ MINUTE$ AND SECOND VALUES AS WELL AS THE FRACTIONAL SECOND VALUE. THE TIME STAMP DATA TYPE IS SPECIFIED AS FOLLOWS. TIMESTAMP[(FRACTIONAL(SECONDS(PRECISION)\ FRACTIONAL(SECONDS(PRECISION OPTIONALLY SPECIFIES THE NUMBER OF DIGITS IN THE FRACTIONAL PART OF THE SECOND DATETIME FIELD AND CAN BE A NUMBER IN THE RANGE 3 TO . THE DEFAULT IS /. CASCADE: S"L4 CREATE TABLE EMP(D 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 CREATE TABLE DEPT(D 2 AS ) SELECT # FROM DEPT5 T6789 :;96<9=. S"L4 ALTER TABLE DEPT(D 2 ADD CONSTRAINT DEPT(D(P' PRIMARY 'EY(DEPTNO)5 T6789 68<9;9=. S"L4 ALTER TABLE EMP(D 2 ADD CONSTRAINT EMP(D(F' FOREIGN 'EY(DEPTNO) REFERENCES DEPT(D(DEPTNO)5 T6789 68<9;9=.

1 ALTER TABLE DEPT(D 2# DISABLE CONSTRAINT DEPT(D(P' S"L4 / ALTER TABLE DEPT(D # ERROR 6< 8NK9 1% ORA&322 0% :6KKD< =NF6789 :DKF<;6NK< (SCOTT.DEPT(D(P') & =9B9K=9K:N9F 9UNF< S"L4 ALTER TABLE DEPT(D 2 DROP CONSTRAINT DEPT(D(P'5 DROP CONSTRAINT DEPT(D(P' # ERROR 6< 8NK9 2% ORA&3220)% <RNF ?KNP?9/B;N>6;A L9A NF ;9T9;9K:9= 7A FD>9 TD;9NSK L9AF S"L4 ALTER TABLE DEPT(D 2 DISABLE CONSTRAINT DEPT(D(P' CASCADE5 T6789 68<9;9=.

S"L4 ALTER TABLE DEPT(D

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 ENABLE CONSTRAINT DEPT(D(P'5 T6789 68<9;9=. S"L4 ALTER TABLE DEPT(D 2 DISABLE CONSTRAINT DEPT(D(P'5 T6789 68<9;9=. S"L4 ALTER TABLE DEPT(D 2 ENABLE CONSTRAINT DEPT(D(P'5 T6789 68<9;9=. 1 ALTER TABLE DEPT(D 2# ENABLE CONSTRAINT DEPT(D(P' CASCADE5 S"L4 / ENABLE CONSTRAINT DEPT(D(P' CASCADE5 # ERROR 6< 8NK9 2% ORA&33 ))% S"L :D>>6K= KD< B;DB9;8A 9K=9= ENABLING A PRIMARY 'EY CONSTRAINT THAT WAS DISABLED WITH CASCADE OPTION DOES NOT ENABLE ANY FOREIGN 'EYS THAT ARE DEPENDENT UPON THE PRIMARY 'EY. CASCADING CONSTRAINTS:

,33

THE CASCADE CONSTRAINTS CLAUSE IS USED ALONG WITH THE DROP COLUMN CLAUSE. THE CASCADE CONSTRAINTS CLAUSE DROPS ALL REFERENTIAL INTEGRITY CONSTRAINTS THAT REFERTO THE PRIMARY AND UNI"UE 'EYS DEFINED ON THE DROPPED COLUMNS. THE CASCADE CONSTRAINTS CLAUSE ALSO DROPS ALL MULTICOLUMN CONSTRAINTS DEFINED ON THE DROPPED COLUMNS. S"L4 CREATE TABLE TEST1 2 (P' NUMBER(13) CONSTRAINT TEST1(P' PRIMARY 'EY$ ) F' NUMBER(13)$ , COL1 NUMBER(13)$ . COL2 NUMBER(13)$ / CONSTRAINT TEST1(F' FOREIGN 'EY(F') REFERENCES TEST1(P')$ 0 CONSTRAINT TEST1(C'1 CHEC'(P' 4 3 AND COL1 4 3)$ 2 CONSTRAINT TEST1(C'2 CHEC'(COL2 4 3))5 T6789 :;96<9=. S"L4 ALTER TABLE TEST1 2 DROP COLUMN P'5 DROP COLUMN P' # ERROR 6< 8NK9 2% ORA&12 2% :6KKD< =;DB B6;9K< L9A :D8?>K S"L4 ALTER TABLE TEST1 2 DROP COLUMN COL15 DROP COLUMN COL1 # ERROR 6< 8NK9 2% ORA&12 1% :D8?>K NF ;9T9;9K:9= NK 6 >?8<N&:D8?>K :DKF<;6NK<

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 ALTER TABLE TEST1 2 DROP (P')5 DROP (P') # ERROR 6< 8NK9 2% ORA&12 2% :6KKD< =;DB B6;9K< L9A :D8?>K S"L4 ALTER TABLE TEST1 2 DROP (COL1)5 DROP (COL1) # ERROR 6< 8NK9 2% ORA&12 1% :D8?>K NF ;9T9;9K:9= NK 6 >?8<N&:D8?>K :DKF<;6NK< S"L4 ALTER TABLE TEST1 2 DROP (P') CASCADE CONSTRAINTS5 T6789 68<9;9=. THE ABOVE STATEMENT DROPS COLUMN P'$ THE PRIMARY 'EY CONSTRAINT$THE FOREIGN 'EYCONSTRAINT AND CHEC' CONSTRAINT. S"L4 DESC TEST15 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& F' NUMBER(13) COL1 NUMBER(13) COL2 NUMBER(13)

,31

1 CREATE TABLE TEST2 2 (P' NUMBER(13) CONSTRAINT TEST2(P' PRIMARY 'EY$ ) F' NUMBER(13)$ , COL1 NUMBER(13)$ . COL2 NUMBER(13)$ / CONSTRAINT TEST2(F' FOREIGN 'EY(F') REFERENCES TEST2(P')$ 0 CONSTRAINT TEST2(C'1 CHEC'(P' 4 3 AND COL1 4 3)$ 2# CONSTRAINT TEST2(C'2 CHEC'(COL2 4 3)) / T6789 :;96<9=.

S"L4 ALTER TABLE TEST2 2 DROP (P'$F'$COL1)5 T6789 68<9;9=. S"L4 DESC TEST2 N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& COL2 NUMBER(13) IN THE ABOVE STATEMENT WE ARE DROPING ALL THE COLUMNS THAT ARE REFERENCED BY CONSTRAINTS$HERE THERE IS NO USE OF THE CASCADE

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
CONSTRAINTS. USER2CONSTRAINTS: 1 CREATE TABLE EMP(DU 2 (EMPNO NUMBER(13) CONSTRAINT PAVAN(P' PRIMARY 'EY$ ) ENAME VARCHAR2(13) CONSTRAINT PAVAN(U' UNI"UE$ , JOB . SAL VARCHAR2(13) CONSTRAINT PAVAN(NN NOT NULL$ NUMBER(13) CONSTRAINT PAVAN(C' CHEC'(SAL 4 1333)$

,32

/# DEPTNO NUMBER(13) CONSTRAINT PAVAN(F' REFERENCES DEPT(DEPTNO)) S"L4 / T6789 :;96<9=.

1 SELECT CONSTRAINT(NAME$CONSTRAINT(TYPE$SEARCH(CONDITION 2 FROM USER(CONSTRAINTS )# WHERE TABLE(NAMEICEMP(DUC S"L4 / CONSTRAINT(NAME C &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& & SEARCH(CONDITION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& PAVAN(NN C OJOBO IS NOT NULL PAVAN(C' SAL 4 1333 PAVAN(P' PAVAN(U' PAVAN(F' C P U R

INTEGRITY CONSTRAINTS: MAINTAINING SECURITY AND INTEGRITY OF A DATABASE IS THE MOST IMPORTANT FACTOR IN JUDGING THE SUCCESS OF A SYSTEM. INTEGRITY CONSTRAINT IS A MECHANISM USED BY ORACLE TO PREVENT INVALID DATA ENTRY INTO THE TABLE. INTEGRITY CONSTRAINTS ARE DEVIDED IN TO THREE CATEGORIES% 1.DOMAIN INTEGRITY CONSTRAINTS. 2.ENTITY INTEGRITY CONSTRAINTS. ).REFERENTIAL INTEGRITY CONSTRAINTS.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE

,3)

DO)AIN INTEGRITY CONSTRAINTS( NOT NULL CHEC' BOTH FALL UNDER THIS CATEGORY.

ENTITY INTEGRITY CONSTRAINTS( ENTITY INTEGRITY CONSTRAINTS ARE OF TWO TYPES% UNI"UE CONSTRAINT. PRIMARY 'EY CONSTRAINT. REFERENTIAL INTEGRITY CONSTRAINTS( REFERENTIAL INTEGRITY CONSTRAINT ENFORCES RELATIONSHIP BETWEEN TABLES. IT DESIGNATES A COLUMN OR COMBINATION OF COLUMNS AS A FOREIGN 'EY. THE FOREIGN 'EY ESTABLISHES A RELATIONSHIP WITH A SPECIFIED PRIMARY 'EY OR UNI"UE 'EY IN ANOTHER TABLE$ CALLED THE REFERENCED 'EY. IN THIS RELATION SHIP $ THE TABLE CONTAINING THE FOREIGN 'EY IS CALLED THE CHILD TABLE AND THE TABLE CONTAINING THE REFERENCED 'EY IS CALLED THE PARENT TABLE.

TRIGGERS:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
D)L TRIGGERS: CREATE [OR REPLACE \ TRIGGER TRIGGER(NAME ] BEFORE V AFTERV ] INSERTVDELETEVUPDATEVUPDATE OF COLUMN LIST^ ON TABLE NAME [FOR EACH ROW\ [WHEN (*..)\ [DECLARE*..\ BEGIN **E!ECUTABLE STATEMENETS [E!CEPTION*..\ END[TRIGGER(NAME\5 S"L4 CREATE TABLE DML(E! 2 (ACTION VARCHAR2(13)$ ) TDATE TIMESTAMP)5 T6789 :;96<9=. 1 CREATE OR REPLACE TRIGGER BFORE(INSERT 2 BEFORE INSERT ON EMP ) BEGIN , INSERT INTO DML(E! . VALUES / (CBFOREINSERTC$SYSTIMESTAMP)5 0# END5 2 / T;NSS9; :;96<9=.

,3,

1 CREATE OR REPLACE TRIGGER BFORE(INSERT(ROW 2 BEFORE INSERT ON EMP FOR EACH ROW ) BEGIN , INSERT INTO DML(E! . VALUES / (CBFOREINSERTROWC$SYSTIMESTAMP)5 0# END5 2 / T;NSS9; :;96<9=.

1 CREATE OR REPLACE TRIGGER AFTER(INSERT 2 AFTER INSERT ON EMP ) BEGIN

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
, INSERT INTO DML(E! . VALUES / (CAFTERINSERTC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER AFTER(INSERT(ROW 2 AFTER INSERT ON EMP FOR EACH ROW ) BEGIN , INSERT INTO DML(E! . VALUES / (CAFTERINSERTROWC$SYSTIMESTAMP)5 0# END5 2 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER BEFORE(UPDATE 2 BEFORE UPDATE ON EMP ) BEGIN , INSERT INTO DML(E! . VALUES / (CBEFOREUPDATEC$SYSTIMESTAMP)5 0# END5 2 / T;NSS9; :;96<9=.

,3.

1 CREATE OR REPLACE TRIGGER BEFORE(UPDATE(ROW 2 BEFORE UPDATE ON EMP FOR EACH ROW ) BEGIN , INSERT INTO DML(E! . VALUES / (CBEFOREUPDATEROWC$SYSTIMESTAMP)5 0# END5 2 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER AFTER(UPDATE 2 AFTER UPDATE ON EMP ) BEGIN , INSERT INTO DML(E! . VALUES / (CAFTERUPDATEC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER AFTER(UPDATE(ROW 2 AFTER UPDATE ON EMP FOR EACH ROW ) BEGIN , INSERT INTO DML(E! . VALUES / (CAFTERUPDATEROWC$SYSTIMESTAMP)5 0# END5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER BEFORE(DELETE 2 BEFORE DELETE ON EMP ) BEGIN , INSERT INTO DML(E! . VALUES / (CBEFOREDELETEC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER BEFORE(DELETE(ROW 2 BEFORE DELETE ON EMP FOR EACH ROW ) BEGIN , INSERT INTO DML(E! . VALUES / (CBEFOREDELETEROWC$SYSTIMESTAMP)5 0# END5 2 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER AFTER(DELETE 2 AFTER DELETE ON EMP ) BEGIN , INSERT INTO DML(E! . VALUES / (CAFTERDELETEC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER AFTER(DELETE(ROW 2 AFTER DELETE ON EMP FOR EACH ROW ) BEGIN , INSERT INTO DML(E! . VALUES / (CAFTERDELETEROWC$SYSTIMESTAMP)5 0# END5 2 / T;NSS9; :;96<9=. S"L4 SELECT # FROM DML(E!5 KD ;DEF F989:<9= S"L4 INSERT INTO EMP 2 (EMPNO$DEPTNO) ) VALUES , (1$13)5 INSERT INTO EMP # ERROR 6< 8NK9 1% ORA&31,31% NKF9;<9= Q68?9 <DD 86;S9 TD; :D8?>K ORA&3/.12% 6< OSCOTT.BFORE(INSERTO$ 8NK9 2 ORA&3,322% 9;;D; =?;NKS 9U9:?<NDK DT <;NSS9; CSCOTT.BFORE(INSERTC S"L4 ALTER TABLE DML(E! 2 MODIFY ACTION VARCHAR2(.3)5

,3/

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
T6789 68<9;9=. S"L4 INSERT INTO EMP 2 (EMPNO$DEPTNO) ) VALUES , (1$13)5 1 ;DE :;96<9=.

,30

S"L4 SELECT # FROM DML(E!5 ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BFOREINSERT 32&SEP&3. 3/.. .31.333333 AM BFOREINSERTROW 32&SEP&3. 3/.. .31.333333 AM AFTERINSERTROW 32&SEP&3. 3/.. .31.333333 AM AFTERINSERT 32&SEP&3. 3/.. .31.333333 AM S"L4 DELETE FROM DML(E!5 , ;DEF =989<9=. S"L4 DELETE FROM EMP WHERE EMPNOI15 1 ;DE =989<9=. S"L4 SELECT # FROM DML(E!5 ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BEFOREDELETE 32&SEP&3. 30.33.11.333331 AM BEFOREDELETEROW 32&SEP&3. 30.33.11.333331 AM AFTERDELETEROW 32&SEP&3. 30.33.11.333331 AM AFTERDELETE 32&SEP&3. 30.33.11.333331 AM S"L4 DELETE FROM DML(E!5 , ;DEF =989<9=. S"L4 UPDATE EMP 2 SET SAL I SALJ3 ) WHERE EMPNOI00225 1 ;DE ?B=6<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM DML(E!5 ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BEFOREUPDATE 32&SEP&3. 30.31.)/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.31.)/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.31.)/.333331 AM AFTERUPDATE 32&SEP&3. 30.31.)/.333331 AM S"L4 DELETE FROM DML(E!5 , ;DEF =989<9=. S"L4 SELECT # FROM DML(E!5 KD ;DEF F989:<9= S"L4 UPDATE EMP 2 SET SAL I SALJ35 1, ;DEF ?B=6<9=. S"L4 SELECT # FROM DML(E!5 ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& BEFOREUPDATE 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM

,32

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW ACTION &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& TDATE &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM BEFOREUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATEROW 32&SEP&3. 30.32.2/.333331 AM AFTERUPDATE

,3

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
32&SEP&3. 30.32.2/.333331 AM )3 ;DEF F989:<9=. 1# SELECT COUNT(#) FROM EMP S"L4 / COUNT(#) &&&&&&&&&& 1,

,13

DDL TRIGGERS: CREATE [OR REPLACE \ TRIGGER TRIGGER(NAME ]BEFORE VAFTERV]DDL EVENT^ ON ]DATABASEVSCHEMA^ DECLARE VARIABLE DECLARATIONS. BEGIN *.SOME CODE*. END5 WHERE DDL(EVENT% CREATE ALTER DROP COMMENT. GRANT. REVO'E. RENAME. TRUNCATE.

S"L4 CREATE TABLE CREATE(DDL(CREA 2 (ACTION VARCHAR2(23)$

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
) TDATE TIMESTAMP)5 T6789 :;96<9=.

,11

1 CREATE OR REPLACE TRIGGER CREATE(DDL(BFORE 2 BEFORE CREATE ON SCHEMA ) BEGIN , INSERT INTO CREATE(DDL(CREA . VALUES / (CCREATINGC$SYSTIMESTAMP)5 0# END5 2 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER CREATE(DDL(AFTER 2 AFTER CREATE ON SCHEMA ) BEGIN , INSERT INTO CREATE(DDL(CREA . VALUES / (CCREATEDC$SYSTIMESTAMP)5 0# END5 2 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER CREATE(DDL(BFORE 2 BEFORE CREATE ON DATABASE ) BEGIN , INSERT INTO CREATE(DDL(CREA . VALUES / (CCREATING DATABASEC$SYSTIMESTAMP)5 0# END5 2 / BEFORE CREATE ON DATABASE # ERROR 6< 8NK9 2% ORA&313)1% NKF?TTN:N9K< B;NQN89S9F S"L4 CONN EK<9; ?F9;&K6>9% SYS AS SYSDBA CDKK9:<9=. S"L4 GRANT DBA TO SCOTT5 G;6K< F?::99=9=. S"L4 CONN EK<9; ?F9;&K6>9% SCOTT CDKK9:<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 CREATE OR REPLACE TRIGGER CREATE(DDL(BFORE 2 BEFORE CREATE ON DATABASE ) BEGIN , INSERT INTO CREATE(DDL(CREA . VALUES / (CCREATING DATABASEC$SYSTIMESTAMP)5 0 END5 2 / CREATE OR REPLACE TRIGGER CREATE(DDL(BFORE # ERROR 6< 8NK9 1% ORA&3,3 .% <;NSS9; CCREATE(DDL(BFOREC 68;96=A 9UNF<F DK 6KD<R9; <6789$ :6KKD< ;9B86:9 N< 1 CREATE OR REPLACE TRIGGER CREATE(DDL(BFORE(DATA 2 BEFORE CREATE ON DATABASE ) BEGIN , INSERT INTO CREATE(DDL(CREA . VALUES / (CCREATING DATABASEC$SYSTIMESTAMP)5 0# END5 2 / T;NSS9; :;96<9=. 1 CREATE OR REPLACE TRIGGER CREATE(DDL(ATER(DATA 2 AFTER CREATE ON DATABASE ) BEGIN , INSERT INTO CREATE(DDL(CREA . VALUES / (CCREATED DATABASEC$SYSTIMESTAMP)5 0# END5 S"L4 / T;NSS9; :;96<9=. S"L4 CREATE TABLE B 2 (EMPNO NUMBER(13))5 T6789 :;96<9=.

,12

S"L4 SELECT # FROM CREATE(DDL(CREA5 ACTION TDATE &&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CREATING 32&SEP&3. 30.10..0.333333 AM CREATING DATABASE 32&SEP&3. 30.10..0.333333 AM CREATED 32&SEP&3. 30.10..0.333333 AM CREATED DATABASE 32&SEP&3. 30.10..0.333333 AM

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
DATABASE E*ENT TRIGGERS: DATABASE EVENT TRIGGERS FIRE WHENEVER DATABASE&WIDE EVENTS OCCUR. THERE ARE FIVE DATABASE EVENT TRIGGERS% STARTUP. FIRES WHEN THE DATABASE IS OPENED. SHUTDOWN FIRES WHEN THE DATABASE IS SHUTDOWN NORMALLY. SERVERERROR FIRES WHEN AN ORACLE ERROR IS RAISED. LOGON FIRES WHEN AN ORACLE SESSION BEGINS. LOGOFF FIRES WHEN ANORACLE SESSION TERMINATES NORMALLY. CREATE [OR REPLACE\ TRIGGER TRIGGER(NAME ]BEFOREVAFTER]DATABASE EVENT^ ON ]DATABASEVSCHEMA^ DECLARE VARIABLE DECLARATIONS. BEGIN *SOME CODE* END.

,1)

NO BEFORE STARTUP TRIGGERS. NOAFTER SHUTDOWN TRIGGERS. NOBEFORE LOGON TRIGGERS. NOAFTERLOGOFF TRIGGERS. NOBEFORESERVERERROR. TABLE % BASIC UNIT OF STORAGE. COMPOSED OF ROWS AND COLUMNS. VIEW % LOGICALLY REPRESENTS SUBSETS OF DATA FROM ONE OR MORE TABLES. SE"UENCE%GENERATES PRIMARY 'EY VALUES. INDE!% IMPROVES THE PERFORMANCE OF SOME "UERIES. SYNONYM % ALTERNATIVE NAME FOR AN OBJECT. INLINE*IE+:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
IT IS NOT A SCHEMA OBJECT LI'E NORMAL VIEW.

,1,

INLINE VIEW IS BASICALLY A SUB"UERY WITH AN ALIAS(CORRELATION NAME) THAT YOU CAN USE LI'E A VIEW INSIDE A S"L STATEMENT.

"UERY DISPLAYS EMPLOYEE NAMES$SALARIES$DEPARTMENT NUMBERS AND MA!IMUM SALARIES FOR ALL THE EMPLOYEES WHO EARN LESS THAN THE MA! SAL IN THEIR DEPARTMENT. S"L4 SELECT A.ENAME$A.SAL$A.DEPTNO$B.MA!SAL 2 FROM EMP A$(SELECT DEPTNO$MA!(SAL) MA!SAL FROM EMP GROUP BY DEPTNO) B ) WHERE A.DEPTNOIB.DEPTNO , AND A.SAL W B.MA!SAL ORDER BY ENAME5 ENAME SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& ADAMS 1133 23 ALLEN 1/33 )3 CLAR' 2,.3 13 JAMES .3 )3 JONES 2 0. 23 MARTIN 12.3 )3 MILLER 1)33 13 SMITH 233 23 TURNER 1.33 )3 WARD 12.3 )3 13 ;DEF F989:<9=. S"L4 SELECT ENAME$SAL$DEPTNO$MA!SAL 2 FROM EMP A ) WHERE SAL W (SELECT MA!(SAL) , S"L4 ED W;D<9 TN89 6TN9=<.7?T 1 SELECT ENAME$SAL$DEPTNO 2 FROM EMP A ) WHERE SAL W (SELECT MA!(SAL) FROM EMP B ,# WHERE A.DEPTNOIB.DEPTNO) . ORDER BY ENAME5 ENAME SAL &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& ADAMS 1133 ALLEN 1/33 CLAR' 2,.3 JAMES .3 JONES 2 0. MARTIN 12.3 MILLER 1)33 SMITH 233 TURNER 1.33 WARD 12.3 13 ;DEF F989:<9=. TOP%N ANALYSIS: DEPTNO 23 )3 13 )3 23 )3 13 23 )3 )3 DEPTNO )333 22.3 .333 22.3 )333 22.3 .333 )333 22.3 22.3 MA!SAL

TOP&N "UERIES AS' FOR THE N LARGEST OR SMALLEST VALUES OF A COLUMN. FOR E!AMPLE% WHAT ARE THE TEN BEST SELLING PRODUCTS. WHAT ARE THE TEN WORST SELLING PRODUCTS.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
BOTH LARGEST VALUES AND SMALLEST VALUES SETS ARE CONSIDERED TOP&N "UERIES.

,1.

PERFOR)ING TOP%N ANALYSIS:

THE HIGH&LEVEL STRUCTURE OF A TOP&N ANALYSIS "UERY IS% SELECT [COLUMN(LIST\$ROWNUM FROM (SELECT [COLUMN(LIST\ FROM TABLE ORDER BY TOP&N(COLUMN) WHERE ROWNUM W I N5

A SUB"ERY OR AN INLINE VIEW TO GENERATE THE SORTED LIST OF DATA. THE SUB"ERY OR THE INLINE VIEW INCLUDES THE ORDER BY CLAUSE TO ENSURE THAT THE RAN'ING IS IN THE DESIRED ORDER. FOR RESULTS RETRIVING THE LARGEST VALUES$A DESC PARAMETER IS NEEDED. AN OUTER "UERY TO LIMIT THE NUMBER OF ROWS IN THE FINAL RESULT SET. THE OUTER "UERY INCLUDES THE FOLLOWING COMPONENTS% THE ROWNUM PSEDOCOLUMN$ WHICH ASSIGNS A SE"UENTIAL VALUE STARTING WITH 1 TO EACH OF THE ROWS RETURNED FROM THE SUB"UERY. A WHERE CLAUSE$ WHICH SPECIFIES THE N ROWS TO BE RETURNED. THE OUTER WHERE CLAUSE MUST USE A W OR W I OPERATOR. SELECT ROWNUM AS RAN'$ ENAME$SAL FROM (SELECT ENAME$SAL FROM EMP ORDER BY SAL DESC) WHERE ROWNUM W I ).

USING A SEQUENCE:

CACHING SE"UENCE VALUES IN MEMORY GIVES FASTER ACCESS TO THOSE VALUES. GAPS IN SE"UENCE VALUES CAN OCCUR WHEN% A ROLLBAC' OCCURS. THE SYSTEM CRASHES. A SE"UENCE IS USED IN ANOTHER TABLE. IF THE SE"UENCE WAS CREATED WITH NOCACHE$ VIEW THE NE!T AVAILABLE VALUE$ BY "UERYING THE USER(SE"UENCES TABLE. DATABASE LIN-S:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
A DATABASE LIN' CONNECTION ALLOWS LOCAL USERS TO ACCESS DATA ON A REMOTE DATABASE. THE LIN' POINTER IS ACTUALLY DEFINED AS AN ENTRY IN A DATA DICTIONARY TABLE. TO ACCESS THE LIN'$YOU MUST BE CONNECTED TO THE LOCAL DATABASE THAT CONTAINS THE DATA DICTIONARY ENTRY.

,1/

A DATABASE LIN' IS A POINTER THAT DEFINES A ONE&WAY COMMUNICATION PATH FROM AN ORACLE DATABASE SERVER TO ANOTHER DATABASE SERVER.

A DATABASE LIN' CONNECTION IS ONE&WAY IN THE SENSE THAT A CLIENT CONNECTED TO LOCAL DATABASE GA CAN USE A LIN' STORED IN DATABASE GA TO ACCESS INFORMATION IN REMOTE DATABASE GB$ BUT USERS CONNECTED TO DATABASE B CANNOT USE THE SAME LIN' TO ACCESS DATA IN DATABASE A. IF LOCAL USERS ON DATABASE B WANT TO ACCESS DATA ON DATABSE A $ THEY MUST DEFINE A LIN' THAT IS STORED IN THE DATA DICTIONARY OF DATABASE B. A DATABASE LIN' CONNECTION GIVES LOCAL USERS ACCESS TO DATA ON REMOTE DATABASE. FOR THIS CONNECTION TO OCCUR$ EACH DATABASE IN THE DISTRIBUTED SYSTEM MUST HAVE A UNI"UE GLOBAL DATABASE NAME. THE GLOBAL DATABASE NAME UNI"UELY IDENTIFIES A DATABASE SERVER IN A DISTRIBUTED SYSTEM. THE GREAT ADVANTAGE OF DATABASE LIN'S IS THAT THEY ALLOW USERS TO ACCESS ANOTHER USERS OBJECTS IN A REMOTE DATABASE SO THAT THEY ARE BOUNDED BY THE PRIVILEGE SET OF THE OBJECTS OWNER. IN OTHER WORDS $ A LOCAL USER CAN ACCESS A REMOTE DATABASE WITHOUT HAVING TO BE A USER ON THE REMOTE DATABASE. NOTE% TYPICALLY$ THE DBA IS RESPONSIBLE FOR CREATING THE DATABASE LIN'. THE DICTIONARY VIEW USER(DB(LIN'S CONTAINS INFORMATION ON LIN'S TO WHICH A USER HAS ACCESS. THE E!AMPLE SHOWS A USER SCOTT ACCESSING THE EMP TABLE ON THE REMOTE DATABASE WITH THE GLOBAL NAME H".ACME.COM.

CREATE T.E DATABASE LIN-: CREATE PUBLIC DATABASE LIN' H".ACME.COM USING GSALES5 DATABASE LIN' CREATED. +RITE SQL STATE)ENTS T.AT USE T.E DATABASE LIN-: SELECT # FROM FRED.EMPYH".ACME.COM. THE USING CLAUSE IDENTIFIES THE SERVICE NAME OF A REMOTE DATABASE. ONCE THE DATABASE LIN' IS CREATED$ YOU CAN WRITE S"L STATEMENTS AGAINST THE DATA IN THE REMOTE SITE. IF A SYNONYM IS SET UP$ YOU CAN WRITE S"L STATEMENTS USING THE SYNONYM. CREATE PUBLIC SYNONYM H"(EMP FOR EMPYH".ACME.COM5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SELECT # FROM H"(EMP5 YOU CANNOT GRANT PRIVILEGES ON REMOTE OBJECTS. CORRELATED SUBQUERIES: CORRELATED SUB"UERIES ARE USED FOR ROW&BY&ROW PROCESSING. EACH SUB"UERY IS E!ECUTED ONCE FOR EVERY ROW OF THE OUTER "UERY. CORRELATED SUBQUERIES E/ECUTION:

,10

1. 2. ). ,.

GET A CANDIDATE ROW(FETCHED BY THE OUTER "UERY). E!ECUTE THE INNER "UERY USING THE VALUE OF THE CANDIDATE ROW. USER THE VALUES RESULTING FROM THE INNER "UERY TO "UALIFY OR DIS"UALIFY THE CANDIDATE. REPEAT UNTIL NO CANDIDATE ROW REMAINS.

NESTED SUBQUERY E/ECUTION:

THE INNER "UERY E!ECUTES FIRST AND FINDS A VALUE. THE OUTER "UERY E!ECUTES ONCE$USING THE VALUE FROM THE INNER "UERY. THE ORACLE SERVER PERFORMS A CORRELATED SUB"UERY WHEN THE SUB"UERY REFERENCES A COLUMN FROM A TABLE REFERRED TO IN THE PARENT STATEMENT. A CORRELATED SUB"UERY IS EVALUATED ONCE FOR EACH ROW PROCESSED BY THE PARENT STATEMENT. THE PARENT STATEMENT CAN BE A SELECT$UPDATE OR DELETE STATEMENT. FIND ALL EMPLOYEES WHO EARN MORE THAN THE AVERAGE SALARY IN THEIR IN THEIR DEPARTMENETS. SELECT ENAME$SAL$DEPTNO FROM EMP A WHERE SAL W (SELECT AVG(SAL) FROM EMP B WHERE B.DEPTNOIA.DEPTNO)5

CORRELATED UPDATE:

S"L4 CREATE TABLE EMP(D 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 DESC EMP(D N6>9 N?88@ TAB9 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& EMPNO NUMBER(,)

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ENAME JOB MGR HIREDATE SAL COMM DEPTNO S"L4 ALTER TABLE EMP(D 2 ADD DNAME VARCHAR2(11)5 T6789 68<9;9=. S"L4 UPDATE EMP(D E 2 SET DNAMEI(SELECT DNAME FROM DEPT D ) WHERE E.DEPTNOID.DEPTNO)5 1, ;DEF ?B=6<9=. S"L4 SELECT EMPNO$ENAME$DEPTNO$DNAME FROM EMP(D5 EMPNO ENAME DEPTNO DNAME &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&&& 0)/ SMITH 23 RESEARCH 0, ALLEN )3 SALES 0.21 WARD )3 SALES 0.// JONES 23 RESEARCH 0/., MARTIN )3 SALES 0/ 2 BLA'E )3 SALES 0022 CLAR' 13 ACCOUNTING 0022 SCOTT 23 RESEARCH 02) 'ING 13 ACCOUNTING 02,, TURNER )3 SALES 020/ ADAMS 23 RESEARCH 0 33 JAMES )3 SALES 0 32 FORD 23 RESEARCH 0 ), MILLER 13 ACCOUNTING 1, ;DEF F989:<9=. CORRELATED DELETE: VARCHAR2(13) VARCHAR2( ) NUMBER(,) DATE NUMBER(0$2) NUMBER(0$2) NUMBER(2)

,12

S"L4 CREATE TABLE EMP(PRESENT 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 CREATE TABLE EMP(PAST 2 AS ) SELECT # FROM EMP5 T6789 :;96<9=. S"L4 DELETE FROM EMP(PAST 2 WHERE EMPNO IN (0)/ $0022$02) $02,,$0022)5 . ;DEF =989<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 SELECT # FROM EMP(PAST5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 ;DEF F989:<9=. S"L4 SELECT # FROM EMP(PRESENT5 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 23 0, ALLEN SALESMAN 0/ 2 23&FEB&21 1/33 )33 )3 0.21 WARD SALESMAN 0/ 2 22&FEB&21 12.3 .33 )3 0.// JONES MANAGER 02) 32&APR&21 2 0. 23 0/., MARTIN SALESMAN 0/ 2 22&SEP&21 12.3 1,33 )3 0/ 2 BLA'E MANAGER 02) 31&MAY&21 22.3 )3 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 13 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 23 02) 'ING PRESIDENT 10&NOV&21 .333 13 02,, TURNER SALESMAN 0/ 2 32&SEP&21 1.33 3 )3 020/ ADAMS CLER' 0022 2)&MAY&20 1133 23 0 33 JAMES CLER' 0/ 2 3)&DEC&21 .3 )3 0 32 FORD ANALYST 0.// 3)&DEC&21 )333 23 0 ), MILLER CLER' 0022 2)&JAN&22 1)33 13 1, ;DEF F989:<9=. S"L4 DELETE FROM EMP(PRESENT E 2 WHERE EMPNOI ) (SELECT EMPNO FROM EMP(PAST M WHERE M.EMPNOIE.EMPNO)5 ;DEF =989<9=. S"L4 SELECT # FROM EMP(PRESENT5 EMPNO ENAME JOB MGR HIREDATE SAL COMM &&&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&& &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 0)/ SMITH CLER' 0 32 10&DEC&23 233 0022 CLAR' MANAGER 02) 3 &JUN&21 2,.3 0022 SCOTT ANALYST 0.// 1 &APR&20 )333 02) 'ING PRESIDENT 10&NOV&21 .333 02,, TURNER SALESMAN 0/ 2 32&SEP&21 .33 3 CONTROLLING USER ACCESS: DEPTNO 23 13 23 13 )3

,1

IN A MULTI USER ENVIRNOMENT$ YOU WANT TO MAINTAIN SECURITY OF THE DATABASE ACCESS AND USE. WITH THE ORACLE SERVER DATABASE SECURITY $ YOU CAN DO THE FOLLOWING% CONTOL DATABASE ACCESS. GIVE ACCESS TO SPECIFIC OBJECTS IN THE DATABASE.

DATABASE SECURITY CAN BE CLASSIFIED INTO T+O CATEGORIES:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SYSTEM SECURITY. DATA SECURITY.

,23

SYSTEM SECURITY COVERS ACCESS AND USE OF THE DATABASE AT SYSTEM LEVEL$SUCH AS USERNAME AND PASSWORD$DIS' SPACE ALLOCATED TO USERS$ AND SYSTEM OPERATIONS ALLOWED BY THE USER. DATABASE SECURITY COVERS ACCESS AND USE OF THE DATBASE OBJECTS AND THE ACTIONS THAT THOSE USERS CAN HAVE ON THE OBJECTS. PRIVILEGES ARE THE RIGHT TO E!ECUTE PARTICULAR S"L STATEMENTS.THE DATABASE ADMINISTRATOR IS A HIGH LEVEL USER WITH THE ABILITY TO GRANT USERS ACCESS TO THE DATABASE AND ITS OBJECTS. THE USERS RE"UIRE SYSTEM PRIVILEGES TO GAIN ACCESS TO THE DATABASE AND OBJECT PRIVILEGES TO MANIPULATE THE CONTENT OF THE OBJECTS IN THE DATABASE. USERS CAN ALSO BE GIVEN THE PRIVILEGE TO GRANT ADDITIONAL PRIVILEGES TO OTHER USERS OR ROLES$ WHICH ARE NAMED GROUPS OF RELATED PRIVILEGES. SC.E)A: A SCHEMA IS A COLLECTION OF OBJECTS$SUCH AS TABLES$VIEWS$ AND SE"UENCES. THE SCHEMA IS OWNED BY A DATABASE USER AND HAS THE SAME NAME AS THAT USER. PRI*ILEGES: 7(SYSTE) PRI*ILEGS( 6( OBJECT PRI*ILEGES(

SYSTE) PRI*ILEGES: GAIN ACCESS TO THE DATABASE. SYSTEM PRIVILEGES TYPICALLY ARE PROVIDED BY THE DATABASE ADMINISTRATOR.THE DBA HAS HIGH LEVEL SYSTEM PRIVILEGES% CREATE USERS$REMOVE TABLES$BAC' UP TABLES. OBJECT PRI*ILEGES:MANIPULATES THE CONTENTS OF THE DATABASE OBJECTS. CREATING USERS:

THE DBA CREATES USERS BY USING THE CREATE USER STATEMENT. S"L4 CREATE USER PAVAN 2 IDENTIFIED BY GAYATRI5 UF9; :;96<9=. AT THIS POINT USER DOES NOT HAVE ANY PRIVILEGES.THE DBA THEN GRANT THE NUMBER OF PRIVILEGES TO THAT USER.THESE PRIVILEGES DETERMINE WHAT THE USER CAN DO AT THE DATABASE LEVEL. ONCE A USER IS CREATED$ THE DBA CAN GRANT SPECIFIC SYSTEM PRIVILEGES TO USER.AN APPLICATION DEVELOPER MAY HAVE THE FOLLOWING SYSTEM PRIVILEGES. CREATE SESSION CREATE TABLE CREATE SE"UENCE CREATE VIEW CREATE PROCEDURE.

S"L4 GRANT CREATE SESSION$CREATE TABLE$CREATE SE"UENCE$CREATE VIEW$CREATE PROCEDURE TO PAVAN5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
G;6K< F?::99=9=. GRANTING PRI*ILEGES +IT. T.E PER)ISSION TO GRANT TO OT.ER USERS: G;6K< F?::99=9=. THE DBA CREATES USER ACCOUNT YOU CAN CHANGE THE PASSWORD. S"L4 ALTER USER PAVAN 2 IDENTIFIED BY GAYATRI5 UF9; 68<9;9=. ROLES:

,21

S"L4 GRANT CREATE SESSION$CREATE TABLE$CREATE SE"UENCE$CREATE VIEW$CREATE PROCEDURE TO PAVAN WITH ADMIN OPTION%

A ROLE IS A NAMED GROUP OF RELATED PRIVILEGES THAT CAN BE GRANTED TO THE USER.THIS METHOD MA'ES GRANTING AND REVO'ING PRIVILEGES EASIER TO PERFORM AND MAINTAIN.FIRST$THE DBA MUST CREATE ROLE.THEN THE DBA CAN ASSIGN PRIVILEGES TO THE ROLE AND USERS TO THE ROLE. S"L4 CREATE ROLE MANAGER5 RD89 :;96<9=. S"L4 GRANT CREATE SESSION$CREATE TABLE$CREATE SE"UENCE$CREATE VIEW$CREATE PROCEDURE TO MANAGER5 G;6K< F?::99=9=. S"L4 GRANT MANAGER TO SCOTT$SATISH5 G;6K< F?::99=9=. ORACLE PREDIFINES SEVERAL OTHER ROLES$WHICH INCLUDES COMMON SYSTEM PRIVILEGES.THE PREDIFINED ORACLE USER SYSTEM IS AUTOMATICALLY GRANTED ALL THESE ROLES. CONNECT: ALTER SESSION$CREATE CLUSTER$CREATE DATABASE LIN'$ CREATE SE"UENCE$CREATE SESSION$CREATE SYNONYM$CREATE TABLE$ CREATE VIEW. RESOURCE:CREATE CLUSTER$CREATE SE"UENCE$CREATE INDE! TYPE$ CREATE OPERATOR$CREATE PROCEDURE$CREATE TYPE$ CREATE TRIGGER$CREATE TABLE. DBA : ALL SYSTEM PRIVILEGS WITH ADMIN OPTION PLUS E!P(FULL(DATABASE AND IMP(FULL(DATABASE. OBJECT PRI*ILEGES: AN OBJECT PRIVILEGES IS A PRIVILEGE OR RIGHT TO PERFORM A PARTICULAR ACTION ON A SPECIFIC TABLE$VIEW$SE"UENCE OR PROCEDURE. OBJECT PRIVILEGE ALTER DELETE E!ECUTE INDE! INSERT REFERENCES SELECT UPDATE TABLE YES YES YES YES YES YES YES VIEW YES YES YES YES YES YES SE"UENCE YES PROCEDURE

OBJECT PRIVILEGES VARY FROM OBJECT TO OBJECT. AN OWNER HAS ALL THE PRIVILEGES ON THE OBJECT.AN OWNER CAN GIVE SPECIFIC PRIVILEGES ON THAT OWNERS OBJECT.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 GRANT SELECT ON EMP TO PAVAN$GAYATRI5 G;6K< F?::99=9=. GI*ING SPECIFIC COLU)NS PER)ISSION: S"L4 GRANT UPDATE(DNAME$LOC) 2 ON DEPT ) TO PAVAN$GAYATRI5 G;6K< F?::99=9=. GI*ING PER)ISSION ON TABLE +IT. GRANT OPTION:

,22

S"L4 GRANT SELECT$INSERT 2 ON DEPT ) TO GAYATRI , WITH GRANT OPTION5 G;6K< F?::99=9=. GI*ING PER)ISSION ON TABLE TO ALL USERS:

S"L4 GRANT SELECT ON EMP 2 TO PUBLIC5 G;6K< F?::99=9=. GI*ING ALL T.E PRI*ILEGES ON TABLE TO USER:

S"L4 GRANT ALL ON EMP TO GAYATRI5 G;6K< F?::99=9=. RE*O-EING PER)ISSIONS:

S"L4 REVO'E SELECT ON EMP FROM PAVAN$GAYATRI5 R9QDL9 F?::99=9=.

IF YOU +ANT TO RE*O-E COLU)N SPECIFIC PER)ISSIONS +E .A*E TO RE*O-E FRO) TABLE NOT FRO) COLU)N(

S"L4 REVO'E UPDATE(DNAME$LOC) 2 ON DEPT ) FROM PAVAN$GAYATRI5 REVO'E UPDATE(DNAME$LOC) # ERROR 6< 8NK9 1% ORA&310.3% UPDATE/REFERENCES >6A DK8A 79 REVO'E= T;D> <R9 ERD89 <6789$ KD< 7A :D8?>K S"L4 REVO'E UPDATE ON DEPT 2 FROM PAVAN$GAYATRI5 R9QDL9 F?::99=9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
S"L4 REVO'E SELECT$INSERT 2 ON DEPT )# FROM GAYATRI5 R9QDL9 F?::99=9=. YOU CANNOT RE*O-E PRI*ILEGES T.AT YOU .AD NOT GRANT BEFORE( S"L4 REVO'E SELECT$INSERT # ERROR 6< 8NK9 1% ORA&31 20% :6KKD< REVO'E B;NQN89S9F AD? =N= KD< S;6K< S"L4 REVO'E SELECT ON EMP 2 FROM PUBLIC5 R9QDL9 F?::99=9=. S"L4 REVO'E ALL ON EMP FROM GAYATRI5 R9QDL9 F?::99=9=.

,2)

DESCRIBE TABLES O+NED BY T.E USER:

SELECT # FROM USER(TABLES5

*IE+ DISTINCT OBJECT TYPES O+NED BY T.E USER:

SELECT DISTINCT OBJECT(TYPE FROM USER(OBJECTS5 *IE+ TABLES"*IE+S"SYNONY)S AND SEQUENCES O+NED BY T.E USER:

SELECT # FROM USER(CATALOG5 USER(CATALOG HAS A SYNONYM CALLED CAT. TABLES IN T.E ORACLE DATABASE: USER TABLES:

COLLECTION OF TABLES CREATED AND MANTAINED BY THE USER. CONTAINS USER INFORMATION. DATA DICTIONARY: COLLECTION OF TABLES CREATED AND MAINTAINED BY THE ORACLE SERVER$CONTAINS DATABASE INFORMATION. ALL THE DATA DICTIONARY TABLES ARE OWNED BY THE SYS USER. THE BASE TABLES ARE RARELY ACCESSED BY THE USER BECAUSE THE INFORMATION IN THEM IS NOT EASY TO UNDERSTAND.THEREFORE$USER TYPICALLY ACCESS DATA DICTIONARY VIEWS BECAUSE THE INFORMATION IS PRESENTED IN A FORMAT THAT IS EASY TO

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
T.ERE ARE FOUR CATEGORIES OF DATA DICTIONARY *IE+S: USER( ALL( DBA( THESE VIEWS CONTAIN INFORMATION ABOUT OBJECTS OWNED BY THE USER. THESE VIEWS CONTAIN INFORMATION ABOUT ALL THE TABLES ACCESSIBLE TO THE USER. THESE VIEWS ARE RESTRICTED VIEWS. ONLY DBA OR ROLE DBA WHO HAS CAN ACCESS THESE.

,2,

UNDERSTAND.INFORMATION STORED IN THE DATA DICTIONARY INCLUDE NAMES OF THE ORACLE SERVER USERS$PRIVILEGES GRANTED TO USERS.DATABASE OBJECT NAMES$TABLE CONSTRAINTS$ AND AUDITING INFORMATION.

V`( THESE VIEWS CONTAINS INFORMATION ABOUT DYNAMIC PERFORMANCE VIEWS$DATABASE SERVER PERFORMANCE AND LOC'ING. PL0SQL SECURITY: USERS MANIPULATE ORACLE TABLE DATA VIA S"L OR PL/S"L SENTENCES. AN ORACLE TRANSACTION CAN BE MADE UP OF A SINGLE S"L SENTENCE OR SEVERAL S"L SENTENCES. THIS GIVE RISE TO SINGLE "UERY TRASACTIONS AND MULTIPLE "UERY TRANSACTIONS.(I.E.$ S"T AND M"T). THESE TRANSACTIONS (WHETHER S"T OR M"T) ACCESS AN ORACLE TABLE(S).SINCE ORACLE WOR'S ON A MULTI& USER PLATFORM $IT IS MORE THAN LI'ELY THAT SEVERAL PEOPLE WILL ACCESS DATA EITHER FOR VIEWING OR FOR MANIPULATING (INSERTING$UPDATING AND DELETING RECORDS) FROM THE SAME TABLES AT THE SAME TIME VIA DIFFERENT S"L STATEMENTS. THE ORACLE TABLE IS THEREFORE A GLOBAL RESOURCE. N.9.$ IT IS SHARED BY SEVERAL USERS. TABLES(N.9.. GLOBAL RESOURCE) CONTAIN VALUABLE DATA ON WHICH BUSSINESS DECISIONS ARE BASED. THERE IS A DEFINITE NEED TO ENSURE THAT THE INTEGRITY OF DATA IN A TABLE IS MAINTAINED EACH TIME THAT ITS DATA IS ACCESSED. THE ORACLE ENGINE HAS TO ALLOW SIMULTANEOUS ACCESS TO TABLE DATA WITHOUT CAUSING DAMAGE TO THE DATA. THE TECHNI"UE EMPLOYED BY THE ORACLE ENGINE TO PROTECT TABLE DATA WHEN SEVERAL PEOPLE ARE ACCESSING IT IS CALLED CONCURRENCY CONTROL. ORACLE USES A METHOD CALLED LOC'ING TO IMPLEMENT CONCURRENCY CONTROL WHEN MULTIPLE USERS ACCESS A TABLE TO MANIPULATE ITS DATA AT THE SAME TIME. LOC'S ARE MECHANISMS USED TO ENSURE DATA INTEGRITY WHILE ALLOWING MA!IMUM CONCURRENT ACCESS TO DATA. ORACLES LOCIING IS FULLY AUTOMATIC AND RE"UIRES NO USER INTERVENTION. THE ORACLE ENGINE AUTO MATICALLY LOC'S TABLE DATA WHILE E!ECUTING S"L STATEMENTS. THIS TYPE OF LOC'ING IS CALLED IMPLICIT LOC'ING. I)PLICIT LOC-ING: SINCE THE ORACLE ENGINE HAS FULLY AUTOMATIC LOC'ING STRATEGY$ IT HAS TO DECIDE ON TWO ISSUES% TYPE OF LOC' IS TO BE APPLIED. LEVEL OF LOC' TO BE APPLIED. TYPES OF LOC-S:

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
READ OPERATIONS : SELECT STATEMENTS. +RITE OPERATIONS: INSERT$ UPDATE$DELETE STATEMENTS.

,2.

THE TYPE OF LOC' TO BE PLACED ON A RESOURCE DEPENDS ON THE OPERATION BEING PERFORMED ON THAT RESOURCE. OPERATIONS ON TABLES CAN BE DISTINCTLY GROUPED INTO T.E FOLLO+ING T+O CATEGORIES:

SINCE READ OPERATIONS MA'E NO CHANGES TO DATA IN A TABLE AND ARE MEANT ONLY FOR VIEWING PURPOSES$SIMULTANEOUS READ OPERATIONS CAN BE PERFORMED ON A TABLE WITHOUT ANY DANGER TO THE TABLES DATA. HENCE$THE ORACLE ENGINE PLACES A SHARED LOC' ON A TABLE WHEN ITS DATA IS BEING VIEWED. ON THE OTHER HAND$ WRITE OPERATIONS CAUSE A CHANGE IN TABLE DATA N.9.$ ANY INSERT$UPDATE OR DELETE STATEMENT AFFECTS TABLE DATA DIRECTLY AND HENCE$SIMULTANEOUS WRITE OPERATIONS CAN ADVERSLY AFFECT TABLE DATA INTEGRITY. SIMULTANEOUS WRITE OPERATION WILL CAUSE LOSS OF DATA CONSISTENCY IN THE TABLE. HENCE ORACLE ENGINE PLACES AN E!CLUSIVE LOC' ON TABLE OR SPECIFIC SECTIONS OF THE TABLESS RESOURCES WHEN DATA IS BEGING WRITTEN TO A TABLE. T.E RULES OF LOC-ING: DATA BEING CHANGED CANNOT BE READ. WRITERS WAIT FOR OTHER WRITERS$ IF THEY ATTEMPT TO UPDATE THE SAME ROWS AT THE SAME TIME. THE TWO TYPES OF LOC'S SUPPORTED BY ORACLE ARE% S.ARED LOC-S: SHARED LOC'S ARE PLACED ON RESOURCES WHENEVER A READ OPERATION(SELECT) IS PERFORMED. MULTIPLE SHARED LOC'S CAN BE SIMULTANEOUSLY SET ON A RESOURCE.

E/CLUSI*E LOC-S: E!CLUSIVE LOC'S ARE PLACED ON RESOURCES WHENEVER WRITE OPERATIONS (INSERT$UPDATE AND DELETE) ARE PERFORMED. ONLY ONE E!CLUSIVE LOC' CAN BE PLACED ON A RESOURCE AT A TIME. N.9.$ THE FIRST USER WHO AC"URIES AN E!CLUSIVE LOC' WILL CONTINUE TO HAVE THE SOLE OWNERSHIP OF THE RESOURCE$ AND NO OTHER USER CAN AC"UIRE AN E!CLUSIVE LOC' ON THAT RESOURCE. ORACLE PROVIDES THE FOLLOWING THREE LEVELS OF LOC'ING% RO+ LE*EL( PAGE LE*EL( TABLE LE*EL(

THE ORACLE ENGINE DECIDES ON THE LEVEL OF LOC' TO BE USED BY THE PRESENCE OR ABSENCE OF A WHERE CONDITION IN A S"L STATEMENT.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
IF THE WHERE CLAUSE EVALUATES TO ONLY ONE ROW IN THE TABLE$ A ROW LEVEL LOC' IS USED. IF THE WHERE CLAUSE EVALUATES TO A SET OF DATA$ A PAGE LEVEL LOC' IS USED. IF THERE IS NO WHERE CLAUSE$(N.9.$ THE "UERY ACCESSES THE ENTIRE TABLE$) A TABLE LEVEL LOC' IS USED.

,2/

ALTHOUGH THE ORACLE ENGINE HAS A DEFAULT LOC'ING STRATERGY IN COMMERCIAL APPLICATIONS$ E!PLICIT USER DEFINED LOC'ING OFTEN RE"UIRED. IF TWO CLIENT COMPUTERS(CLIENT A AND CLIENT B) ARE ENTERING SALES ORDERS$ EACH TIME A SALES ORDER IS PREPARED$ THE "UANTITY ON HAND OF THE PRODUCT FOR WHICH THE ORDER IS BEING GENERATED NEEDS TO BE UPDATED IN THE PRODUCT(MASTER TABLE. NOW$ IF THE CLIENT A FIRES AN UPDATE COMMAND ON A RECORD IN THE PRODUCT(MASTER TABLE$ THEN ORACLE WILL IMPLICITLY LOC' THE RECORD SO THAT NO FURTHER DATA MANIPULATION CAN BE DONE BY ANY OTHER USER TILL THE LOC' IS RELEASED. THE LOC' WILL BE RELEASED ONLY WHEN CLIENT A FIRES A COMMIT OR ROLLBAC'. IN THE MEANTIME $ IF CLIENT B TRIES TO VIEW THE SAME RECORD$ THE ORACLE ENGINE WILL DISPLAY THE OLD SET FOR VALUES FOR THE RECORD AS THE TRANSACTION FOR THAT RECORD HAS BEEN COMPLETED BY CLIENT A. THIS LEADS TO WRONG INFORMATION BEING DISPLAYED TO CLIENT B. IN SUCH CASES$ CLIENT A MUST E!PLICITLY LOC' THE RECORD SUCH THAT$ NO OTHER USER CAN ACCESS THE RECORD EVEN FOR VIEWING PURPOSES TILL CLIENT AS TRANSACTION IS COMPLETED. A LOC' SO DEFINED IS CALLED E!PLICIT LOC'. USER DEFINED E!PLICIT LOC'ING ALWAYS OVERRIDES ORACLES DEFAULT LOC'ING STRATEGY. E/PLICIT LOC-ING: THE TECHNI"UE OF LOC' TA'EN ON A TABLE OR ITS RESOURCES BY A USER IS CALLED E!PLICIT LOC'ING. +.O CAN LOC- E/PLICITLY: USER CAN LOC' TABLES THEY OWN OR ANY TABLES ON WHICH THEY HAVE BEEN GRANTED TABLE PRIVILEGES(SUCH AS SELECT$INSERT$UPDATE$DELETE). ORACLE PROVIDES FACILITIES BY WHICH DEFAULT LOC'ING STRATEGY CAN BE OVERRIDEN. TABLES OR ROWS CAN BE E!PLICITLY LOC'ED BY USING EITHER THE SELECT* FOR UPDATE STATEMENT$ OR LOC' TABLE STATEMENT. THE SELECT *. FOR UPDATE STATEMENT. TWO CLIENT MACHINES CLIENT A AND CLIENT B ARE RECORDING THE TRANSACTIONS PERFORMED IN A BAN' FOR A PARTICULAR ACCOUNT NUMBER SIMULTANEOUSLY. CLIENT A FIRES THE FOLLOWING SELECT STATEMENT% CLIENT A 4 SELECT # FROM ACCT(MSTR WHERE ACC(NO I GSB FOR UPDATE. ORACLE LOC'S THE RECORD SB . IT RELEASES WHEN A COMMIT OR ROLLBAC' IS FIRED BY CLIENT A. NOW CLIENT B FIRES THE SELECT STATEMENT$ WHICH POINTS TO RECORD SB $ WHICH IS ALREADY LOC'ED BY CLIENT A. CLIENT B4 SELECT # FROM ACCT(MSTR WHERE ACC(NO I GSB FOR UPDATE5 THE ORACLE ENGINE WILL ENSURE THAT CLIENT BS S"L STATEMENT WAITS FOR THE LOC' TO BE RELEASED ON ACC(MSTR BY A COMMIT OR ROLLBAC' STATEMENT FIRED BY CLIENT A FOREVER. IN ORDER TO AVOID UNNECESSARY WAITING TIME$ A NOWAIT OPTION CAN BE USED TO INFORM THE ORACLE ENGINE TO TERIMINATE THE S"L STATEMENT IF THE RECORD HAS BEEN LOC'ED.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
IF CLIENT B FIRES THE FOLLOWING SELECT STATEMENT NOW WITH NOWAIT CLAUSE. CLIENT B4 SELECT # FROM ACCT(MSTR WHERE ACC(NO I GSB FOR UPDATE NOWAIT5 OUTPUT%

,20

IF THIS HAPPENS THE ORCLE ENGINE TERIMINATES THE RUNNING DML AND COMES UP WITH A MESSAGE INDICATING THAT THE RESOURCE IS BUSY.

SINCE CLIENT A HAS ALREADY LOC'ED RECORD SB WHEN CLIENT B TRIES TO AC"UIRE A SHARED LOC' ON THE SAME RECORD THE ORACLE ENGINE DIPLAYS THE FOLLOWING MESSAGE. S"L4 333.,% RESOURCE BUSY AND AC"UIRE WITH NOWAIT SPECIFIED. USING LOC- TABLE STATE)ENT: LOC' TABLE W TABLE NAME4 [$ W TABLE NAME\*. IN ] ROW SHAREVROW E!CLUSIVE VSHARE UPDATEVSHAREVSHARE ROW E!CLUSIVE VE!CLUSIVE^ [NO WAIT\

TABLE PARTITIONS: TABLES CAN BE PARTITIONED AND STORED IN DIFFERENT LOCATIONS AS PER RE"UIREMENT. A SINGLE LOGICAL TABLE CAN BE SPILT IN TO A NUMBER OF PHYSICALLY SEPARATE PIECES BASED ON RANGES OF 'EY VALUES. EACH OF THE PARTS OF THE TABLE IS CALLED A PARTITION. ALTHOUGH THE PARTITIONS ARE HELD AND MANAGED INDEPENDENTLY$ THEY CAN BE "UERIED AND UPDATED BY REFERENCE TO THE NAME OF THE LOGICAL TABLE. ORACLE PROVIDES PARTITION TRANSPARENCY. THE APPLICATION COULD BE UNAWARE OF THE FACT THAT THE TABLE HAS BEEN PARTITIONED. THERE IS A DIFFERENCE BETWEEN A TABLE $ WHICH HAS A SINGLE PARTITION$ AND A TABLE THAT HAS NO PARTITIONS. A NON&PARTITIONED TABLE CANNOT PARTITIONED LATER.EACH PARTITION IS STORED IN A DIFFERENT SEGMENT AND HAS DIFFERENT PHYSICAL ATTRIBUTES. TABLE PARTITIONS CAN BE STORED IN DIFFERENT TABLE SPACES. ORACLE PROVIDES PARTITION INDEPENDENCE. WE CAN ACCESS AND MANIPULATE DATA IN ONE PARTITION EVEN IF SOME OR ALL OF THE OTHER PARTITION ARE UNAVAILABLE. THIS IS MAJOR BENEFIT FOR ADMINISTRATORS AND USERS. THIS MEANS THAT THEY CAN PERFORM MAINTENANCE OPERATIONS IN A PIECE MEAL FASHION AGAINST INDIVIDUAL PARTITIONS WHILE THE REST OF THE DATA REMAINS AVAILABLE FOR USE. AD*ANTAGES: IT REDUCES THE POSSIBILITY OF DATA CORRUPTION INMULTIPLE PARTITIONS. BAC' UP AND RECOVERY OF EACH PARTITION CAN BE DONE INDEPENDENTLY. CONTROLLING THE MAPPING OF PARTITIONS TO DIS' DRIVES(IMPORTANT FOR BALANCING I/O LOAD) IS POSSIBLE. PARTITIONED TABLES CANNOT CONTAIN ANY COLUMNS WITH LONG OR LONG RAW DATATYPES$ LOB DATATYPES (BLOB$CLOB$NCLOB$ OR BFILE) OR OBJECT TYPES.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
THERE ARE TWO PRIMARY REASONS FOR PARTITIONING A TABLE. CREATE TABLE TABLE(NAME (COL1 DATATYPE$ COL 2 DATATYPE$ **. ) PARTITION BY RANGE (COL(NAME) (PARTITION W PARTITION(NAME4 VALUES LESS THAN WVALUE4$ PARTITION W PARTITION(NAME 4 VALUE LESS THAN W VALUE4)5 DIS' SPACE. PROCESSING TIME.

,22

1 CREATE TABLE ANGEL 2 (EMPNO NUMBER(13) CONSTRAINT ANGEL(P' PRIMARY 'EY$ ) ENAME VARCHAR2(13)$ , JOB VARCHAR2(13)) . PARTITION BY RANGE (EMPNO) /# (PARTITION EM1 VALUES LESS THAN (13)$ PARTITION EM2 VALUES LESS THAN (23)) S"L4 / T6789 :;96<9=.

S"L4 INSERT INTO ANGEL 2 VALUES ) (1$CPAVANC$CMANAGERC)5 1 ;DE :;96<9=. 1 INSERT INTO ANGEL 2 VALUES )# (2$C'UMARC$CMANAGERC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO ANGEL 2 VALUES )# (11$CSMITHC$CMANAGERC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO ANGEL

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
2 VALUES )# (12$CALLENC$CCLER'C) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO ANGEL 2 VALUES )# (13$CARYAC$CCLER'C) S"L4 / 1 ;DE :;96<9=. S"L4 COMMIT5 CD>>N< :D>B89<9. S"L4 SELECT # FROM ANGEL PARTITION(EM1)5 EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 1 PAVAN MANAGER 2 'UMAR MANAGER S"L4 SELECT # FROM ANGEL PARTITION(EM2)5 EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 11 SMITH MANAGER 12 ALLEN CLER' 13 ARYA CLER'

,2

1 CREATE TABLE ANGEL2 2 (ORDERNO VARCHAR2(13) CONSTRAINT ANGEL2(P' PRIMARY 'EY$ ) ODATE DATE$ , VENCODE VARCHAR2(13)) . PARTITION BY RANGE (ORDERNO$VENCODE) / (PARTITION OM1 VALUES LESS THAN (CO313C$CVO13C)$ 0 PARTITION OM2 VALUES LESS THAN (CO323C$CV323C)$ 2# PARTITION OM) VALUES LESS THAN (MA!VALUE$MA!VALUE)) S"L4 / T6789 :;96<9=. S"L4 INSERT INTO ANGEL2 2 VALUES ) (CO331C$C2)&FEB& 1 ;DE :;96<9=. C$CV331C)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 INSERT INTO ANGEL2 2 VALUES )# (CO332C$C2)&FEB& S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO ANGEL2 2 VALUES )# (CO31.C$C2)&FEB& S"L4 / 1 ;DE :;96<9=. C$CV332C) C$CV332C)

,)3

1 INSERT INTO ANGEL2 2 VALUES )# (CO32.C$C2)&FEB& S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO ANGEL2 2 VALUES )# (CO32/C$C2)&FEB& S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO ANGEL2 2 VALUES )# (CO320C$C2)&FEB& S"L4 / 1 ;DE :;96<9=. S"L4 COMMIT5 CD>>N< :D>B89<9. C$CV332C) C$CV332C) C$CV332C)

1# SELECT # FROM ANGEL2 PARTITION(OM1) S"L4 /

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
ORDERNO ODATE VENCODE &&&&&&&&&& &&&&&&&&& &&&&&&&&&& O331 2)&FEB& V331 O332 2)&FEB& V332 1# SELECT # FROM ANGEL2 PARTITION(OM2) S"L4 / ORDERNO ODATE VENCODE &&&&&&&&&& &&&&&&&&& &&&&&&&&&& O31. 2)&FEB& V332 1# SELECT # FROM ANGEL2 PARTITION(OM)) S"L4 / ORDERNO ODATE VENCODE &&&&&&&&&& &&&&&&&&& &&&&&&&&&& O32. 2)&FEB& V332 O32/ 2)&FEB& V332 O320 2)&FEB& V332

,)1

HERE THE VALUES O32.$O32/$O320 ARE GREATER THAN FIRST AND SECOND PARTITION$ BUT VENCODE VALUE IS FALLS IN THE FIRST PARTITION. EVEN THEN IT FALLS IN THIRD PARTITION BECAUSE THE LEFT PREFI! OF THE PARTITION BOUND TA'ES PRECEDENCE. )AINTAINING PARTITIONS: MOVING PARTITIONS. ADDING PARTITIONS. DROPPING PARTITIONS. SPLITTING PARTITIONS. E!CHANGING TABLE PARTITIONS.

)O*ING PARTITIONS: S"L4 ALTER TABLE ANGEL2 2 MOVE PARTITION OM1 TABLESPACE PAVAN(TAB5 T6789 68<9;9=.

S"L4 SELECT # FROM ANGEL2 PARTITION(OM1)5 ORDERNO ODATE VENCODE &&&&&&&&&& &&&&&&&&& &&&&&&&&&& O331 2)&FEB& V331 O332 2)&FEB& V332 ADDING PARTITIONS: S"L4 ALTER TABLE ANGEL 2 ADD PARTITION EM) VALUES LESS THAN ()3)5 T6789 68<9;9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
SPLITTING PARTITIONS: S"L4 ALTER TABLE ANGEL 2 SPLIT PARTITION EM) AT(2.) INTO (PARTITION EM11$ PARTITION EM12)5 T6789 68<9;9=. S"L4 INSERT INTO ANGEL 2 VALUES ) (21$CFORDC$CMANAGERC)5 1 ;DE :;96<9=. 1 INSERT INTO ANGEL 2 VALUES )# (22$CDONC$CMANAGERC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO ANGEL 2 VALUES )# (2/$CFRAN'C$CMANAGERC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO ANGEL 2 VALUES )# (22$CSCOTTC$CMANAGERC) S"L4 / 1 ;DE :;96<9=. S"L4 COMMIT5 CD>>N< :D>B89<9. S"L4 SELECT # FROM ANGEL PARTITION(EM))5 SELECT # FROM ANGEL PARTITION(EM)) # ERROR 6< 8NK9 1% ORA&321, % SB9:NTN9= B6;<N<NDK =D9F KD< 9UNF<

,)2

1# SELECT # FROM ANGEL PARTITION(EM11) S"L4 / EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 21 FORD MANAGER 22 DON MANAGER

1# SELECT # FROM ANGEL PARTITION(EM12) S"L4 / EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 2/ FRAN' MANAGER

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
22 SCOTT MANAGER S"L4 ALTER TABLE ANGEL 2 DROP PARTITION EM)5 DROP PARTITION EM) # ERROR 6< 8NK9 2% ORA&321, % SB9:NTN9= B6;<N<NDK =D9F KD< 9UNF< S"L4 ALTER TABLE ANGEL 2 DROP PARTITION EM25 T6789 68<9;9=. S"L4 SELECT # FROM ANGEL PARTITION(EM2)5 SELECT # FROM ANGEL PARTITION(EM2) # ERROR 6< 8NK9 1% ORA&321, % SB9:NTN9= B6;<N<NDK =D9F KD< 9UNF<

,))

CREATING PARTITIONS IN DIFFERENT TABLE SPACES:

S"L4 CREATE TABLE ANGEL) 2 (EMPNO NUMBER(13) PRIMARY 'EY$ ) ENAME VARCHAR2(13)$ , JOB VARCHAR2(13)) . PARTITION BY RANGE(EMPNO) / (PARTITION EM1 VALUES LESS THAN (13) TABLESPACE PAVAN(TAB$ 0 PARTITION EM2 VALUES LESS THAN (23) TABLESPACE PAVAN1(TAB)5 T6789 :;96<9=. E/C.ANGING TABLE PARTITIONS

S"L4 CREATE TABLE ANGEL, 2 (EMPNO NUMBER(13) PRIMARY 'EY$ ) ENAME VARCHAR2(13)$ , JOB VARCHAR2(13)) . PARTITION BY RANGE(EMPNO) / (PARTITION EM1 VALUES LESS THAN (13)$PARTITION EM2 VALUES LESS THAN (23))5 T6789 :;96<9=. S"L4 INSERT INTO ANGEL, 2 VALUES ) (1$CPAVANC$CMANAGERC)5 1 ;DE :;96<9=. 1 INSERT INTO ANGEL, 2 VALUES )# (2$C'UMARC$CMANAGERC) S"L4 / 1 ;DE :;96<9=.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
1 INSERT INTO ANGEL, 2 VALUES )# (11$CSMITHC$CMANAGERC) S"L4 / 1 ;DE :;96<9=.

,),

1 INSERT INTO ANGEL, 2 VALUES )# (12$CFORDC$CMANAGERC) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO ANGEL, 2 VALUES )# (1)$CFRAN'C$CMANAGERC) S"L4 / 1 ;DE :;96<9=. S"L4 COMMIT5 CD>>N< :D>B89<9. S"L4 CREATE TABLE E!CHANGE(PAR 2 (EMPNO NUMBER(13) PRIMARY 'EY$ ) ENAME VARCHAR2(13)$ , JOB VARCHAR2(13))5 T6789 :;96<9=. S"L4 INSERT INTO E!CHANGE(PAR 2 VALUES ) (10$CSCOTTC$CCLER'C)5 1 ;DE :;96<9=. 1 INSERT INTO E!CHANGE(PAR 2 VALUES )# (12$C'INGC$CCLER'C) S"L4 / 1 ;DE :;96<9=. 1 INSERT INTO E!CHANGE(PAR 2 VALUES )# (1 $CJULIC$CCLER'C) S"L4 / 1 ;DE :;96<9=. S"L4 COMMIT5 CD>>N< :D>B89<9.

S"L4 SELECT # FROM ANGEL, PARTITION(EM1)5

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE

ORACLE
EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 1 PAVAN MANAGER 2 'UMAR MANAGER 1# SELECT # FROM ANGEL, PARTITION(EM2) S"L4 / EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 11 SMITH MANAGER 12 FORD MANAGER 1) FRAN' MANAGER S"L4 SELECT # FROM E!CHANGE(PAR5 EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 10 SCOTT CLER' 12 'ING CLER' 1 JULI CLER' S"L4 ALTER TABLE ANGEL, E!CHANGE PARTITION EM2 WITH TABLE E!CHANGE(PAR5 T6789 68<9;9=. S"L4 SELECT # FROM ANGEL, PARTITION(EM2)5 EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 10 SCOTT CLER' 12 'ING CLER' 1 JULI CLER' S"L4 SELECT # FROM E!CHANGE(PAR5 EMPNO ENAME JOB &&&&&&&&&& &&&&&&&&&& &&&&&&&&&& 11 SMITH MANAGER 12 FORD MANAGER 1) FRAN' MANAGER

,).

E!CHANGING TABLE PARTITIONS IS USED CONVERT A PARTITION INTO A NON&PARTITIONED TABLE$AND A TABLE INTO A PARTITION OF A PARTITIONED TABLE BY E!CHANGING THEIR DATA SEGMENTS. E!CHANGING TABLE PARTITIONS IS MOST USEFUL WHN AN APPLICATION USING NON&PARTITIONEDTABLES NEED TO BE CONVERTED INTO PARTITIONS OF A PARTICULAR TABLE.

I Soft Solutio ! "B# $%&'(

STRUCTURED QUERY LANGUAGE