100% found this document useful (1 vote)
2K views

Oracle Complete Notes

The document provides an overview of the Oracle Complete Notes OCA Syllabus. It covers 25 topics that make up the syllabus including introduction to Oracle, creating and managing users, tables, permissions, views, indexes, constraints, sequences, procedures, functions, packages, cursors, triggers and more. It also includes examples of SQL commands for common tasks like creating users and tables, inserting and updating data, joining tables, and manipulating strings, dates and numbers.

Uploaded by

sathish706
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views

Oracle Complete Notes

The document provides an overview of the Oracle Complete Notes OCA Syllabus. It covers 25 topics that make up the syllabus including introduction to Oracle, creating and managing users, tables, permissions, views, indexes, constraints, sequences, procedures, functions, packages, cursors, triggers and more. It also includes examples of SQL commands for common tasks like creating users and tables, inserting and updating data, joining tables, and manipulating strings, dates and numbers.

Uploaded by

sathish706
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 61

ORACLE Complete Notes OCA Syllabus: 1) Introduction of Oracle 2) Create, Manage and Drop Users 3) Create, Manage and

Drop Tables 4) Distinct ,Wild cards and Sub Queries 5) Order By, Group By Clause 6) Set Functions or Set Operator 7) Joins (Inner / Outer / Left / Right) 8) String Functions 9) Date Functions 10) Math Functions and Numeric Functions 11) Create, Manage and Drop Permission Grant / Revoke 12) Create, Manage and Drop View 13) Create, Manage and Drop Index 14) Create, Manage and Drop Constraints 15) Create, Manage and Drop Synonyms 16) Create, Manage and Drop Sequence 17) Procedure Language - SQL (PL - SQL ) 18) Conditions and Loops 19) Exception Handling 20) Create, Manage and Drop Procedures 21) Create, Manage and Drop Functions 22) Create, Manage and Drop Package 23) Cursor 24) Trigger 25) SQL * Plus commands, Forms and Reports

1 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes Class: 1 (Theory) Introduction of Oracle: Developed by Oracle One of the Server Level Data Base Software Oracle all read by Table Format Oracle is not a case sensitive Oracle Database File is <Database Name>.SQL Types of Oracle: 1) SQL Structure Query Language 2) PL SQL Procedure Language and SQL 3) ISQL Internet Structure Query Language 4) SQL *Plus Advance SQL Commands Diagram of Data Base Mgt System Concept:
Application Server (Http server Run on this Machine)

SQL Data Base DBA


Http: //127.0.0.0.1/ www.localhost.com

U1

U2

U3

U4

U5

Http: //200.0.10.1/ www.southindia.com, www.12thresult.com, www.annuniv.com, www.Squarebrothers.com

Way to Open Oracle Software: Start All Programs Oracle Database 10 G Express Edition SQL Command Line Click Or Start Run sqlplus (Type) ok
2 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes Class: 2 (Theory) Create, Manage and Drop Users or Schemas: Diagram of Access Database with Schemas:

Oracle Data

App Server Run on This Machine


http://localhost:8080/htmldb

Scott Scott Tiger Tiger (Console) (Console)

System System Manager Manager (Windows) (Windows)

Karthik Karthik Hacker Hacker

Raj Raj Password Password

Default User Name and Password: User name system Password manager User name scott Password tiger How to Create New Schema or User Name with Password: Syntax: SQL> Create user <user name> Identified by <password > / externally/ globally [Default Tablespace <Table space1> Temporary Tablespace <Table space2> Quota unlimited on <Table space1> Quota 10MB on <Table space3> Password Expire Account Lock/ Unlock]; O/P: User created Eg: SQL> Create User Karthik identified by Hacker; O/P: User Created
3 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes How to Give Permission to Access our New User or Schema: Syntax: SQL> Grant [connect, resource, dba] to <new User name>; Eg: SQL> Grant connect, resource to Karthik; To Navigate One Schema or User to Another Schema or User: Syntax: SQL > Connect or Conn; Eg: SQL > Connect or Conn; To Display All Schema or User Name with Schema or User ID: Syntax: SQL> Select * from all_Users; Eg: SQL> Select * from all_Users; To change password for old User Account: Syntax: SQL > Password; Eg: SQL > Password; To Check the Current Schema or User Name: Syntax: SQL> Select User from dual; or SQL> Show User; Eg: SQL> Select User from dual; or SQL> Show User; How to Drop Schema or User Account in Database: Syntax: SQL> Drop User <User name>; Eg: SQL> Drop User Karthik;

4 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes To Run the Last Query: Syntax: SQL> / or L or list; Eg: SQL> / or L or List; To Display all object in Current User Account: Syntax: SQL> Select * From Tab; Eg: SQL> Select * From Tab; How to Return Oracle Database to Host or System Command: Syntax: SQL > Host; Eg: SQL > Host; How to Change Text in Screen: Syntax: SQL> C /<What Text you want to Change>/ <Your Content>; Eg: SQL> C /Karthik/ Admin; How to Edit Page in Oracle Data Base Screen: Syntax: SQL> Edit or Ed; Eg: SQL> Edit or Ed; How to Exit Oracle Database Software: Syntax: SQL> Exit; Eg: SQL> Exit;

5 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes Class: 3 (Theory) Introduction of SQL: Types of SQL: 1) Data Definition Language: A data base schema or User or plan (diagram) is specifies by a set of definitions expressed by a special language called DDL 1) Create 2) Alter 3) Drop 4) Truncate 2) Data Manipulation Language: This language that enable user to access or manipulate data as organized by appropriate data mode 1) Insert 2) Update 3) Delete 4) Select 3) Data Control or Transaction Control Language: This language is used to give permission to access our database to another user or to revoke that user 1) Grant 2) Revoke 3) Commit 4) Rollback

6 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes Define Data type: Data type is types of data Data means collection of information. Types of Data Types: 1) Integer or Number 2) Float 3) ROWID 4) Varchar or Varchar2 5) Date 6) TimeStamp 7) Lob 8) CLob 9) Blob 10) BFile files 11) RAW 12) Long Accept Integer values Accept Floating values Used for sequence Accept Character and String Value Accept Date and Time Value Accept Date and Time with Second Accept Image data types Character large Object string Binary large Object string Store file system directory Store graphics, sounds files Store summary context

7 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Create, Manage and Drop Tables: How to Create New Table to Our Data Base: Syntax: SQL> Create Table <table name> (<Field name 1> <data type> (<size>), <Field name 2> <data type> (<size>),); O/P: Table created Eg: Table Name: Student Field name Rollno Name Mark1 Mark2 Mark3 Data type (<size>) number (3) varchar (20) number (3) number (3) number (3)

Eg: SQL> Create table Student (Rollno number (3), name varchar(20), mark1 number(3), mark2 number(3), mark3 number(3)); To Display Table Structure: Syntax: SQL> Describe < Table Name >; or SQL> Desc <Table Name>; Eg: SQL> Describe student; How to Rename Table Name: Syntax: SQL> Rename <Old Table Name> to <New Table name>; Eg: SQL> Rename Student to Marksheet;
8 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Notes: Character or String Integer

Front and Back Single code No Need

How to insert values for all the Field Names: Syntax: SQL> Insert into <Table name> values (<field name1 value>, <Field name2 value>, <Field name3 value>,); How to insert values for particular Field Names Only: Syntax: SQL> Insert into <table name> (<Field name1>, < Field name2>,..) values (<field name1 value>, <Field name2 value>,); How to insert values for all the Field Names in Run Time: Syntax: SQL> Insert into <Table name> values (<&Field name1>, <&Field name2 >, <& Field name3>,); Eg: Table name: student Rollno 1 2 3 4 5 name Senthil Karthi Vinoth Rajesh Vignesh mark1 mark2 mark3 23 56 67 89 78 89 67 56 34 56 34 67 56 45

Eg: SQL > Insert into student values (&Rollno, &Name, &Mark1, &Mark2, &Mark3); O/P: 1 row Affected
9 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Alter: 1) Add Column To Add New Column Name 2) Modify Column To Modify Data Type Column Size 3) Rename Column To Rename Column Name Only 4) Drop Column To Drop Old Column Name It does not affect the values only affects field name How to Add New Field Name in Existing Table: Syntax: SQL> Alter table <Table name> add (<New Filed name1> <Datatype> (<size>), <New Filed name2> <Datatype> (<size>),.); O/P: SQL> Table Altered Eg: Table name: Student New field name Data type (size) Tot Number (3) Avg Number (5, 2) Result Varchar (10) Eg: SQL> Alter table Student add (Tot number (3), Avg number(5,2), Result Varchar (10)); O/P: SQL> Table Altered How to Modify Data Type and Its Size Only: Syntax: SQL> Alter Table <Table name> modify (<old Field name> <new Data type> (<size>),);

10 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes Eg: Table name: Student Old field name old Data type (size) Result Varchar (10)

New Data type (size) Varchar (7)

Eg: SQL> Alter table student Modify (Result varchar (7)); O/P: Table Altered How to Rename Old Field Name to New Field Name: Syntax: SQL> Alter table <Table name> rename Column <Old field name> to <New Field name>; Eg: Table name: Student Old Field Name New Field Name: Rollno Regno SQL> Alter table student rename Column Rollno to Regno; O/p: SQL>Table Altered How to Drop Particular Field Name in Table: Syntax: SQL> Alter table <table name> Drop (<Old Field name>,); O/p: Table Altered Eg: SQL> Alter table student Drop (Result); O/p: Table Altered

11 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

OPERATORS: Operator is a Symbol, Which is used to do some Operations 1) Arithmetic Operator: Operator Meaning + Addition Subtraction * Multiplication / Division Mod Modulus (After division Remainder) 2) Relational Operator: Operator Meaning > Greater Than < Lesser than >= Greater than or equal to <= Less than or equal to = Equal to < > ,! = Not Equal := Assignment operator 3) Logical Operator: Operator Meaning AND AND (Both condition True) OR OR (Any one condition True) NOT NOT 4) Special Operator: Operator Meaning Like Same Between To between IN From the value is present or not
12 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes EOF BOF || End of file Beginning of file Attach Two String

To Update Values Only in Particular Table: Syntax: SQL> Update <table name> set <field name> = <values> [where <condition>] To Find the Total Values: Eg: SQL> update student set tot = mark1+mark2+mark3; O/p: SQL> 5 rows updated To Find the Average Values: SQL> update student set avg = tot/3; O/p: SQL> 5 rows updated To Find the Result Values for Pass: SQL> update student set result = Pass where mark1>34 and mark2>34 and mark3>34; O/p: SQL> 3 rows updated To Find the Result Values for Fail: SQL> update student set result = Fail where mark1<35 or mark2<35 or mark3<35; O/p: SQL> 2 rows updated To Display all Values in Particular Table: Syntax: SQL> select * from <table name> [where <Condition>]; Eg: SQL> Select * From Student;
13 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

To Display Select Field Name Values Only in Particular Table: Syntax: SQL> select <Field Name> from <table name> [where <Condition>]; Eg: SQL> select name, result from student; O/p: To Display Output Based on Condition: SQL> Select * from student where result= Pass; O/p: How to Copy all Data to New Table Name: Syntax: SQL> Create table <Table Name> as <Select Statements>; EG: SQL> Create table Student1 as Select *from student; O/P: Table Created

14 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 4 (Theory) Distinct: To display without Duplicate Entries in Data Base: Syntax: SQL> Select Distinct * From <Table Name>; Eg: SQL> Select Distinct * From Hcl; The wild cards: * Asterisk (*) means display all field values % Leave remaining character or number Like Like means similar to those values _ Leave single character or number Syntax for Wild Cards: SQL> Select * from <Table name> where <Field name> like <Wild Card Condition>; Eg: SQL> select * from Student where Name like %S; Or SQL> select * from Student where Name like S%; Or SQL> select * from Student where Name like S_nthil;

15 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Sub Queries: Operator and Or Not Null Not Null Like Between Not Between In Not In Is NVL = Meaning Both Condition True Any One condition True Opposite Empty Value Not Empty Value Similar From the Range Not From the Range Within that Range Not within that Range Same Equal of

Syntax: SQL> Select * From <Table Name> where <Sub Queries Cond>; Eg: SQL> Select * From Hcl where salary>2000 and salary<10000; SQL> Select Idno,Name From Hcl where salary<50000 or Dept=sw and idno<10; SQL> select * from hcl where salary between 8000 and 10000; SQL> select * from hcl where salary like null; SQL> select * from hcl where salary is not null; SQL> select * from hcl where salary is null and idno<=10; SQL> select * from hcl where salary in 9000 or idno<=3; SQL> select * from hcl where idno in (1, 3, 5);

16 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 5 (Theory) Order by Clause: How to Display Values as Ascending or Descending Order: SQL> Select * from <table name> [where <Condition>] order by <Field name or Column Number> Asc or Desc; Eg: SQL>Select * from Student order by idno Asc; SQL>Select Name, Result from Student order by idno Asc; SQL>Select * from Student order by idno Desc; Group by Function or Aggregative Function: Group by clause tells the oracle to group the records together Group or Aggregative Function Disp sum of given field values Disp max of given field value Disp min of given field value Disp number of rows found Disp Avg of Given Field value Syntax Sum (<Field name>) Max (<Field name>) Min (<Field name>) Count (<Field name>) Avg (<Field Name>)

Syntax: SQL> Select <Aggregative function> from <Table name> [Group by <Field name>]; Eg: SQL> Select sum (Salary) from Hcl group by Dept; SQL> Select Avg (Salary) from Hcl group by Dept; SQL> Select Max (Salary) from Hcl group by Dept; SQL> Select Min (Salary) from Hcl group by Dept; SQL> Select Count (Salary) from Hcl group by Dept;
17 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 6 (Theory) Set Function or Set Operator: Set Function Union UnionAll Minus Intersect Meaning Used to Join two or more than two table Used to Join all field name in more than 2 table Used to display both common values only Used to extract value from 2 table

Syntax for Set Operator or Set Function: SQL><Select Statements1> <Set Function> <Select Statements2>; Eg: SQL> Select Name from Student1 Union Select Name from Student2; SQL> Select Name from Student1 Minus Select Name from Student2; SQL> Select Name from Student1 Intersect Select Name from Student2; How to Delete all or Particular values in Table: Syntax: SQL> Delete from <Table name> [where <Condition>]; Eg: SQL> Delete from Student Where Rollno=10; How to delete all Values Only in Table: Syntax: SQL>Truncate Table <Table name>; Eg: SQL>Truncate Table student;
18 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes How to Drop Table Permanently: Syntax: SQL> Drop Table <table name>; Eg: SQL> Drop Table Student; Class: 7 (Theory) Joins Query: A Join is a query that combines rows from two or more tables, views, etc. Eg: Emp.deptno = dept.deptno Types of Joins: 1) Equi Join 2) Non Equi Join 3) Outer Join 4) Selft Join
1. Equi Joins

Selects the department names along with the other details for every employee. Joins emp and dept tables.
Query SELECT empno, ename, dept.deptno, dname FROM emp, dept WHERE emp.deptno = dept.deptno;

1.

Non-equi joins

The query selects the name,department number and department names of those employees whose salary is greater than 3000.
Query SELECT ename, emp.deptno, dname FROM emp, dept WHERE emp.deptno = dept.deptno AND sal > 3000;

19 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


1. Outer Join

Returns rows even when a join condition fails.


Query SELECT empno, ename, dept.deptno, dname FROM emp, dept WHERE emp.deptno(+) = dept.deptno;

Self Join Illustrates the way to a join a table to itself. Displays every employee's number, name and his/her manager's number and name. In order to query an employee and his/her manager the emp table is joined to itself. Uses table aliases to represent the same table as two different tables.
Query SELECT x.empno "EmpNo", x.ename "EmpName",y.empno "MgrNo",y.ename "MgrName" FROM emp x, emp y WHERE x.mgr = y.empno; Query Analysis

Before we analyze the program, let us look at the following illustration which joins two tables X and Y which are exact copies of emp. SELECT X.ename,Y.ename FROM X,Y WHERE X.mgr = Y.empno; We know that the mgr column contains values that are present in the empno column since a non-existing employee cannot be a manager. X.mgr = Y.empno is an equi join condition. Thus X.ename returns the name of the employee from the X table and Y.ename returns the name of the employee from the Y table. The name returned by Y.ename would be the manager name due to the join condition. The following figure explains this concept.
X table X table
20 Prepared by A.KARTHIKEYAN ( : 9790768919

Y table

ORACLE Complete Notes


Empno 7369 7499 7902 7521 Ename Smith Allen Ford Ward Mgr 7902 7698 7839 7698 Empno 7369 7499 7902 7521 Ename Smith Allen Ford Ward Mgr 7902 7698 7839 7698

X.empno X.ename Y.empno(X.mgr) Y.ename 7369 Smith 7902 Ford The query SELECT x.empno "EmpNo",x.ename "EmpName" , y.empno "MgrNo",y.ename "MgrName" works in a similar way. FROM emp x, emp y refers the single table emp as x and y for the purpose of the join.
The emp table appears twice in the FROM clause and is followed by table

aliases, that are used to qualify column names in the join condition. x and y are termed as table aliases. WHERE x.mgr = y.empno creates a join between the mgr column of one emp table with the empno of another copy of emp table. This condition joins a table to itself. Hence termed as Self Join. 1. Another Illustration for Self Join

Selects the employees who get salary greater than their superiors. Use of Self Join and a non-equal condition.
Query SELECT x.ename "EmpName",x.sal "EmpSal",y.ename "MgrName",y.sal "MgrSal" FROM emp x,emp y WHERE x.mgr = y.empno AND x.sal > y.sal; Query Analysis

WHERE x.mgr = y.empno joins the mgr column with the empno column. x.sal > y.sal compares the salary of each employee with his manager's salary.
21 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


Thus the query selects those employees who get more salary than their managers.

Class: 8 (Theory) String Function: String Function Lower(<Text>) Upper(<Text>) Length(<Text>) Replace(<String>,<c1>,<c2>) SubStr (<string>,<start Position>, <No of char>) Trim Ltrim(<String >) Rtrim(<String>) Reverse(<String>) Ascii(<Char>) Chr(<Ascii>) Soundex( ) Lpad( ) Rpad() Initcap Meaning To Convert Lower Case To Convert Upper Case To Find out the Length String with every occurrence of character 1 replace with character2 Extract position of given string Eliminate space for both side Eliminate Left Character or Space Eliminate Right Character or Space To reverse the Given string To convert ASCII value To Convert char value Based on Sound echo Left Pad Right Pad First letter capital others small

Syntax for Applying String Function: SQL> Select <String Function Name> from dual; Eg: SQL> Select Length (Hacker) from dual;
22 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes Or SQL> Select Length (Name) From Student;

Class: 9 (Theory) Date and Time Function: Date Function SysDate() Last_day(<Date>)) Add_Months(<date>,<No of Month Add>); Months_between(<First months>,<last Month>) Next_day(<date>,<day>) To_char(<Date>,Day-Monthyear) To_Date(<Date>,Day-monthyear) Current_Date SysTimeStamp Meaning Display Current System Date Display Last day of given month Add no of Months from the given date Find the Diff between two months Display next given days from the date Convert given date as character format Convert Date Format Display current Date Display current sys time stamp

Syntax for Applying Date Function: SQL> Select <Date Function Name> from dual; Eg: SQL> Select sysdate from dual;
23 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 10 (Theory) Numeric and Mathematical Function: Numeric Meaning Ceil (<Value>) Display Nearest After Whole Integer Value Floor(<Value>) Display Nearest Before Whole Integer Value Round(<Value>) Round up the given Value Power(<Value>) Find out the Power Value Sign(<Value>) Display Positive or Negative Sqrt(Value>) Display Square root value Mod(<Value>) Display Modulus Value Trunc(<Value>) Remove Floating Points Abs(<Value>) Display absolute value Max(<Values>) Display max value Min(<Values>) Display Min Value Sum(<Values>) Sum of all values Count(<Values>) Display total no of counts Rank(<Values>) Set the ranking Avg(<Values>) Display average value Greatest(<Values>) Display greatest value Least(<Values>) Display Least value Syntax for Applying Math & Numeric Function: SQL> Select <Math Function Name> from dual; Eg: SQL> Select Power (4, 2) from dual; SQL> Select Max (4, 2,56,34,245,64,45) from dual;
24 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes SQL> Select Avg (4, 2,56,34,245,64,45) from dual; SQL> Select count (4, 2,56,34,245,64,45) from dual;

Class: 11 (Theory) Create, Manage and Drop Permission (Grant / Revoke) (TCL): How to give Permission to access Our New User: Syntax: SQL> Grant [connect, resource, dba] to <New User Name>; Syntax: SQL> Grant connect, resource, dba to Raj; How to Revoke Permission to access Our Old User: Syntax: SQL> Revoke [connect, resource, dba] from <User Name>; Syntax: SQL> Revoke connect, resource, dba from Raj; How to give Permission to access our Table to Other User: Syntax: SQL> Grant <DML Command> on <table name> to <user name>; Eg: SQL> Grant select on Student to Raj; How to Remove Permission to access our Table to Other User: Syntax: SQL> Revoke <DML Command> on <Table name> from <New User name>; Eg: SQL> Revoke select on student from Raj; How to save our Data permanently to our Database: Syntax:
25 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes SQL> Commit; Eg: SQL> Commit; How to Undone Last Action until the last Commit Statements: Syntax: SQL> Rollback; Eg: SQL> Rollback; Class: 12 (Theory) Create, Manage and Drop View: View is a logical window on a Table It depends on existing Table How to Create New View: Syntax: SQL> Create View <View Name> As <Select Statements>; Eg: SQL> Create View V1 as Select* From Student; How to Display all View Values: Syntax: SQL> Select* From <View Name>; Eg: SQL> Select* From V1; How to Insert values for View (It Affect both Table and View): Syntax: SQL>Insert into <View name> values (<&field name1>,); Eg: SQL>Insert into V1 values (&name); How to delete values from View (It Affect Both): Syntax: SQL>Delete from <View name> Where <Condition>;
26 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes Eg: SQL>Delete from V1 Where Regno=5; How to Drop View in Our Database: Syntax: SQL> Drop View <View Name>; Eg: SQL> Drop View V1; Class: 13 (Theory) Create, Manage and Drop Index: An index is a performance-tuning method of allowing faster retrieval of records. An index creates an entry for each value that appears in the indexed columns. By default, Oracle creates B-tree indexes. Syntax for Create Index: CREATE [UNIQUE] INDEX index_name ON table_name (column1, column2, . column_n) [ COMPUTE STATISTICS ];

Syntax for Rename Index Name: Alter Index <Old Index name Rename to <New Index name>; Syntax for Drop Index: Drop index <Index Name>;

27 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 14 (Theory) Create and Manage Constraints: Constraints Keys Unique Meanings This key accept null number only but is does not allow duplicate Values Not Null This key does not allow null values but it accept the duplicate Values Primary Key This Key Does not accept Both Null and Duplicate Values Check (<Condition>) This key is used for Checking Condition at Insert Time Default Set a content as default value Foreign Key or References This key used for Create Relationship Between one table to another Table Syntax for Constraint Keys: SQL> Create table <table name> (<Field name> <Data type> <Constraint Key>,..); Eg: SQL> Create table Student (Regno <Data type> <Constraint Key>,..); Syntax for References or Foreign Key:

28 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes SQL> Create table <table name2> (<Table2 field name1> <data type>, foreign key (<Table1 field name1>) references <Table name1> (<Table1 field name1>),..); Eg: SQL> Create table Student2 (Rollno Number, foreign key (Rollno) references Student1 (Rollno), Name Varchar(20));

Class: 15 (Theory) Create and Manage Synonyms: A synonym is an alternative name for objects such as tables, views, sequences, stored procedures, and other database objects.

29 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 16 (Theory) Create and Manage Sequence: A sequence is an object in Oracle that is used to generate a number sequence. Syntax for Create Sequence: SQL> Create Sequence <Sequence Name> MinValue <n> MaxValue <n> Start with <n> Increment by <n>; Eg for Sequence Creation: SQL > Create Sequence S1 MinValue 1 MaxValue 100 Start with 10 Increment by 1; Syntax for insert sequence value to Table: SQL> insert into <Table name> values (<seq name>.nextval>); Eg: SQL> insert into Hcl (Sno, name, Salary) values (s1.nextval,&name, &salary);
30 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes Syntax for display Current Sequence Value: SQL > Select <Seq Name>.currval from dual; Eg: SQL > Select S1.currval from dual; Syntax for Drop Sequence: SQL> Drop sequence <Sequence name>; Eg: SQL> Drop sequence S1; Class: 17 (Theory) PL - SQL: PL means Procedure Language and Structure Query Language PLSQL is refers to block structure language It contains program code, variable declaration, error handling, procedures and functions Structure of PL - SQL: SQL> Declare <Variable Declaration>; Begin <Main Coding>; Exception <Exception Coding> End;

31 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 18 (Theory) Conditions and Loops: 1) IF-THEN-ELSE Statement 2) Case Statement 3) GOTO Statement 4) Loop Statement 5) FOR Loop 6) CURSOR FOR Loop 7) While Loop 8) Repeat Until Loop 9) Exit Statement

32 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 19 (Theory) Exception Handling: Some abnormal an error can be occur to avoid this error we can use Exception concept.

33 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 20 (Theory) Procedures:

34 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 21 (Theory) Functions:

35 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 22 (Theory) Package:

36 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 23 (Theory) Cursor: A cursor is a mechanism by which you can assign a name to a "select statement" and manipulate the information within that SQL statement.

37 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 24 (Theory) Trigger: Stored procedure that is fired implicitly whenever the data is associated table are changed is called the trigger Parts of Trigger: 1) Trigger Statements: SQL statement that includes trigger is called trigger statement 2) Trigger Restriction: Trigger is fired only if the condition is true 3) Trigger Action: PL/SQL block executed when a trigger is fired is called trigger action Types of Trigger Fired: 1) Each Row Trigger fired each time the row is affected by trigger statements 2) Each Statement Trigger fired only once for execution of trigger in statements Types of Trigger Changes: 1) Before Trigger Trigger action executes before the triggering statement 2) After Trigger Trigger action executes after the triggering statement
38 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes Syntax for Trigger Declaration: SQL> Create Trigger <Trigger name> <After/Before> <insert/update/Delete> on <table name> For <each row/each statement> Declare <Variable declaration>; Begin <Statements>; End; / O/P: Syntax for Drop Trigger: SQL>Drop Trigger <Trigger name>; O/P: SQL> Trigger Dropped Eg for Trigger Concept: SQL> Create trigger Trigger1 After insert on dept For each row Declare Begin Dbms_output.put_line(1 row created in dept table); End; / O/P: SQL> Trigger Created Checking Trigger concept: SQL> Insert into dept values(5,ramesh); O/P: SQL> 1 row created in dept table SQL> 1 row created Syntax for Drop Trigger:
39 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes SQL>Drop Trigger Trigger1; O/P: SQL> Trigger Dropped

Syntax for Disable/Enable Trigger: SQL> Alter Trigger <Trigger name> Disable/Enable; Eg: SQL> Alter Trigger trigger1 Enable; Syntax for Disable/Enable all trigger on Tables: SQL> Alter Table <Table Name> Disable/Enable all Triggers; Eg: SQL> Alter Trigger trigger1 Disable all Triggers;

40 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

Class: 25 SQL * Plus Commands:


Command @ @@ / ACCEPT APPEND Run an SQL Script Run a nested SQL Script Executes the SQL command or PL/SQL block User Input Accept Variable <Data type> Description

Adds specified text to the end of the current line in the buffer. Specifies where and how formatting will change in a report, or lists the current break definition. Places and formats a specified title at the bottom of each report page, or lists the current BTITLE definition. Changes text on the current line in the buffer. Resets or erases the current clause or setting for the specified option, such as BREAKS or COLUMNS.
41 ( : 9790768919

BREAK

BTITLE

CHANGE CLEAR Scr

Prepared by A.KARTHIKEYAN

ORACLE Complete Notes


Command CONNECT COPY Description Connects a given user to Oracle. Copies results from a query to a table in a local or remote database. Specifies a user variable and assigns it a CHAR value, or lists the value and variable type of a single variable or all variables. Deletes one or more lines of the buffer. Lists the column definitions for the specified table, view, or synonym or the specifications for the specified function or procedure.

DEFINE

DEL DESCRIBE

DISCONNECT Commits pending changes to the database and logs the current user off Oracle, but does not exit SQL*Plus. EDIT Invokes a host operating system text editor on the contents of the specified file or on the contents of the buffer. Executes a single PL/SQL statement. Terminates SQL*Plus and returns control to the operating system. Loads a host operating system file into the SQL buffer. Accesses the SQL*Plus help system. Executes a host operating system command without leaving SQL*Plus. Adds one or more new lines after the current line in the buffer.

EXECUTE EXIT

GET HELP HOST

INPUT

42 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


Command LIST PASSWORD Description Lists one or more lines of the SQL buffer. Allows a password to be changed without echoing the password on an input device. Displays the specified text, then waits for the user to press [Return]. Displays the current value of a bind variable. Sends the specified message to the user's screen. Terminates SQL*Plus and returns control to the operating system. QUIT is identical to EXIT. Remark Comments or comment or /*comment */ Lists and executes the SQL command or PL/SQL block currently stored in the SQL buffer. Saves the contents of the SQL buffer in a host operating system file (a script). Sets a system variable to alter the SQL*Plus environment for your current session. Shows the value of a SQL*Plus system variable or the current SQL*Plus environment. Shuts down a currently running Oracle instance. Stores query results in an operating system file and, optionally, sends the file to a printer. Executes the contents of the specified script. The script can only be called from a url.
43 Prepared by A.KARTHIKEYAN ( : 9790768919

PAUSE

PRINT PROMPT QUIT

REMARK RUN

SAVE

SET

SHOW

SHUTDOWN SPOOL

START

ORACLE Complete Notes


Command TIMING Description Records timing data for an elapsed period of time, lists the current timer's title and timing data, or lists the number of active timers. Places and formats a specified title at the top of each report page, or lists the current TTITLE definition. Declares a bind variable that can be referenced in PL/SQL.

TTITLE

VARIABLE

Report Generation: Reports Builder is a visual tool to develop reports Can generate reports based on the data in the data base Provides extensive formatting facilities Use of PL/SQL in reports further enhances the capability Can integrate with other Oracle tools like Oracle Forms and Graphics Parts of Report: The basic requirements of a report are: Data Model Layout Model The Data Model is composed of objects that define the data to be included in the report The Layout Model is composed of objects that define positioning and appearance of data and other objects in the report Various Types of Reports: -Tabular -Form Like -Mailing Label
44 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes -Form Letter -Group Left -Group Above -Matrix -Matrix with Group

SQL & PLSQL Commands Query: SQL Commands: 1. Select and display the names of all the tables owned by you. 2. Find out the column names and data types of some of these tables. 3. Select all rows and all columns from these tables. 4. Display empno, ename, deptno, mgr from emp. 5. Display mgr, deptno,empno, ename from emp. 6. Display the above columns again with the column tittles as Employee_no, Name, Manager, Department. 7. Display empno, name, salary deptno in ascending order of employee number. 8. Display empno, name, salary, deptno in descending order of deptno. 9. Display empno, name, salary, deptno in ascending order of salary. 10. Display empno, name, salary, deptno in ascending order of employee name. 11. Display empno, name, salary, deptno in descending order of employee number. 12. Display empno, name, salary, deptno in descending order of salary.
45 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


13. Display empno, name, salary, deptno in ascending order of department number and within department - employee number in ascending order. 14. Display empno, name, salary, deptno in ascending order of department number and within department - employee number in descending order. 15. Display one occurrence of each for department number from emp. 16. Display one occurrence of each for job from emp table 17. Display all the columns from emp which has employee number = 7654. 18. Display all the columns from emp with employee name as SCOTT. 19. Display all the columns from emp with job = MANAGER. 20. Display all the columns from emp for those employee(s) joined on 3-1281. 21. Display all the employees who are managers. 22. Display all the employees who are managers and who belong to dept no 20. 23. Display all the employees who are managers and who belong to dept no 40. 24. Display all the employees who are not managers but belong to dept no 40. 25. Display all the employees who are either analysts or clerks. 26. Display employee number, name, job, commission for those employees who have null commission. 27. Display employee number, name, job, commission for those employees who do not have null commission. 28. Display employee number, name, salary, date of joining for those employees who have joined after 28th September 1981. 29. Display employee number, name, salary, date of joining for those employees who have joined before 28th September 1981.
46 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


30. Display all the columns from emp which have employee number less than 7654. 31. Display all the columns from emp which have employee number less than or equal to 7654. 32. Display all the columns from emp which have employee number greater than 7900. 33. Display employee number, name, salary for those employees with salary between 1500 and 5000. 34. Display employee number, name, job for employees with job analyst, clerk or salesman. 35. Display employee number, name, sal, commission from emp table for employees whose names start with S. 36. Display employee number, name, sal, commission from employee table for employees whose names start with M. 37. Display employee number, name, sal, commission from employee table for employees whose names sound like skot. 38. Display all the columns of the employee table for those employees who are not analysts . 39. Display the employee number, name, salary, comm for those employees who do not have any commission and who do not belong to department 10 . 40. Find out those employees whose salary is more than 2500 and who belong to dept 20 or 30 as well as well as with their names starting with S or F. 41. Formulate a query to find out the employees who do not report to any one. 42. Find out those employees who are clerks but do not belong to department 20. 43. Find out those employees who have joined after 1st Feb 81 but before 31-12-81.
47 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


44. Add a bonus column to your query which is 15% of salary for those drawing less than a salary of 3500. 45. Add an incentive column to your query which is 10% of salary plus 5% of commission for those drawing more than a salary of 3500 . 46. Find out those employees who have null commission or zero commission using a single query without using OR. 47. Select the departments from the dept table which are not located in Dallas. 48. Find out the department number of the accounting department. 49. Find out those employees who draw more commission than salary. 50. Find out those employees who draw more salary than commission. 51. Display the result of the query without the column headers. 52. Display the system time along with SQL prompt. 53. Set the appropriate system variable such that feedback of a query is given, only for 5 or more rows JOINS Commands: 1. Join the employee table and the department table so that your query displays the department name for each employee. 2. Design a query on the employee table which displays employee number, name, salary,department, manager no, manager name. (Hint: use table aliases). 3. Design a query on the employee and department tables which displays the name, no, salary, department no, department name for all employees who are not managers. 4. Design a query on the employee and department tables which displays the name, no, salary, department no, department name for all employees who do not belong to research department. 5. Design a query on the employee and department tables which displays the name, no, salary, department no, department name for all employees
48 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


whose department number is greater than 20. 6. Find out those employees who draw more salary than their managers. (Hint: Use self join to join the employees row with their respective managers and then find out employee.sal > manager.sal in the same query.) 7. Create a query which lists the names of the employees, their department names, their respective managers along with the department names of those managers. (Hint: Use table alias/self join and equi join concepts.)

8. Write a query on emp and dept tables to display the names of the respective departments for every employee. In addition the query should also display the department nos in the dept table but not in emp table along with the name. (Hint: Use outer join.) SQL Expressions and Datatype Functions: 1. Display the employee number, name, salary, commission and salary+ commission for those employees who are salesmen. Name the calculated column as Gross. 2. Display the employee number, name, salary, commission and salary+ 10% of salary for those employees who are not salesmen. Name the calculated column as Revised_Pay. 3. Display the employee number, name, salary, commission for those employees whose salaries are greater than twice their commission.(Hint: use NVL function) 4. Display the employee number, name, salary, commission and salary multiplied by 1.1234 for those employees who are salesmen. (round off the calculated column to 2 digits after decimal). 5. Display the employee number, name, salary, and salary multiplied by 12.975 for those employees who are not salesmen. (truncate the calculated column to 2 digits after decimal). 6. Display the average salary for every department in the employee table. 7. Display the total salary, average salary, maximum salary, no of rows and
49 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


department no for every department in a single query. 8. Modify the above query to display only for managers in each department. 9. Select the minimum and maximum salaries and commissions of all the employees departmentwise. 10. Use decode to get the names of the departments from the emp table. 11. Using DECODE display the null values in the comm column as Not Applicable. Values other than NULL should be displayed as such. 12. Display the employee name in lower case, length of the name and first three characters. 13. Display the hiredate from employee in the format mm/dd/yyyy-hh:mi:ss. 14. Add 15 months to the hiredate in the select statement and display the new date. 15. Find the number of months between 15-12-96 and 1-1-98. 16. Find the last date of the month for the hire dates in the employee table . 17. Find the date on which the next Sunday occurs. 18. Design a query which rounds off sysdate to the nearest month, date and year. 19. Design a query which truncates the sysdate month, date, yearwise respectively. 20. Select sum of salaries from emp table departmentwise for sum(sal) more than twice the sum of comm of the respective departments. 21. Select sum of salaries of emp table empnowise and observe the results. 22. Find out the managers who draw more than twice/thrice the average salary of their subordinates. (Hint: Attempt it after learning about sub queries) 23. Display the decimal portion and the integer portion of the number 4345.232. 24. Replace each occurrence of 'S' and 'A' with 'X' and 'Y' in ename column
50 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


of emp table. 25. Display the names of those employees whose name contain the letter 'E'. 26. Display the hiredate of the employees in the specified date format. (Hint: 02-JUN-01 as 2nd June of the year 2001) 27. Display the commission of the employees in words.

SUB Queries: 1. Display employee number, name, salary, department number from employee table for the department number of Jones. 2. Display employee number, name, salary, department number from employee table for department name accounting. (available in department table). 3. Display employee number, name, salary, department number from employee table for salary > maximum salary. 4. Repeat the above query for salary > minimum salary. 5. Modify the query 3 above to display the salaries > minimum salary for the respective departments. DDL Commands: 1. Create the following tables: Item_master(item code number 5, item_name varchar2 30 unit of measure varchar2 3, unit cost number 12,2) Stock(item code number 5, opening balance date date, opening quantity number 15,2, current stock number 15,2) Grn header(grn_number number 3, grn date date supplier_code varchar2 5, purchase_order_number number 5) Grn detail(grn_number number 3, grn_date date, item_code number 5, quantity number 15,2) Supplier_master(supplier_code varchar2 5, name varchar2 30, address_line1 varchar2 30, address_line2 varchar2 30,
51 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


pincode number 6, phone number 7, fax number 7) Po_header(po_no number 3, po_date date, supplier_code varchar2 5) Po_detail(po_no number 3, po_date date, item_code number 5, quantity number 15,2) 2. Create unique index on supplier code for supplier master. 3. Create unique index on item code for item master. 4. Create unique index on item code for stock master. 5. Create unique index on grn no, date for grn header. 6. Create index on grn no, date for grn detail. 7. Create unique index on po no, date for po header. 8. Create index on po no, date for po detail. 9. Modify all the above indexed columns to not null. 10. Add a column location varchar2 10 to stock master. 11. Increase the size of the address column to 40 in supplier master. 12. Drop and create again the supplier master with supplier code as primary key. 13. Increase the size of grn number to 10 wherever it appears. DML Commands: 1. Insert 5 compatible rows for each of the above tables. 2. Change the values of at least two columns in each of the above tables. 3. Make the changes permanent. 4. Delete GRN Nos 1 and 2 from both grn header and detail. 5. Select from grn tables and observe, then roll back.
52 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


6. Insert into item master the following values: Item Code 2149 2150 2151 2152 Name monitor key board nos 400 850 Unit of Measure nos Unit Cost 700

After every insert , select and verify and then commit . 7. Modify the above values as follows: Item Code 2149 2150 2151 2152 Name printer monitor manuals cables Unit of Measure nos dozen boxes mtr Unit Cost 1900 6000 400 900

Select and verify the changes you have made and commit if they are OK. 8. Delete the following rows: - the row with item code =2152 - the row with item name as manuals - the rows with unit cost >500 9. Select and verify after every delete 10. Roll back 11. Delete all rows. Select and verify 13. Roll back. Select and verify 15. Commit VIEWS Commands: 1. Create a view containing all columns except salary from the employee table for department no 20. 2. Create a view for dept 20 with check option. 3. Update dept no 20 to 30 in the above view and observe the results.
53 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


4. Create a view joining emp and dept with deptno as the join condition. 5. Try updating the above view and observe 6. Create a view using item master and stock master to display the item name along with the other columns of the stock master. 7. Create a read-only view of the emp table, containing empno, ename, job, deptno columns. DB Constraints: 1. Create table course as follows: course code varchar2(5) primary key constraint course name varchar2 30 not null and unique duration in months number should be one of 12,24,36,48 2. Create table student as follows: student_no number 5, name not null, course code should be present in course table, start_date date, end_date date should be greater than start_date, course_code, student_no as primary key 3. Try to create a check constraint on emp for sal > 3000 and trap violations into excpt. 4. Create a join of emp and excpt appropriately to view the violating rows. 5. Add a constraint to your stock master to ensure that the item code in the stock master is present in the item master. PL/SQL Comments: 1. Write a PL/SQL program which reads emp table and increases the salary by 10% for dept 10 increases the salary by 20% for dept 20 increases the salary by 30% for dept 30 2. Write a PL/SQL program that increases the salary based on the job. 3. Write a PL/SQL program that increases the salary based on deptno and job. 4. Write a PL/SQL program which identifies those employees who have null
54 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


and zero commission and inserts the empno and comm (null or zero) of those rows into an error_table (to be created with a single column - error_text varchar2(100)). (Treat zero and null comm as two different exceptions and insert them accordingly). 5. Rewrite program 1 using cursor parameter for deptno. 6. Using a PL/SQL program validate the item code values in grn_detail and stock tables against those in the item master. Insert the item codes of the violating tables into the error table with an informative error message. Rectify the errors and execute the program again. Repeat the process till there are no errors. (Use cursor for loops and nested PL/SQL blocks). Write the above program as two separate programs as follows: - Item_code in grn_detail Vs item_code in item_master - Item_code in stock_master Vs Item_code in item_master. 7. Rewrite the above program using REF cursor. 8. Pl use the existing emp table for this exercise - declare a pl/sql table variable for empno - declare a pl/sql table variable for sal - for every odd value of array index increment sal by 101 - for every even value of array index increment sal by 102 - insert the empno, array index value, old sal, new sal in a separate table to be created for this purpose - Verify the results. 9. Write a PL/SQL program to display the employee details with the department name and bonus amount. Create a record type emp_rec containing the relevent fields to hold employee name, depatrment name and bonus. 10. Wrap any of your previous subprograms/packages and try creating them using your wrap file. PROCEDURES, FUNCTIONS AND PACKAGES Comments: 1. Create a procedure to insert into the employee table. This will be called from SQL and the various column values will be passed to the procedure 2. Similarly create a procedure to update the emp table 3. Convert two of your PL/SQL programs into procedures and execute.
55 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


(Hint: These converted procedures will not accept arguments) 4. Create a function which returns the number of rows affected by an update operation . 5. Create a function which returns the updated value of stock. 6. Create a package containing one procedure and one function from the above examples. 7. Create a function f_bonus which fetches the bonus details of each particulars from the bonus table. The function should accept an empno and return the bonus amount. Call this function through a SELECT statement (on emp table) to display the employee details and bonus. 8. Create a table student_master(stud_id number 4, fname varchar2 10, lname varchar2 10) and insert 5 rows. Create a package stud_pack containing two procedures as follows: - RegStudent (p_Fname varchar2 10, p_Lname varchar2 10, course varchar2 10); - RegStudent (p_studID number, Course varchar2 10); The procedures should insert the student_id and course details into the table registered_stud(stid_id number 4, course varchar2 10). The student_master table can be used to fetch the stud_id when name is given. 9. Write a PL/SQL subprogram which dynamically creates a DML statement to delete the students enrolled for a particular course, from the registered_stud table. Also display the number off records deleted. 10. Execute a query dynamically to display the items received on a particular date, from the grn_detail table. DB TRIGGERS Comments: 1. Create a DB Trigger on grn detail which updates stock whenever a new row is inserted into the grn details.
56 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


2. Create a DB Trigger on grn detail which updates stock whenever a row is updated in the grn_details. 3. Create a DB Trigger on grn detail which updates stock whenever a row is deleted from grn_details. 4. Create a DB trigger which inserts the contents of a row along with the user id into an audit table whenever a row is inserted, deleted or updated in emp table. For update and delete the previous values should be inserted. 5. Convert the above trigger to a statement trigger. 6. Create a view emp_mgr_view containing the employee number, name, manager's number, manager's name. Create two instead of triggers (Upd_mgrname_tr and Upd_mgrno_tr) on the view to update the manager name and number in the view. ORACLE FORMS Comments: Exercise : 1 a. Create a default form for the item master table - make it tabular and multi record - insert, query, update and delete rows/columns and observe the results b. Create a default form for stock master table - make it form type - use this form to enter the details of stock of all items in item master c. Create a default form for supplier table - make it form type - use this form to enter details of suppliers Exercise : 2 a. Open the forms created in the previous exercise one by one - align the various fields in each form suitably - give appropriate labels for the fields - adjust the color combinations
57 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


- draw a rectangle enclosing the block of fields - give appropriate titles for the forms you have created b. Go to the object navigator and familiarize yourself with the various features and their uses. c. Similarly observe the various options available with the menu and the tool bars. Exercise : 3 1. Open item master form and include the following: - item classification ( text item - base table item) - this column has to be added to the item master table - varchar2(2) - the possible values are RM(Raw Material) , FG(Finished Goods) CN(Consumable) b. Include the following in the stock master form: - create a display item for item name - display the item name from the item master - also validate the item code with the item master - the item name should be displayed even during execute query c. In all the forms you have created so far ( item master, stock master, supplier) add push buttons for save, exit and cancel. Write the necessary triggers to perform these functions. d. Execute all the forms one by one. Add, modify, query and delete rows/columns. Observe the behaviour of the forms at various stages. Discuss Exercise :4 1. Add a new column perishable_yn in the item master - add a check box for this column in the corresponding form - change the item type to a list item 2. Add a new column location in the stock master - create a radio group in the form to represent this column with four radio buttons each representing a location
58 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


Exercise: 5 a. Open stock master and display the error message for invalid item code through an ALERT. b. In the stock master form provide list of values facility for entering the item code. c Upgrade your existing form with proper interface items appropriately Exercise : 6 a. Create a master detail form for grn header and detail tables (grn no, date) b. Create a master detail form PO header and detail tables (po no, date) c. Display supplier name, item name at appropriate places in these forms Exercise: 7 a. In the grn master detail form create a new block for stock master . - whenever the item code is entered display the stock block as a pop up block with the current stock of the corresponding item b. In the PO header detail form include a supplier block and display supplier address as a pop up block Exercise: 8 a. Open GRN header detail form and write the following triggers - when validate item for supplier code and item code - post query for item code and supplier code - the above triggers should also display the corresponding item/supplier name as a display item. - create price and value text items in grn detail(non base table) - calculate value using pre/post text item trigger - write a post block trigger in header block which sets the price (grn detail) to a minimum amount based on the supplier_code b. Revisit the triggers you have created in the previous exercises and discuss
59 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes


Exercise: 9 1. Open the GRN master detail form and create the following triggers: - post insert trigger to update stock - post update trigger to update stock - post delete trigger to update stock Note: Please analyze, understand the effect of the base table (grn) operations before writing the triggers Exercise 10 a. Create a inventory menu and include all the forms you have created so far b. Give suitable application titles to MDI Window and Window0 c. Run the inventory application through the menu ORACLE Reports: 1. Create a report to print the contents of Item Master. 2. Create a report to print the contents of Stock master. 3. Create a Master Detail report with GRN header and detail tables. (Hint : create break column on grn no. of grn detail.) 4. Create a formula column VALUE (Price * qty) in grn detail group - create a summary column for total cost - create a formula column to display item name and supplier name 5. Convert the item master report to a form report and observe. 6. Create a form letter report on the purchase order table for the supplier asking him to expedite supply. Also refer your PO number in that report. 7. Create a matrix report on emp table for sum(sal) deptwise/jobwise 8. Call these reports from the menu you have created and review your inventory application in full

60 Prepared by A.KARTHIKEYAN ( : 9790768919

ORACLE Complete Notes

61 Prepared by A.KARTHIKEYAN ( : 9790768919

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy