Published on

Please dont ask for download/ file sending.

Published in: Technology, Business
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Oracle 9i A Presentation By: Kamlesh C
  2. 2. Session Objectives <ul><li>Introduction of RDBMS - Oracle 9i </li></ul><ul><ul><li>What is RDBMS? </li></ul></ul><ul><ul><li>Normalization </li></ul></ul><ul><ul><li>Oracle9i Built-In Data types </li></ul></ul><ul><ul><li>Structured Query Language </li></ul></ul><ul><ul><li>Oracle Built-In Functions </li></ul></ul><ul><ul><ul><li>String </li></ul></ul></ul><ul><ul><ul><li>Numbers </li></ul></ul></ul><ul><ul><ul><li>Date </li></ul></ul></ul><ul><ul><ul><li>Transformation </li></ul></ul></ul><ul><ul><li>Grouping Data Together </li></ul></ul><ul><ul><li>Other Database Objects </li></ul></ul><ul><ul><li>Oracle Text </li></ul></ul>
  3. 3. Session Objectives <ul><li>PL/SQL </li></ul><ul><ul><li>What is PLSQL </li></ul></ul><ul><ul><li>Introduction of Cursors </li></ul></ul><ul><ul><li>Subprograms </li></ul></ul><ul><ul><ul><li>Procedures </li></ul></ul></ul><ul><ul><ul><li>Functions </li></ul></ul></ul><ul><ul><li>Packages </li></ul></ul><ul><ul><li>Triggers </li></ul></ul>
  4. 4. <ul><li>Introduction of RDBMS – Oracle 9i </li></ul>
  5. 5. What is RDBMS? <ul><li>What is Database Management System ? </li></ul><ul><li>Data is just &quot;Data&quot; until it is organized in a meaningful way, at which points it becomes &quot;information&quot;. Oracle is also a means of easily turning data into information. </li></ul><ul><li>  </li></ul><ul><li>A relational database management system gives a way of doing </li></ul><ul><li>these tasks in an understandable and reasonably uncomplicated </li></ul><ul><li>way. It basically does three things: </li></ul><ul><li>       Lets you put data into it. </li></ul><ul><li>     Keeps the data </li></ul><ul><li>     Lets you to get the data out and work with it. </li></ul><ul><li>Note: An object relational database management system extends the capabilities of </li></ul><ul><li>the RDBMS to support object-oriented concepts. </li></ul>
  6. 6. Normalization <ul><li>Normalization is process of identifying the functional dependencies </li></ul><ul><li>between different business entities. Data is split into a number of </li></ul><ul><li>related tables in order to minimize duplication of information. </li></ul><ul><li>1st Rule of normalization: Each cell should have 1 value only. </li></ul><ul><li>2nd Rule of normalization: Partial dependencies </li></ul><ul><li>3rd Rule of normalization: Transitive dependency - No non PK should transitively dependent upon PK. </li></ul><ul><li>4th Rule of normalization: Multi Value dependencies </li></ul><ul><li>5th Rule of normalization: Loss less join </li></ul>
  7. 7. Oracle Built-in Data Types <ul><li>A datatype associates a fixed set of properties with the values that can be used in a column of a table. These properties cause Oracle to treat values of one datatype differently from values of another datatype. For example, Oracle can add values of NUMBER datatype, but not values of RAW datatype. </li></ul><ul><li>Oracle supplies the following built-in datatypes: </li></ul><ul><li>Character datatypes </li></ul><ul><li>CHAR </li></ul><ul><li>NCHAR </li></ul><ul><li>VARCHAR2 and VARCHAR </li></ul><ul><li>NVARCHAR2 </li></ul><ul><li>CLOB </li></ul><ul><li>NCLOB </li></ul><ul><li>LONG </li></ul><ul><li>NUMBER datatype </li></ul>
  8. 8. Oracle Built-in Data Types (cont.) <ul><ul><li>Time and date datatypes: </li></ul></ul><ul><ul><li>DATE </li></ul></ul><ul><ul><li>INTERVAL DAY TO SECOND </li></ul></ul><ul><ul><li>INTERVAL YEAR TO MONTH </li></ul></ul><ul><ul><li>TIMESTAMP </li></ul></ul><ul><ul><li>TIMESTAMP WITH TIME ZONE </li></ul></ul><ul><ul><li>TIMESTAMP WITH LOCAL TIME ZONE </li></ul></ul><ul><ul><li>Binary datatypes: </li></ul></ul><ul><ul><li>BLOB </li></ul></ul><ul><ul><li>BFILE </li></ul></ul><ul><ul><li>RAW </li></ul></ul><ul><ul><li>LONG RAW </li></ul></ul><ul><li>Another datatype, ROWID, is used for values in the ROWID pseudo column, which represents the unique address of each row in a table . </li></ul><ul><li>More information on Oracle Datatypes </li></ul>
  9. 9. SQL - Structured Query Language <ul><li>Types of SQL statements </li></ul><ul><li>Structured Query Language (SQL) Statements </li></ul><ul><ul><li>Data Definition Language (DDL) Statements </li></ul></ul><ul><ul><li>Data Manipulation Language (DML) Statements </li></ul></ul><ul><ul><li>Data Control Language (DCL) </li></ul></ul><ul><li>Transaction Control (TCL) Statements </li></ul><ul><li>Session Control Statements </li></ul><ul><li>System Control Statements </li></ul>
  10. 10. SQL - Structured Query Language <ul><ul><li>SQL is used to communicate with a database. According to ANSI (American National Standards Institute), it is the standard language for relational database management systems. SQL statements are used to perform tasks such as update data on a database, or retrieve data from a database. The standard SQL commands such as &quot;Select&quot;, &quot;Insert&quot;, &quot;Update&quot;, &quot;Delete&quot;, &quot;Create&quot;, and &quot;Drop&quot; can be used to accomplish almost everything that one needs to do with a database. </li></ul></ul><ul><ul><li>SELECTING DATA </li></ul></ul><ul><ul><li>SELECT [DISTINCT] &quot;COLUMN1&quot; [,&quot;COLUMN2&quot;,ETC] FROM &quot;TABLENAME&quot; [WHERE &quot;CONDITION&quot;] [GROUP BY “COLUMN1,COLUMN2”, ETC] [HAVING “ARITHMATIC EXPRESSION”] [ORDER BY “COLUMN1, COLUMN2”, ETC ASC | DESC NULLS FIRST | NULLS LAST] [FOR UPDATE OF “COLUMN1” NOWAIT | WAIT [DURATION]]; </li></ul></ul><ul><ul><li>[] = optional </li></ul></ul><ul><ul><li>INSERTING INTO A TABLE </li></ul></ul><ul><ul><li>INSERT INTO &quot;TABLENAME&quot; (FIRST_COLUMN,...LAST_COLUMN) VALUES (FIRST_VALUE, ...LAST_VALUE); </li></ul></ul><ul><ul><li>INSERT INTO “TABLENAME1” (“COLUMN1”, “COLUMN2”, ETC.) SELECT “COLUMN1”,”COLUMN2”, ETC FROM “TABLENAME2”; </li></ul></ul><ul><ul><li>Note: Corresponding column datatype should be compatible </li></ul></ul>
  11. 11. SQL - Structured Query Language <ul><ul><li>Inserting into a Table (cont.) </li></ul></ul><ul><ul><li>UN-CONDITIONAL INSERT ALL : </li></ul></ul><ul><ul><li>INSERT ALL INTO &quot;TABLENAME1&quot; VALUES (&quot;COLUMN1&quot;,&quot;COLUMN2&quot;, ETC) </li></ul></ul><ul><ul><li> INTO &quot;TABLENAME2&quot; VALUES (&quot;COLUMN3&quot;,&quot;COLUMN4&quot;,ETC) </li></ul></ul><ul><ul><li>SELECT &quot;COLUMN1&quot;,&quot;COLUMN2&quot;,COLUMN3&quot;,&quot;COLUMN4&quot; FROM &quot;TABLENAME3&quot; </li></ul></ul><ul><ul><li>WHERE [CONDITION] </li></ul></ul><ul><ul><li>CONDITIONAL INSERT ALL: </li></ul></ul><ul><ul><li>INSERT ALL </li></ul></ul><ul><ul><li>WHEN “COLUMN3” = <EXPRESSION1> THEN </li></ul></ul><ul><ul><li>INTO &quot;TABLENAME1&quot; VALUES (&quot;COLUMN1&quot;,&quot;COLUMN2&quot;, ETC) </li></ul></ul><ul><ul><li>ELSE </li></ul></ul><ul><ul><li>INTO &quot;TABLENAME2&quot; VALUES (&quot;COLUMN3&quot;,&quot;COLUMN4&quot;,ETC) </li></ul></ul><ul><ul><li>SELECT &quot;COLUMN1&quot;,&quot;COLUMN2&quot;,COLUMN3&quot;,&quot;COLUMN4&quot; FROM &quot;TABLENAME3&quot; </li></ul></ul><ul><ul><li>WHERE [CONDITION] </li></ul></ul>
  12. 12. SQL - Structured Query Language <ul><ul><li>Inserting into a Table (cont.) </li></ul></ul><ul><ul><li>UN-CONDITIONAL INSERT FIRST : </li></ul></ul><ul><ul><li>INSERT FIRST INTO &quot;TABLENAME1&quot; VALUES (&quot;COLUMN1&quot;,&quot;COLUMN2&quot;, ETC) </li></ul></ul><ul><ul><li> INTO &quot;TABLENAME2&quot; VALUES (&quot;COLUMN3&quot;,&quot;COLUMN4&quot;,ETC) </li></ul></ul><ul><ul><li>SELECT &quot;COLUMN1&quot;,&quot;COLUMN2&quot;,COLUMN3&quot;,&quot;COLUMN4&quot; FROM &quot;TABLENAME3&quot; </li></ul></ul><ul><ul><li>WHERE [CONDITION] </li></ul></ul><ul><ul><li>CONDITIONAL INSERT FIRST : </li></ul></ul><ul><ul><li>INSERT FIRST </li></ul></ul><ul><ul><li>WHEN “COLUMN3” = <EXPRESSION1> THEN </li></ul></ul><ul><ul><li>INTO &quot;TABLENAME1&quot; VALUES (&quot;COLUMN1&quot;,&quot;COLUMN2&quot;, ETC) </li></ul></ul><ul><ul><li>WHEN “COLUMN4” = <EXPRESSION2> THEN </li></ul></ul><ul><ul><li>INTO &quot;TABLENAME2&quot; VALUES (&quot;COLUMN3&quot;,&quot;COLUMN4&quot;,ETC) </li></ul></ul><ul><ul><li>SELECT &quot;COLUMN1&quot;,&quot;COLUMN2&quot;,COLUMN3&quot;,&quot;COLUMN4&quot; FROM &quot;TABLENAME3&quot; </li></ul></ul><ul><ul><li>WHERE [CONDITION] </li></ul></ul><ul><ul><li>INSERT WITH SUBQUERY: </li></ul></ul><ul><ul><li>INSERT /*+ APPEND */ INTO (SELECT “COLUMN1” FROM “TABLENAME1” </li></ul></ul><ul><ul><li>WHERE “CONDITION”) VALUES (“VALUE1”) | SELECT “COLUMN2” FROM “TABLENAME2” </li></ul></ul>
  13. 13. SQL - Structured Query Language <ul><ul><li>UPDATING INTO A TABLE: </li></ul></ul><ul><ul><li>UPDATE “TABLENAME | SUBQUERY” [WITH {READ ONLY | CHECK OPTION </li></ul></ul><ul><ul><li>CONSTRAINT “CONSTRAINTNAME”] SET ( “ COLUMNNAME1”, </li></ul></ul><ul><ul><li>” COLUMNNAME2 ”, ETC ) = (“VALUE | EXPRESSION |SUBQUERY”) [WHERE </li></ul></ul><ul><ul><li>CONDITION] [ RETURNING (COLUMN1, EXPRESSION, ETC.) INTO :VAR1, :VAR2, ETC] </li></ul></ul><ul><ul><li>UPDATE WITH SET VALUE: </li></ul></ul><ul><ul><li>UPDATE “TABLE1 P” SET VALUE(P) = (SELECT VALUE(Q) FROM “TABLE2 Q” </li></ul></ul><ul><ul><li>WHERE P.COLUMN1 = Q.COLUMN2) WHERE P.COLUMN1 = “VALUE | </li></ul></ul><ul><ul><li>EXPRESSION | SUBQUERY”; </li></ul></ul><ul><ul><li>DELETING FROM A TABLE </li></ul></ul><ul><ul><li>DELETE [FROM] “TABLENAME | SUBQUERY [WITH CHECK OPTION]” [WHERE </li></ul></ul><ul><ul><li>“ CONDITION”] [RETURNING (COLUMN1, EXPRESSION, ETC.) INTO :VAR1, :VAR2, ETC] </li></ul></ul><ul><ul><li>TRUNCATE TABLE “TABLENAME”; </li></ul></ul><ul><ul><li>DROP TABLE “TABLENAME” [CASCADE CONSTRAINTS] </li></ul></ul><ul><ul><li> Note: These are DDL Statements. </li></ul></ul>
  14. 14. SQL – Data Definition Language <ul><ul><li>CREATE TABLE </li></ul></ul><ul><ul><li>CREATE TABLE “TABLENAME” (“COLUMN1” “DATATYPE1” [“CONSTRAINT </li></ul></ul><ul><ul><li>CLAUSE”], “COLUMN2” “DATATYPE2” [“CONSTRAINT CLAUSE”], ETC .., </li></ul></ul><ul><ul><li>“ TABLE_CONSTRAINT_CLAUSE”); </li></ul></ul><ul><ul><li>CREATE TABLE “TABLE1” AS SELECT “COLUMN1, ..” FROM “TABLE2” [WHERE “CONDITION”]; </li></ul></ul><ul><ul><li>ALTER TABLE </li></ul></ul><ul><ul><li>ALTER TABLE “TABLENAME” MODIFY “COLUMN1 DATATYPE”; </li></ul></ul><ul><ul><li>ALTER TABLE “TABLENAME” ADD (“COLUMN1 DATATYPE” “CONSTRAINT </li></ul></ul><ul><ul><li>CLAUSE”, “COLUMN1 DATATYPE” “CONSTRAINT CLAUSE”, ETC); </li></ul></ul><ul><ul><li>ALTER TABLE “TABLENAME” DROP (“COLUMN1”, “COLUMN2”, ETC); </li></ul></ul><ul><ul><li>ALTER TABLE “TABLENAME” SET UNUSED (“COLUMN1”, “COLUMN2”, ETC); </li></ul></ul><ul><ul><li>ALTER TABLE “TABLENAME” SET UNUSED COLUMN “COLUMN1”; </li></ul></ul><ul><ul><li>ALTER TABLE “TABLENAME” DROP UNUSED COLUMNS; </li></ul></ul><ul><ul><li>ALTER TABLE “TABLENAME” DROP PRIMARY KEY [CASCADE]; </li></ul></ul><ul><ul><li>ALTER TABLE “TABLENAME” ADD CONSTRAINT “CONSTRAINT_NAME” “CONSTRAINT_CLAUSE” [ENABLE | DISABLE] [VALIDATE | NOVALIDATE]; </li></ul></ul><ul><ul><li>ALTER TABLE “TABLENAME” DROP CONSTRAINT “CONSTRAINT_NAME”; </li></ul></ul><ul><ul><li>ALTER TABLE “TABLENAME” MODIFY CONSTRAINT “CONSTRAINT_NAME” </li></ul></ul><ul><ul><li>[ENABLE | DISABLE] [VALIDATE | NOVALIDATE]; </li></ul></ul>
  15. 15. SQL – Constraints <ul><ul><li>CONSTRAINTS </li></ul></ul><ul><ul><li>Oracle uses integrity constraints to prevent invalid data entry into the base </li></ul></ul><ul><ul><li>tables of the database. You can define integrity constraints to enforce the </li></ul></ul><ul><ul><li>business rules you want to associate with the information in a database. If any </li></ul></ul><ul><ul><li>of the results of a DML statement execution violate an integrity constraint, </li></ul></ul><ul><ul><li>then oracle rolls back the statement and returns an error. </li></ul></ul><ul><ul><li>TYPES OF INTEGRITY CONSTRAINTS </li></ul></ul><ul><ul><ul><li>NOT NULL Integrity Constraints </li></ul></ul></ul><ul><ul><ul><li>UNIQUE Key Integrity Constraints </li></ul></ul></ul><ul><ul><ul><li>PRIMARY KEY Integrity Constraints </li></ul></ul></ul><ul><ul><ul><li>REFERENTIAL Integrity Constraints </li></ul></ul></ul><ul><ul><ul><li>CHECK Integrity Constraints </li></ul></ul></ul>
  16. 16. SQL – Indexes <ul><ul><li>INDEXES </li></ul></ul><ul><ul><li>The impetus to index data arises because of the need to locate specific info </li></ul></ul><ul><ul><li>and then to retrieve it as efficiently as possible since it is not possible to keep </li></ul></ul><ul><ul><li>the entire set of data into the memory, and since disk access times are much </li></ul></ul><ul><ul><li>slower than main memory access times, indexing plays important role. </li></ul></ul><ul><ul><li>TYPES OF INDEXES </li></ul></ul><ul><ul><ul><li>B-TREE INDEX </li></ul></ul></ul><ul><ul><ul><ul><li>UNIQUE / NON-UNIQUE INDEX </li></ul></ul></ul></ul><ul><ul><ul><ul><li>REVERSE KEY </li></ul></ul></ul></ul><ul><ul><ul><ul><li>FUNCTION BASED INDEX </li></ul></ul></ul></ul><ul><ul><ul><li>BITMAP INDEX </li></ul></ul></ul><ul><ul><ul><ul><li>REVERSE KEY </li></ul></ul></ul></ul><ul><ul><li>CREATE [UNIQUE|BITMAP] INDEX “INDEXNAME” ON TABLE (“COLUMN1” | </li></ul></ul><ul><ul><li>“ EXPRESSION” [ASC | DESC]) [NOSORT|REVERSE]; </li></ul></ul><ul><ul><li>ALTER INDEX “INDEXNAME” RENAME TO “NEW_INDEX_NAME”; </li></ul></ul><ul><ul><li>DROP INDEX “INDEXNAME”; </li></ul></ul>
  17. 17. SQL - Structured Query Language (cont) <ul><ul><li>Types of OPERATORS </li></ul></ul><ul><ul><ul><li>SET : UNION, UNION ALL, INTERSECT, MINUS </li></ul></ul></ul><ul><ul><ul><li>EQUALITY: <,>,<=,>=,!=,<>,^= </li></ul></ul></ul><ul><ul><ul><li>LIKE with % and _ </li></ul></ul></ul><ul><ul><ul><li>IN </li></ul></ul></ul><ul><ul><ul><li>ANY </li></ul></ul></ul><ul><ul><ul><li>ALL </li></ul></ul></ul><ul><ul><ul><li>EXISTS </li></ul></ul></ul><ul><ul><ul><li>BETWEEN </li></ul></ul></ul><ul><ul><li>Aggregate Functions </li></ul></ul><ul><li>- MIN </li></ul><ul><li>MAX </li></ul><ul><li>SUM </li></ul><ul><li>AVG </li></ul><ul><li>COUNT(“COLUMNNAME”) </li></ul><ul><li>COUNT(*) </li></ul>
  18. 18. Oracle Built-In Functions <ul><li>|| or CONCAT ('STRING1','STRING2') - Concatenate two strings together. </li></ul><ul><li>ASCII('CHR | STRING') - Returns the decimal representation in the database characterset of the fist character of the string </li></ul><ul><li>CHR(NUMBER) - Returns the character having the binary equivalent to the string in either database character set or national character set </li></ul><ul><li>INITCAP('STRING1') - Initial Capital </li></ul><ul><li>INSTR('STRING1','CHR | STRING2', FROMLOCATION1, OCCURENCE) - finds the location of of a character in a string </li></ul><ul><li>LENGTH('STRING1') - Returns the length of a string </li></ul><ul><li>LOWER('STRING1') - Converts every letter in a string to lowercase. </li></ul><ul><li>LPAD('STRING1',LENGTH,'CHR || STRING2') - Left pad. </li></ul><ul><li>LTRIM('STRING1','SET1') - Left Trim </li></ul><ul><li>RPAD('STRING1',LENGTH,'CHR || STRING2') - Right PAD </li></ul><ul><li>RTRIM('STRING1','SET1') - Right Trim </li></ul><ul><li>SOUNDEX('STRING1') - Finds words that sound like the example specified </li></ul><ul><li>SUBSTR('STRING1',FROM1,COUNT) - Substring. </li></ul><ul><li>TRIM('STRING1','SET1') - All trim </li></ul><ul><li>UPPER('STRING1') - Converts every letter in a string to uppercase. </li></ul>String Function:
  19. 19. Oracle Built-In Functions <ul><li>Single Value Function- </li></ul><ul><ul><li>ABS(NUMBER1) - Returns ABSolute value of the number. </li></ul></ul><ul><ul><li>CEIL(NUMBER1) - Produces smallest integer greater than specified. </li></ul></ul><ul><ul><li>FLOOR(NUMBER1) - Produces smallest integer lesser than specified. </li></ul></ul><ul><ul><li>MOD(NUMBER1,DIVISOR1) - Returns modulus of the number. </li></ul></ul><ul><ul><li>NVL(NUMBER1,SUBSTITUTE) - Returns Sub value if specified value is null </li></ul></ul><ul><ul><li>POWER(NUMBER1,EXPONENT) - Number raised to exponent power </li></ul></ul><ul><ul><li>ROUND(NUMBER1,PRECISION) - Rounds to the next value (if greater than 0.49) </li></ul></ul><ul><ul><li>SIGN(NUMBER1) - Returns 1, -1 or 0 depending upon the sign. </li></ul></ul><ul><ul><li>SQRT(NUMBER1) - Returns square root of the value </li></ul></ul><ul><ul><li>TRUNC(NUMBER1,PRECISION) - Rounds to lower value </li></ul></ul><ul><ul><li>VSIZE(NUMBER1 | CHAR | BLOB) - Returns storage size in oracle </li></ul></ul><ul><li>List Functions - </li></ul><ul><ul><li>COALESCE(VALUE1,VALUE2,...) - Returns first not-NULL value in list </li></ul></ul><ul><ul><li>GREATEST(VALUE1,VALUE2,...) - Functions like MAX in list </li></ul></ul><ul><ul><li>LEAST(VALUE1,VALUE2,...) - Functions like MIN in list </li></ul></ul>Number Functions:
  20. 20. Oracle Built-In Functions <ul><li>ADD_MONTH(DATE, N) - Adds N months in date specified. </li></ul><ul><li>CURRENT_TIMESTAMP - Returns current timestamp with active timezone </li></ul><ul><li>DBTIMEZONE - Returns current database zone </li></ul><ul><li>EXTRACT(timeunit FROM datatime) - Extract a portion of date </li></ul><ul><li>GREATEST(VALUE1,VALUE2,...) - Functions like MAX in list </li></ul><ul><li>LEAST(VALUE1,VALUE2,...) - Functions like MIN in list </li></ul><ul><li>LAST_DAY(date) - Gives last day of the month </li></ul><ul><li>MONTHS_BETWEEN(date2,date1) - Gives date2 - date 1 in months (fractional) </li></ul><ul><li>NEXT_DAY(Date,‘Day') - Gives date of next day. </li></ul><ul><li>TO_DATE('STRING1','FORMAT') - Converts string to date in given valid format. </li></ul>Date Functions:
  21. 21. Oracle Built-In Functions <ul><li>DECODE(VALUE,IF,THEN,IF, THEN,… ELSE) – Decodes a CHAR, VARCHAR2 or NUMBER into any of several different character strings or Numbers based on value. </li></ul><ul><li>TO_CHAR(NUMBER1) – Converts Number to character </li></ul><ul><li>TO_NUMBER(‘STRING1’) – Converts string to number </li></ul><ul><li>TRANSLATE(‘STRING1’,IF,THEN) – Does an orderly char-to-char substitution in a string. </li></ul>Conversion and Transformation Functions:
  22. 22. Grouping Data Together <ul><li>Types of Joins </li></ul><ul><ul><li>INNER JOIN : An inner join (sometimes called a &quot;simple join&quot;) is a join of two or more tables that returns only those rows that satisfy the join condition. </li></ul></ul><ul><ul><li>OUTER JOIN: An outer join extends the result of a simple join. An outer join returns all rows that satisfy the join condition and also returns some or all of those rows from one table for which no rows from the other satisfy the join condition. </li></ul></ul><ul><ul><ul><li>NATURAL JOIN : A natural join is based on all columns in the two tables that have the same name </li></ul></ul></ul><ul><ul><ul><li>LEFT OUTER JOIN – Taking all records from the left table </li></ul></ul></ul><ul><ul><ul><li>RIGHT OUTER JOIN - Taking all records from the right table </li></ul></ul></ul><ul><ul><li> What is Cartesian Product ? </li></ul></ul>
  23. 23. Grouping Data Together (contd.) <ul><li>CORRELATED SUBQUERIES - Oracle performs a correlated subquery when the subquery references a column from a table referred to in the parent statement. A correlated subquery is evaluated once for each row processed by the parent statement. The parent statement can be a SELECT, UPDATE, or DELETE statement. </li></ul><ul><li>GROUP BY EXTENSION - </li></ul><ul><li>ROLLUP </li></ul><ul><li>CUBE </li></ul><ul><li>GROUPING </li></ul>
  24. 24. Other Database Objects <ul><li>VIEWS – View is a filtered information from table(s). </li></ul><ul><ul><li>Simple View </li></ul></ul><ul><ul><ul><li>Read-only </li></ul></ul></ul><ul><ul><ul><li>Updateable </li></ul></ul></ul><ul><ul><ul><ul><li>With Check Option </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Without Check Option </li></ul></ul></ul></ul><ul><ul><li>Complex View </li></ul></ul><ul><ul><ul><li>Read-only </li></ul></ul></ul>CREATE VIEW “NAME” AS “QUERY” [WITH READ ONLY | WITH CHECK OPTION]; DATABASE LINK - A named schema object that describes a path from one database to another. Database links are implicitly used when a reference is made to a global object name in a distributed database. CREATE [SHARED][PUBLIC] DATABASE LINK “LINK_NAME” [CONNECT TO CURRENT_USER] [USING 'CONNECT_STRING'] CREATE [SHARED][PUBLIC] DATABASE LINK “LINK_NAME” [CONNECT TO “ USER” IDENTIFIED BY “PASSWORD”] [AUTHENTICATED BY “USER” IDENTIFIED BY “PASSWORD”] [USING 'CONNECT_STRING'] .
  25. 25. Other Database Objects <ul><li>SEQUENCE – A database object from which multiple users may generate unique </li></ul><ul><li>integers. </li></ul><ul><li>CREATE SEQUENCE “SEQUENCE_NAME” [INCREMENT BY int ] </li></ul><ul><li>[START WITH int] [MAXVALUE int | NOMAXVALUE] [MINVALUE int | </li></ul><ul><li>NOMINVALUE] [CYCLE | NOCYCLE] [CACHE int | NOCACHE] [ORDER | </li></ul><ul><li>NOORDER ] </li></ul>SYNONYM – A synonym is an alias for a table, view, sequence, or program unit. A synonym is not actually a schema object itself, but instead is a direct reference to a schema object. CREATE [PUBLIC] SYNONYM “SYNONYM_NAME” FOR “OBJECT” [@DBLINK]
  26. 26. Oracle Text <ul><li>What is Oracle Text? </li></ul><ul><li>Oracle Text is a tool that enables you to build text query applications. Oracle Text provides indexing, word and theme searching, and viewing capabilities for text. </li></ul>Text Query Applications The purpose of a text query application is to enable users to find text that contains one or more search terms. The text is usually a collection of documents. A good application can index and search common document formats such as HTML, XML, plain text, or Microsoft Word. For example, an application with a browser interface might enable users to query a company website consisting of HTML files, returning those files that match a query. CREATE TABLE “TABLE_NAME” (&quot;COLUMN_NAME&quot; BLOB NOT NULL, .. ETC) LOB(&quot;COLUMN_NAME“, …. ) STORE AS “LOB_NAME” ( STORAGE ( MAXEXTENTS UNLIMITED) ENABLE | DISABLE STORAGE IN ROW CHUNK 2K PCTVERSION 10 [CACHE READS | NOCACHE LOGGING | NOLOGGING]) TABLESPACE “TABLESPACE_NAME” <ul><li>Loading Your Text Table </li></ul><ul><li>Text information (can be documents or text fragments) </li></ul><ul><li>Path names of documents in your file system </li></ul><ul><li>URLs that specify World Wide Web documents </li></ul>
  27. 27. Oracle Text (CONTD.) Indexing documents To query your document collection, you must first index the text column of your text table. Indexing breaks your text into tokens, which are usually words separated by spaces. <ul><li>Type of Index </li></ul><ul><li>Oracle Text supports the creation of three types of indexes depending on your </li></ul><ul><li>application and text source. </li></ul><ul><ul><li>CONTEXT </li></ul></ul><ul><ul><li>CTXCAT </li></ul></ul><ul><ul><li>CTXRULE </li></ul></ul>CREATE INDEX “INDEX” ON “TABLE”(“BLOB_COLUMN”) INDEXTYPE IS CTXSYS.CONTEXT PARAMETERS ('DATASTORE CTXSYS.DEFAULT_DATASTORE FILTER CTXSYS.NULL_FILTER SECTION GROUP CTXSYS.HTML_SECTION_GROUP'); CREATE INDEX AUCTION_TITLEX ON AUCTION(TITLE) INDEXTYPE IS CTXCAT PARAMETERS ('INDEX SET AUCTION_ISET'); CREATE INDEX ON MYQUERIES(QUERY) INDEXTYPE IS CTXRULE PARAMETERS('LEXER LEXER_PREF STORAGE STORAGE_PREF SECTION GROUP SECTION_PREF WORDLIST WORDLIST_PREF');
  28. 28. PL/SQL <ul><ul><li>What is PL/SQL ? </li></ul></ul><ul><ul><li>PL/SQL is a procedural language that Oracle developed as an extension to standard SQL to provide a way to execute procedural logic on the database. </li></ul></ul><ul><ul><li>Why Learn PL/SQL? </li></ul></ul><ul><ul><li>Regardless of the front-end tool that you are using, you can use PL/SQL to perform processing on the server rather than the client. You can use PL/SQL to encapsulate business rules and other complicated logic. It provides for modularity and abstraction. You can use it in database triggers to code complex constraints, which enforce database integrity; to log changes; and to replicate data. PL/SQL can also be used with stored procedures and functions to provide enhanced database security. Finally, it provides you with a level of platform independence. Oracle is implemented on many hardware platforms, but PL/SQL is the same on all of them. It makes no difference whether you are running Personal Oracle on a laptop or Oracle8i Enterprise on UNIX. </li></ul></ul>
  29. 29. PL/SQL (contd.) <ul><ul><li>PL/SQL Is Block Structured </li></ul></ul><ul><ul><li>DECLARE </li></ul></ul><ul><ul><li>variable_declarations </li></ul></ul><ul><ul><li>BEGIN </li></ul></ul><ul><ul><li>program_code </li></ul></ul><ul><ul><li>EXCEPTION exception_handlers </li></ul></ul><ul><ul><li>END; </li></ul></ul><ul><ul><li>What About Some Output? </li></ul></ul>
  30. 30. PL/SQL (contd.) <ul><ul><li>Variable declarations </li></ul></ul><ul><ul><li>Variable_name [CONSTANT] data_type [NOT NULL] [:= (or DEFAULT) value]; </li></ul></ul><ul><ul><li>All declarations must be made in the declaration section of the block. </li></ul></ul><ul><ul><li>Variable Scopes: Block structure rule </li></ul></ul><ul><ul><li>%TYPE </li></ul></ul><ul><ul><li><var-name> <obj>%type [not null][:= <init-val>]; </li></ul></ul><ul><ul><li>E.g. name Books.title%type;   /*  name is defined as the same type as column 'title' of table  Books*/ </li></ul></ul><ul><ul><li>comm number(5,2) := 12.5; x comm%type; --  x is defined as the same type as variable comm </li></ul></ul><ul><ul><li>User-defined subtypes </li></ul></ul><ul><ul><li>SUBTYPE new_type IS original_type ; </li></ul></ul><ul><ul><li>Example: SUBTYPE num IS NUMBER ; -- NUMBER(4) not allowed (constraint) </li></ul></ul><ul><ul><li>mynum num; -- num is a user-defined type name (number) </li></ul></ul><ul><ul><li>SUBTYPE nametype IS customer.fname%TYPE; </li></ul></ul>
  31. 31. PL/SQL Control Structure <ul><ul><li>CONDITIONAL IF-THEN_ELSE STATEMENT: </li></ul></ul><ul><ul><li>IF condition1 THEN </li></ul></ul><ul><ul><li>sequence_of_statements1 </li></ul></ul><ul><ul><li>ELSIF condition2 THEN </li></ul></ul><ul><ul><li>sequence_of_statements2 </li></ul></ul><ul><ul><li>ELSE </li></ul></ul><ul><ul><li>sequence_of_statements3 </li></ul></ul><ul><ul><li>END IF; </li></ul></ul>
  32. 32. PL/SQL Control Structure (contd.) <ul><ul><li>CASE STATEMENT: </li></ul></ul><ul><ul><li>CASE SELECTOR </li></ul></ul><ul><ul><li>WHEN EXPRESSION1 THEN SEQUENCE_OF_STATEMENTS1; </li></ul></ul><ul><ul><li> WHEN EXPRESSION2 THEN SEQUENCE_OF_STATEMENTS2; ... WHEN EXPRESSIONN THEN SEQUENCE_OF_STATEMENTSN; [ELSE SEQUENCE_OF_STATEMENTSN+1;] </li></ul></ul><ul><ul><li>END CASE; </li></ul></ul><ul><ul><li>SELECT CASE “COLUMN_NAME” WHEN “VALUE1” THEN “VALUE2” </li></ul></ul><ul><ul><li>ELSE “VALUE3” </li></ul></ul><ul><ul><li>END </li></ul></ul><ul><ul><li>FROM “TABLE_NAME”; </li></ul></ul>
  33. 33. PL/SQL Control Structure (contd.) <ul><ul><li>ITERATIVE CONTROL: LOOP AND EXIT STATEMENTS: </li></ul></ul><ul><ul><li>LOOP ... </li></ul></ul><ul><ul><li>IF CONDITIONS1 THEN ... </li></ul></ul><ul><ul><li>EXIT; -- exit loop immediately </li></ul></ul><ul><ul><li>-- EXIT WHEN CONDITION2; </li></ul></ul><ul><ul><li>END IF; </li></ul></ul><ul><ul><li>END LOOP; </li></ul></ul><ul><ul><li><<outer>> </li></ul></ul><ul><ul><li>LOOP ... </li></ul></ul><ul><ul><li>LOOP ... </li></ul></ul><ul><ul><li>EXIT outer WHEN ... -- exit both loops </li></ul></ul><ul><ul><li>END LOOP; ... </li></ul></ul><ul><ul><li>END LOOP outer; </li></ul></ul>
  34. 34. PL/SQL Control Structure (contd.) <ul><ul><li>ITERATIVE CONTROL: LOOP AND EXIT STATEMENTS: </li></ul></ul><ul><ul><li>While Loop: </li></ul></ul><ul><ul><li>WHILE condition LOOP </li></ul></ul><ul><ul><li>sequence_of_statements </li></ul></ul><ul><ul><li>END LOOP; </li></ul></ul><ul><ul><li>FOR counter IN [REVERSE] lower_bound..higher_bound LOOP sequence_of_statements </li></ul></ul><ul><ul><li>END LOOP; </li></ul></ul><ul><ul><li>SEQUENTIAL CONTROL: GOTO AND NULL STATEMENTS </li></ul></ul>
  35. 35. Introduction of Cursors <ul><ul><li>PL/SQL uses two types of cursors: implicit and explicit . PL/SQL declares a cursor implicitly for all SQL data manipulation statements, including queries that return only one row. However, for queries that return more than one row, you must declare an explicit cursor, use a cursor FOR loop, or use the BULK COLLECT clause. </li></ul></ul><ul><ul><li>CURSOR CURSOR_NAME [(PARAMETER[, PARAMETER]...)] [RETURN RETURN_TYPE] IS SELECT_STATEMENT; </li></ul></ul><ul><ul><li>PARAMETER = cursor_parameter_name [IN] datatype [{:= | DEFAULT} expression] </li></ul></ul><ul><ul><li>OPENING A CURSOR: </li></ul></ul><ul><ul><li>OPEN CURSOR_NAME [(parameter1, parameter2…)]; </li></ul></ul><ul><ul><li>FETCHING WITH A CURSOR: </li></ul></ul><ul><ul><li>LOOP </li></ul></ul><ul><ul><li>FETCH CURSOR_NAME INTO VARIABLE1; </li></ul></ul><ul><ul><li>EXIT WHEN CURSOR_NAME%NOTFOUND; </li></ul></ul><ul><ul><li>-- process data record </li></ul></ul><ul><ul><li>END LOOP; </li></ul></ul>
  36. 36. Introduction of Cursors (contd.) <ul><ul><li>USING CURSOR FOR LOOPS: </li></ul></ul><ul><ul><li>DECLARE RESULT TEMP.COL1%TYPE; </li></ul></ul><ul><ul><li>CURSOR C1 IS SELECT N1, N2, FROM DATA_TABLE WHERE EXPER_NUM = 1; BEGIN </li></ul></ul><ul><ul><li>FOR C1_REC IN C1 LOOP </li></ul></ul><ul><ul><li>/* CALCULATE AND STORE THE RESULTS */ </li></ul></ul><ul><ul><li>RESULT := C1_REC.N2 / (C1_REC.N1 + C1_REC.N1); </li></ul></ul><ul><ul><li>INSERT INTO TEMP VALUES (RESULT, NULL, NULL); </li></ul></ul><ul><ul><li>END LOOP; </li></ul></ul><ul><ul><li>COMMIT; </li></ul></ul><ul><ul><li>END; </li></ul></ul>WHAT IS REF CURSORS?
  37. 37. Subprograms <ul><ul><li>What Are Subprograms? </li></ul></ul><ul><ul><li>Subprograms are named PL/SQL blocks that can take parameters and be invoked. PL/SQL has two types of subprograms called procedures and functions. </li></ul></ul><ul><ul><li>Subprograms have a declarative part, an executable part, and an optional exception-handling part. The declarative part contains declarations of types, cursors, constants, variables, exceptions, and nested subprograms. These objects are local and cease to exist when you exit the subprogram. The executable part contains statements that assign values, control execution, and manipulate ORACLE data. The exception-handling part contains exception handlers, which deal with exceptions raised during execution. </li></ul></ul>
  38. 38. Subprograms - Procedures <ul><ul><li>A procedure is a subprogram that computes a value, and returns one or more values. </li></ul></ul><ul><ul><li>[CREATE [OR REPLACE]] PROCEDURE PROCEDURE_NAME[(PARAMETER DATATYPE [NOCOPY] [IN|OUT |INOUT][, PARAMETER DATATYPE [IN|OUT |INOUT]]...)] [AUTHID CURRENT_USER | AUTHID DEFINER ] </li></ul></ul><ul><ul><li>{IS | AS} </li></ul></ul><ul><ul><li>[PRAGMA AUTONOMOUS_TRANSACTION;] [LOCAL DECLARATIONS] </li></ul></ul><ul><ul><li>BEGIN </li></ul></ul><ul><ul><li>EXECUTABLE STATEMENTS </li></ul></ul><ul><ul><li>[EXCEPTION EXCEPTION HANDLERS] </li></ul></ul><ul><ul><li>END [PROCEDURE_NAME]; </li></ul></ul>
  39. 39. Subprograms - Functions <ul><ul><li>A function is a subprogram that computes a value. Inside the function body, the RETURN statement is used to return control to the caller with a value. </li></ul></ul><ul><ul><li>[CREATE [OR REPLACE]] FUNCTION FUNCTION_NAME[(PARAMETER DATATYPE[, PARAMETER DATATYPE]...)] RETURN DATATYPE} {IS | AS} [PRAGMA AUTONOMOUS_TRANSACTION;] [LOCAL DECLARATIONS] </li></ul></ul><ul><ul><li>BEGIN </li></ul></ul><ul><ul><li>EXECUTABLE STATEMENTS </li></ul></ul><ul><ul><li>[EXCEPTION EXCEPTION HANDLERS] </li></ul></ul><ul><ul><li>END [FUNCTION_NAME]; </li></ul></ul>
  40. 40. Packages <ul><ul><li>What are Packages? </li></ul></ul><ul><ul><li>Packages are PL/SQL constructs that allow related objects to be stored together. </li></ul></ul><ul><ul><li>What are the advantages? </li></ul></ul><ul><ul><li>Enforced information hiding, Object-Oriented design, Object persistence, Performance improvement, Less restrictive on dependency </li></ul></ul><ul><ul><ul><li>A package has two separate parts : specification and body. Each of them is stored separately. </li></ul></ul></ul><ul><ul><ul><li>A package can only be stored </li></ul></ul></ul><ul><ul><ul><li>Package Specification </li></ul></ul></ul><ul><ul><ul><li>It contains information about the contents of the package, NOT the code itself. </li></ul></ul></ul><ul><ul><ul><li>CREATE [OR REPLACE] PACKAGE PACKAGE_NAME {IS|AS} -- NO PARAMETERS </li></ul></ul></ul><ul><ul><ul><li>PROCEDURE_SPECIFICATION | FUNCTION_SPECIFICATION | VARIABLE_DECLARATION | TYPE_DEFINITION | </li></ul></ul></ul><ul><ul><ul><li>EXCEPTION_DECLARATION | CURSOR_DECLARATION </li></ul></ul></ul><ul><ul><ul><li>END [PACKAGE_NAME]; </li></ul></ul></ul>
  41. 41. Packages (contd.) <ul><ul><ul><li>Package Body </li></ul></ul></ul><ul><ul><ul><li>It contains the actual code for the forward subprogram declarations in the package header -- so it can not be compiled without the header. </li></ul></ul></ul><ul><ul><ul><li>Package body is optional (if no procedure or function defined in the header) </li></ul></ul></ul><ul><ul><ul><li>The specification for the procedure or function must be the same in both. </li></ul></ul></ul><ul><ul><ul><li>CREATE OR REPLACE PACKAGE BODY PACKAGE_NAME {IS|AS} </li></ul></ul></ul><ul><ul><ul><li>... </li></ul></ul></ul><ul><ul><ul><li>[BEGIN] </li></ul></ul></ul><ul><ul><ul><li>... – Provide code for the subprograms. </li></ul></ul></ul><ul><ul><ul><li>END [PACKAGE_NAME]; </li></ul></ul></ul><ul><ul><ul><li>Packages and Scope </li></ul></ul></ul><ul><ul><ul><li>Any object declared in a package header is in scope and is visible outside the package. This may be useful for declaring global variables, and can be accessed by qualifying the object with the package name. E.g. DBMS_OUTPUT.PUT_LINE('hello'); </li></ul></ul></ul><ul><ul><ul><li>The procedure call is the same as it would be for a stand-alone procedure. </li></ul></ul></ul>
  42. 42. Packages (contd.) <ul><ul><ul><li>Packages and Dependencies </li></ul></ul></ul><ul><ul><ul><li>The package body depends on the header and referenced tables </li></ul></ul></ul><ul><ul><ul><li>The package header does not depend on anything (this is the advantage!) -- we can change the package body without changing the header. </li></ul></ul></ul><ul><ul><ul><li>If the header is changed, this automatically invalidates the body. </li></ul></ul></ul>
  43. 43. Triggers <ul><ul><ul><li>What are triggers? </li></ul></ul></ul><ul><ul><ul><li>A trigger defines an action the database should take when some database-related event (such as inserts, updates, deletes) occurs. </li></ul></ul></ul><ul><ul><ul><li>Triggers are similar to procedures, in that they are named PL/SQL blocks. </li></ul></ul></ul><ul><ul><ul><li>Differences between Procedures and Triggers: A procedure is executed explicitly from another block via a procedure call with passing arguments, while a trigger is executed (or fired) implicitly whenever the triggering event (DML: INSERT, UPDATE, or DELETE) happens, and a trigger doesn't accept arguments. </li></ul></ul></ul><ul><ul><ul><li>When triggers are used? </li></ul></ul></ul><ul><ul><ul><li>Auditing information in a table by recording the changes </li></ul></ul></ul><ul><ul><ul><li>Automatically signaling other programs that action needs to take place when changes are made to a table </li></ul></ul></ul><ul><ul><ul><li>Enforcing complex business rules </li></ul></ul></ul>
  44. 44. Triggers (contd.) <ul><ul><ul><li>TYPES OF TRIGGERS: </li></ul></ul></ul><ul><ul><ul><li>Row-level triggers </li></ul></ul></ul><ul><ul><ul><li>Row-level triggers execute once for each row in a transaction. </li></ul></ul></ul><ul><ul><ul><li>Row-level triggers are the most common type of triggers; they are often used in data auditing applications. </li></ul></ul></ul><ul><ul><ul><li>Row-level trigger is identified by the FOR EACH ROW clause in the CREATE TRIGGER command. </li></ul></ul></ul><ul><ul><li>Statement-level triggers </li></ul></ul><ul><ul><li>Statement-level triggers execute once for each transaction. </li></ul></ul><ul><ul><li>Statement-level triggers are the default type of triggers created and are identified by omitting the FOR EACH ROW clause in the CREATE TRIGGER command. </li></ul></ul><ul><li>Before and After Triggers </li></ul><ul><ul><li>Since triggers occur because of events, they may be set to occur immediately before or after those events. The events that execute triggers are database transactions, triggers can be executed immediately BEFORE or AFTER the statements INSERTs, UPDATEs, DELETEs. </li></ul></ul><ul><ul><li>AFTER row-level triggers are frequently used in auditing applications, since they do not fire until the row has been modified. </li></ul></ul>
  45. 45. Triggers (contd.) <ul><ul><ul><li>CREATE [OR REPLACE] TRIGGER “TRIGGER_NAME” {BEFORE EVENT | AFTER EVENT | INSTEAD OF EVENT} [FOR EACH ROW] WHEN (CONDITION) PL_SQL_BLOCK </li></ul></ul></ul><ul><ul><ul><li>EVENT CAN BE ONE OR MORE OF THE FOLLOWING (SEPARATE MULTIPLE EVENTS WITH OR) </li></ul></ul></ul><ul><ul><ul><li>DELETE EVENT_REF </li></ul></ul></ul><ul><ul><ul><li>INSERT EVENT_REF </li></ul></ul></ul><ul><ul><ul><li>UPDATE EVENT_REF </li></ul></ul></ul><ul><ul><ul><li>UPDATE OF COLUMN, COLUMN... EVENT_REF </li></ul></ul></ul><ul><ul><ul><li>DDL_STATEMENT ON [SCHEMA.] {TABLE|VIEW} </li></ul></ul></ul><ul><ul><ul><li>DDL_STATEMENT ON DATABASE </li></ul></ul></ul><ul><ul><ul><li>SERVERERROR </li></ul></ul></ul><ul><ul><ul><li>LOGON </li></ul></ul></ul><ul><ul><ul><li>LOGOFF </li></ul></ul></ul><ul><ul><ul><li>STARTUP </li></ul></ul></ul><ul><ul><ul><li>SHUTDOWN </li></ul></ul></ul><ul><ul><ul><li>EVENT_REF: </li></ul></ul></ul><ul><ul><ul><li>ON [SCHEMA.]TABLE </li></ul></ul></ul><ul><ul><ul><li>ON [SCHEMA.]VIEW </li></ul></ul></ul>
  46. 46. Triggers (contd.) <ul><ul><ul><li>Using :old and :new in Row-level Triggers </li></ul></ul></ul><ul><ul><ul><li>A row-level trigger fires once per row processed by the triggering statement. Inside the trigger, you can access the row that is currently being processed through two pseudocodes -- :old and :new, e.g., :new.field or :old.field. However, they are not true records. </li></ul></ul></ul><ul><ul><ul><li>:old refers to the data as it existed prior to the transaction. Updates and Deletes usually reference :old values. The :new values are the data values that the transaction creates (such as the columns in an inserted record). </li></ul></ul></ul><ul><ul><ul><li>:old is undefined for INSERT statements, :new is undefined for DELETE statements. </li></ul></ul></ul><ul><ul><ul><li>If you need to set a column value in an inserted row via your trigger, then you will need to use a BEFORE INSERT trigger in order to access the :new values. Using an AFTER INSERT trigger would not allow you to set the inserted value, since the row will already have been inserted into the table (and thus be :old). </li></ul></ul></ul>What is mutating table?
  47. 47. QUESTIONS ?
  48. 48. Thank You ! The end of my presentation ... but there are many more features in Oracle 9i, will be used during practice. - Kamlesh Chaudhary