Академический Документы
Профессиональный Документы
Культура Документы
DBMS Concepts
5/2/2012 9:50 PM
5/2/2012 9:50 PM
Advantages of DBMS:
Data can be stored Standards can be enforced Integrity can be maintained Security restrictions can be applied Redundancy (repetition of data) can be reduced
FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
5/2/2012 9:50 PM
DBMS Models:
A Database Model describes, how the data are presented to the user and programmer for access. The database models can be classified into: FMS (File Management System)
5/2/2012 9:50 PM
DBMS Models:
HDBMS (Hierarchical Database Management System) NDBMS (Network Database Management System) RDBMS (Relational Database Management System
5/2/2012 9:50 PM
5/2/2012 9:50 PM
5/2/2012 9:50 PM
RDBMS concepts
Dr.E.F.Codd proposed the relational model for database systems in 1970. The term relational derived from the set theory of mathematics. Relational model contains . Collection of Objects or relations. Set of Operators to act on the relations. Data integrity for accuracy and consistency.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
RDBMS terminology
It represents database as a collection of entitities or relations (tables). A row or record is called as a tuple which represents an entity. A column or field is called as an attribute of entity. A list of values of a field (column) is called domain. The number of attributes of a relation is called degree. The number of tuples determines the cardinality of the relation. 5/2/2012 9:50 PM FACULTY : SK ABDUL
YESDANI
RDBMS terminology
Primary Key : An attribute or combination of attributes that uniquely defines each tuple in a relation. Foreign key: An attribute or combination of Attributes in one relation R1 which indicates the relationship of R1 with another relation R2 and must contains values matching at both relations.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
RDBMS Users
RDBMS are multi user supported and many persons involved in the design, use, and maintenance of a large database with hundreds of users. Database Designer: Responsible for identifying the data to be stored in the database and choosing proper structures to represent and store data.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
RDBMS Users
Database Administrator (DBA): Collects the information to store in the database. A database is designed to provide the right information at the right time to right persons. DBA is responsible to authorizing access to the database, monitoring the database , breech of security and poor response time etc,.
5/2/2012 9:50 PM
RDBMS Users
System Analysts and Application programmers: System Analists determine requirements of end users, and develop specifications for transactions that meet the requirements. Programmers implements the specifications as programs then test, debug, document and maintain these transactions. Maintain operation of the RDBMS software
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
RDBMS Users
End Users: They invoke an application to interact with the system, or writes a query for easy retrieval, modification, or deletion of data.
5/2/2012 9:50 PM
RDBMS Components
Entities and Tables: An entity is any object which is distinctly identified becomes a table in the RDBMS. Ex: the entities in a college are students, faculty, branches etc. Each entity has its own features or characteristics known as attributes become columns in the table.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Emp_no Emp_name
123 124 125 126
5/2/2012 9:50 PM
Emp_dob Emp_desig
Executive Supervisor Manager Accountant
T U P L
Data Modeling
Data modeling is a group of conceptual tools that describes data n its relationships. Data modeling contains 3 steps. Conceptual data modeling identifies highest level of relationships in the data. Logical Data Modeling :describes the data and its relationships in detail. Physical Data Modeling: Specifies how the logical model is to be realized.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Types of Relationships
One to One One to Many Many to One Many to Many
5/2/2012 9:50 PM
5/2/2012 9:50 PM
E-R Diagrams
Component
Entity
Symbol
Entity
Example
Student
Weak Entity
Relationship
Weak Entity
relationship
assignment
Saves in
Attribute
Key Attribute
5/2/2012 9:50 PM
attribute
attribute
FACULTY : SK ABDUL YESDANI
rollno
Acct_no
Types of attributes
Multi valued attributes Ex: multiple phone nos. Composite attributes Ex: address doorno, street, city,pin etc; Derived Attributes. Ex: age derives from DOB and current date.
FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
5/2/2012 9:50 PM
5/2/2012 9:50 PM
Normalization
Previously databases used to have large number of columns and records. This has some drawbacks as given below. Repetition anomaly: repetition of data in different records effects on performance during retrieval of data. Insertion anomaly: Inserting data in some columns & leaving some columns blank could lead to problems while retrieving data.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Normalization
Deletion anomaly: deleting data from some columns may lead to deletion of all data regarding that person. Updating anomaly: if some thing is updated at one place this should be reflected at all other related places. If it is not updating at all related places that is updating anomaly.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Normalization
To avoid all anomalies from the database a technique called Normalization has introduced by Dr.E.F.Codd. There are 3 Normalizations based on dependencies among attributes of a relation.
5/2/2012 9:50 PM
5/2/2012 9:50 PM
Madhu C
5/2/2012 9:50 PM
salary
30000 25000 20000 20000
bharat kiran
B C
Madhu C
nd 2
Projid projname
113 124
Projid 113 124 113 245 Mad C 113 FACULTY : SK ABDUL hu YESDANI 124
Emp Emp Grad no name e 142 Ama A r 168 bhar B at 263 kiran C
rd 3
Normal Form
Empno 142 168 263 245 Empname Amar bharat kiran Madhu Projid 113 124 113 113 124 Grade A B C C
Grade A B C
De normalization
By normalizing the database redundancy is reduced and data integrity ensured. But to retrieve the data complex queries may have required. It tends to effect on the performance of the database. So to avoid this a minimal redundancy can accepted and this is called De normalization.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Relational Operators
Operators operate on relations based on the foundation of relational Algebra. Select: used to extract data with a given condition. Project: Used to project certain details of a relational table. Product: It combine relation from 2 different relational tables.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Relational Operators
Union: it retrieve either one or 2 sets of data . Intersect : It will retrieve the data which is combination of 2 sets. Difference: It retrieve data that holds true in one table and not in the other. Join: Its the enhancement to the product operator.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
SQL
SQL is used to create and manipulate all database objects. SQL was developed by IBM in the year 1979. The SQL performs the following variety of tasks: Creating, Modifying and Deleting database objects Inserting, Updating and Deleting data Provides for data integrity and consistency Querying data. Controlling access to the database.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
SQL categories
Data Definition language (DDL) Data Manipulation Language (DML) Data Control Language (DCL). Transaction Control language (TCL) Data Retrieval Languae.
5/2/2012 9:50 PM
DDL
Commands of DDL. CREATE ALTER DROP RENAME TRUNCATE
FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
DML
Commands of DML: INSERT UPDATE DELETE MERGE
5/2/2012 9:50 PM
TCL
Commands of TCL: COMMIT ROLLBACK SAVEPOINT
5/2/2012 9:50 PM
DCL
Commands of DCL: GRANT REVOKE Data Retrieval Language Command: SELECT
5/2/2012 9:50 PM
Data types
Date represent date & time from 01-Jan4712 B.C to 31-Dec-9999 AD. Time Stamp Precision point time regarding seconds/ milliseconds/ CLOB character based large objects can be stored max size 4 gb. BLOB Binary based large objects can be stored upto a max size of 4 Gb.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Number (p,s) Number having precision p and scale s. The precision p can range from 1 to 38. The scale s can range from -84 to 127. BINARY_FLOAT 32 bit single precision float data types requires 5 bytes and max value is 1.79 e 308. Binary _Double 64 bit double precision float data types requires 5 bytes and max value is 3.4 e 38.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Data types
Create command
It is used to create an object (table). Syntax: create table <table name>(column name data type constraint, ); Ex: create table student(st-no char(3), st_name varchar2(20), course vrchar2(20), Fees number(5));
5/2/2012 9:50 PM
Describe command
It is used to see the structure of the object (table). Syntax: Describe <table name>; Ex: Describe student; Or Desc student; It will show the structure of the table.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Insert command
Syntax: 1.Insert into <tablename> (column 1,.) Values( actual values for columns); 2. insert into <tablename> values( actual values for all columns in the order of creation);
5/2/2012 9:50 PM
Update command
It is used to update or edit the data in the table. Syntax: Update <table name> set < columnname > = new value, where clause; Ex: update student set course='Java', fees=5500 where rolno='21';
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Delete command
It is used to delete data from the table. Syntax : Delete <table name> where clause; Ex: delete student where rolno='8';
5/2/2012 9:50 PM
Operators
Operators are used to perform certain operations on the data or objects. Arithmetic operators. Logical Opertors. Relational operators.
5/2/2012 9:50 PM
Arithmetic Operators
+ * (multiplication) / (division)
5/2/2012 9:50 PM
Logical Operators
AND It is used to combine both must be true. Or It is used to either of any one can be true Not Its used to become false .
FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
5/2/2012 9:50 PM
Operators
LIKE Match a character pattern Ex: Select * from Emp where empname LIKE %Raju; ISNULL Is a null value Select * from Student where fee IS NULL;
5/2/2012 9:50 PM
String Functions
Upper(string) converts to uppercase. Ex: Select upper(empname) from emp; It will convert all employee names into uppercase. Lower(string) converts to lowercase. Initcap(string) converts intial letter of every word to uppercase.
Length(string) returns the length of string Substr(string,n,[m]) clips out of m character piece of string starting at position n. If m not given assumes end of the string. Ex: select substr(Abdul Raheem,7) from dual; It will get Raheem from the string.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Aggregate Functions
They are statistical functions to count , average on a set of attribute values to get a single value. Count It will count rows. Ex: select count* from Emp; It will get the number of rows in the Emp table.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Ex: select count(distinct desig )from Emp; It will bring out How many different job designations are in the table Emp. Max it will bring out maximum value from a column. Min it will bring out minimum value from a column. Ex: select min(sal), max (sal) from Emp; It will bring out max & min salaries from Emp 5/2/2012 9:50 PM FACULTY : SK ABDUL
YESDANI
Sum computes the sum of values in a column which are number data types. Ex: select sum(sal) from Emp where desig=engineer; It will get sum of the salaries paid to all engineers.
5/2/2012 9:50 PM
Number Functions
They will accept numeric input & return numeric values. Round(colm/ exprsion, n) rounds the given value to n decimal places. If n omitted there will be no decimal places. Trunc(colm/expresion, n) Truncate the given value to n decimal places, if n is omitted then n defaults to zero
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Mod(m,n) returns the reminder of m divided by n. Abs(n) returns the absolute value of n. Sqrt(n) returns square root of n. Pow(m,n) m will be raised to power of n Floor(n) adjust nearest small whole num. Ceil(n) adjust to nearest large whole num
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Date + number / 24 date adds a number of DAYS ( hours to DAY) a date. Ex: select ename , (sysdate hiredate)/7 as weeks_ago_ joined from emp where deptid=90;
5/2/2012 9:50 PM
Date functions
They operate on Oracle dates. All date functions returns a value of DATE data type except MONTHS_BETWEEN, which returns a numeric value. MONTHS_BETWEEN(date1, date2) find number of months between 2 dates. The non integer part of the result represents a portion of the month.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Date functions
ADD_MONTHS(date, n) adds n calender months to a date. NEXT_DAY(date, char) finds the date of the next specified day of the week (char) following date. The value of char may be a number representing a day or a character string. LAST_DAY(date) finds the date of the last day of the month from the date.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
ROUND(date,[fmt]) returns the date rounded to the unit specified by the formal model fmt. If the fmt is omitted , date is rounded to the nearest day. TRUNC(date,[fmt]) returns with the time portion of the day truncated to the unit specified by the format model fmt. If no fmt the date is truncated to nearest day.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
TO_CHAR(date) it will convert the date into string format. Ex: select TO_CHAR(sysdate, dd-Monyyyy) from dual; Ex: select To_Char(sysdate, dd-Mon-RR) from dual;
5/2/2012 9:50 PM
Primary Key
We can directly mention primary key constraint to a table while creating the table. Syntax: create table <tablename>(column1,,<constraint > [constraint name ] <constraint type> (column name to which constraint applied));
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Primary key
Ex:create table dept1(dno char(4), dname varchar2(30), constraint dno_pk primary key(dno)); OR
5/2/2012 9:50 PM
Primary key
Syntax2:Create table <table name> (<column1 > <datatype> <constraint> [constraint name] <constraint type>, column2,..); Ex:create table dept ( dept_id char(3) constraint dept_pk primary key, dept_name varchar2(20))
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Primary key
After creating the table without a primary key column we need to add a primary key constraint to the table. Ex: create table course(course_id char(3), coursename varchar2(30), fee number(5)); Alter table course add constraint course_pk primary key(course_id); It will add the primary key constraint to the course table.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Foreign key
Foreign key is used to create relationship between 2 relations . Syntax: create table <tablename>(column1, ,colum n, <references> <referenced tablename>(<colum name from referenced table>));
5/2/2012 9:50 PM
Foreign key
Ex:create table students (st_no char(3)primary key, st_name varchar2(30),j_date date, course_id char(3) references course(course_id));
5/2/2012 9:50 PM
Alter Command
Its used to alter a table structure. We can add a new column, constraint to an existing table. We can modify the column data types , size of the column data type etc. We can drop columns, drop constraints of a table.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Alter
Adding a new colum to an existing table structure. Syntax: alter table <tablename> add (new column name data type); Ex: alter table dept add( location varchar2(30));
5/2/2012 9:50 PM
Alter
Dropping a column Sysntax: Alter table <table name> drop column <column name> ; Example: alter table dept drop column location;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Alter
Modifying the data type or size of columns in the table . Syntax: alter table <table name> modify <column name> <new data type (size)> ; Ex: alter table dept1 modify dname char(20); It will changes the dname column data type to char(20).
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Alter
Adding constraints to the table with alter. Syntax: Alter table <table name> add constraint <constraint name > <constraint type> (<column name>); Ex: alter table dept add constraint did_pk primary key (deptid);
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
alter
Dropping the constraint of a table / column. Syntax: Alter table <table name> drop constraint <constraint name>; Ex: alter table dept drop constraint did_pk;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Alter
Adding a check constraint to a column. Check constraint is used to limit values between a range / or to do some validation. Ex: Alter table dept add constraint chk check(deptid between 101 and 909);
5/2/2012 9:50 PM
Queries
A query is an operation that retrieves data from one or more tables or views. In this reference, a top-level SELECT statement is called a query, and a query nested within another SQL statement is called a sub query. Ex: select empid, empname, salry, desig from employee where empid =109;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
joins
To execute a join of three or more tables, Oracle first joins two of the tables based on the join conditions comparing their columns and then joins the result to another table based on join conditions containing columns of the joined tables and the new table. Oracle continues this process until all tables are joined into the result. The optimizer determines the order in which Oracle joins tables based on the join conditions, indexes on the tables, and, any available statistics for the tables.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Types of joins
Equijoin: An equijoin is a join with a join condition containing an equality operator. An equijoin combines rows that have equivalent values for the specified columns.
5/2/2012 9:50 PM
Equijoin example
SELECT last_name, job_id, departments.department_id, department_name FROM employees, departments WHERE employees.department_id = departments.department_id;
5/2/2012 9:50 PM
Self Joins
Self join is used to create a query on a single table . The following query uses a self join to return the name of each employee along with the name of the employee's manager. A WHERE clause is added to shorten the output.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
SELECT e1.last_name||' works for '|| e2.last_name Employees and Their Managers FROM employees e1, employees e2 WHERE e1.manager_id = e2.employee_id AND e1.last_name LIKE 'R%';
5/2/2012 9:50 PM
Sub Queries
subquery answers multiple-part questions. For example, to determine who works in Taylor's department, you can first use a subquery to determine the department in which Taylor works. You can then answer the original question with the parent SELECT statement.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
A subquery in the FROM clause of a SELECT statement is also called an inline view. A subquery in the WHERE clause of a SELECT statement is also called a nested subquery. A subquery can contain another subquery.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
To define one or more values to be assigned to existing rows in an UPDATE statement. To provide values for conditions in a WHERE clause, HAVING clause, or START WITH clause of SELECT, UPDATE, and DELETE statements.
5/2/2012 9:50 PM
5/2/2012 9:50 PM
Select * from emp where deptno in( Select deptno from dept where Loc=Hyderabad); It will list all employees who are working in department(s) located in Hyderabad.
5/2/2012 9:50 PM
Grouping
With GROUP BY clause we can group rows witch have certain properties & then applying an aggregate function on one column for each group separately. This clause appears after the where clause and must refer to columns of tables listed in the from clause
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Example
select dno,avg(salry) from employees group by dno; It will extract average salary of all depts. Select dno, count(eno) from employees where dno in(111,114) group by dno; It will return no.of employees working in dnos 111 & 114.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Select dno, sum(salry) from employees where salry >0 group by dno; It will calculate total salry for each department.
5/2/2012 9:50 PM
Views
View is a logical subsets or combination of data by creating views of tables. A view can be logical table based on a table or another view. It contains no data of its own but its like a window by which data from tables can be viewed of changed. The tables on which a view is based are called base tables.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
The view is stored as a select statement in the data dictionary. View s are useful to restrict data access and to make complex queries. To provide data independence. To present different views of the same data.
5/2/2012 9:50 PM
Types of views
Simple views Complex views
5/2/2012 9:50 PM
Featyres simple view No.of tables One Functions No Groupsof data No DML operations through view Yes
5/2/2012 9:50 PM
Creating views
Syntax: CREATE [OR REPLACE] [FORCE] [NOFORCE] VIEW viewname AS subquery [WITH CHECK OPTION [CONSTRAINT]] [ WITH READ ONLY [CONSTRAINT]];
5/2/2012 9:50 PM
OR REPLACE Recreate already existing view. FORCE creates the view regardless of whether base table exists or not. NOFORCE creates the view if the base table exists , its default. WITH CHECK OPTION specifies only rows accessible to the view can be inserted /updated
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
WITH READ ONLY ensures that no DML operations can be performed on the view. Example : Create view empview80 as select empid, name, salry from employee where deptid =80;
5/2/2012 9:50 PM
create view sal_view as select ename, salary, did from employee where did in('a01','c01'); Extracting the data from view: Syntax: Select < columnames > from view name; select * from sal_view
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Modifying a view
Syntax : Create or replace view < viewname> as select < columnames> from <tablename > <where clause> Ex: create or replace view sal_view as select eid,ename, salary, did from employee where did='d01;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
Top N Analysis
Syntax:
Example: select rownum as rank, ename, salary from (select ename, salary from employee order by salary asc) where rownum <=6
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Continued
These logical blocks can contain any number of nested sub blocks. Generally each block corresponds to a problem or sub problem to be solved. So, PL/SQL supports divide & conquer approach to problem solving called stepwise refinement.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
Advantages of PL/SQL
PL/SQL is completely portable, high performance transaction processing language . Supports for SQL. Supports Object-Oriented Programming. Better Performance &Tight Security. Tight integration with Oracle.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Continued.
We can use all SQL commands and functions, operators and pseudo columns. So, we can manipulate data flexibly and safely. It supports all SQL data types and it reduces the need to convert data passed between front end application and data base.
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
Important Operators
+ , -, *, / ** Exponentiation operator. % attribute indicator. : host variable indicator. ; statement terminator. := Assignment operator => association operator
FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
Continued..
|| Concatenate operator < > , != , ^ = relational (Not equal to) = relational (Equal to) > , <, >=, <=, -- single line comment /* ..*/ multi line comments
FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
5/2/2012 9:50 PM
IF-THEN
IF condition THEN Block of statements END IF; Example: IF sales > quota THEN compute_bonus(empid); UPDATE payroll SET pay = pay+bonus where empno = empid; END IF;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
IF-THEN-ELSE
IF condition THEN Blok of statements1; ELSE Block of statements 2; END IF;
5/2/2012 9:50 PM
Continue
Example: IF trans_type =CR THEN UPDATE accounts SET balance = balance+ credit where account _no = act_id; ELSE UPDATE accounts SET balance = balancedebit where account _no = act_id; END IF;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
IF-THEN-ELSEIF
BEGIN IF condtion1 THEN block of statements; ELSEIF conditionn2 THEN block of statements; ELSE block of statements; END IF; END;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Continued
BEGIN IF sales >60000 THEN bonus := 1800; ELSEIF sales >40000 THEN bonus := 1000; ELSE bonus := 500; END IF; Insert into payroll values(empid,bonus,.); END;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
CASE
Example: CASE grade WHEN A THEN Salary := 40000; WHEN B THEN Salary := 30000; WHEN C THEN Salary := 25000; WHEN D THEN Salary := 20000; END CASE;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
Loop
LOOP IF credit_rating <3 THEN Exit; -- Exits loop immediately END IF; END LOOP; --Control resume here
FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
5/2/2012 9:50 PM
WHILE - LOOP
1.WHILE condition LOOP sequence of statements END LOOP; Example: WHILE total <=25000 LOOP SELECT sal INTO salary from emp whree..; total := total+salary; END LOOP;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
FOR - LOOP
FOR counter IN [REVERSE] lower bound . Upperbound LOOP sequence of statements; END LOOP; Ex: FOR i IN REVERSE 1..3 LOOP -assigns values 3,2,1 to I total := total +200; -- executes 3 times END LOOP;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
COLLECTIONS
A collection is an ordered group of elements of same type. Its a general concept that contains lists, arrays and other data types. Each element has a unique subscript that determines its position in the collection.
5/2/2012 9:50 PM
Continue..
To create collections, U define a collection type, then declare variables of that type. U can define table and VARRAY types in the declarative part of any PL/SQL block, subprogram, or package
5/2/2012 9:50 PM
Collection EXample
DECLARE TYPE EmpTabTyp IS TABLE OF emp%ROWTYPE INDEX BY BINARY_INTEGER; emp_tab EmpTabTyp; BEGIN select * INTO emp_tab(6754) from emp where empno=6754; END;
5/2/2012 9:50 PM FACULTY : SK ABDUL YESDANI
5/2/2012 9:50 PM
5/2/2012 9:50 PM
PROCEDURES
Use the CREATE PROCEDURE statement to create a standalone stored procedure or a call specification. A procedure is a group of PL/SQL statements that you can call by name.
5/2/2012 9:50 PM
A call specification (sometimes called call spec) declares a Java method or a thirdgeneration language (3GL) routine so that it can be called from SQL and PL/SQL. The call spec tells Oracle Database which Java method to invoke when a call is made.
5/2/2012 9:50 PM
It also tells the database what type conversions to make for the arguments and return value. Stored procedures offer advantages in the areas of development, integrity, security, performance, and memory allocation.
5/2/2012 9:50 PM
5/2/2012 9:50 PM