7
Contents DBMS RDBMS DBMS Based Storage Approach OS File System Storage Based Approach Relational Model SQL (Structured Query Language) Tables Data Types Simple Queries Select Query Selecting Columns Selection of Tuples Relational operators in sql Logical operators in sql Create table command Constraints Inserting values into table String Operations Aggregate Functions Update statement Delete tuples from table Deleting a Table Alter table command Commit and Rollback Complex Queries Joining Relations Subqueries Operations on Result Sets union intersect

Nitin Tyagi

Embed Size (px)

DESCRIPTION

bggh

Citation preview

Contents DBMS RDBMS DBMS Based Storage Approach OS File System Storage Based Approach Relational Model SQL (Structured Query Language) Tables Data Types Simple Queries Select Query Selecting Columns Selection of Tuples Relational operators in sql Logical operators in sql Create table command Constraints Inserting values into table String Operations Aggregate Functions Update statement Delete tuples from table Deleting a Table Alter table command Commit and Rollback Complex Queries Joining Relations Subqueries Operations on Result Sets union intersect minus Group by clause Views Sequence & Synonym Introduction of PL/SQL

Introduction PL/SQL (Procedural Language/SQL) is a procedural extention of oracle-SQL that offers language constructs similar to those in imperative programming language. PL/SQL allows its users to develop complex database applications that require the usage of control structure & procedural elements such as procedures, function, modules etc.

PL/SQL Block: A PL/SQL block is a set of related procedural SQL statements, delimited by the reserved words BEGIN & END. PL/SQL supports two types of block:-i)Anonymous blocksii)Named blocks

Anonymous blocks: Anonymous blocks are the blocks without headers. Anonymous blocks do not form the body of a procedure function or trigger.

Named blocks: Named blocks are the block having headers or labels, Named blocks can either be sub programs (procedures, function, packages) or triggers (specialized block that initiate some action before or after some data is manipulated in a table).

Variable: A variable declaration requires valid name & data-type information. Variable declaration in PL/SQL are contained in its DECLARE section. When a variable is declared using the CONSTANT keyword, its values cannot be changed after it has been defined PL/SQL supports there type of variables:-i)Local variable:- These variable are declared in the DECLARE block of PL/SQL code.ii)Substitution variable:- These variable get declared automatically by prefixing the & sign to the variable. These variable used for data input at suntime.iii) Bind variable:- These variable can be declared in SQL*Plus (at SQL > prompt) & are refrred to in PL/SQL program using the : as prefix.

Use of % type attribute: % The ROWTYPE attribute can be used to declare a composite variable that can store all the data associated with a single row of a table or a query.Use of % type attribute: % type is used to retrieve a data-type from database. The variable declared with a % type attribute are called anchored variables. An anchored data type find its use in declaring variable thats can hold data being read from a database or from a predefined variable.Use of Select into Statement:- A PL/SQL program is not allowed to send the data generated by a SELECT statement, directly to the output. A SELECT INTO statement helps in the situation by storing the data coming from tables into memory variables, which can later be displayed or used for further processing.A SELECT INTO statement can be used with those queries that generate exactly one row. If the number of rows generated is either less or greater than one, an exception is raised. To process the queries that might generate zero or multiple rows a cursor can be used.Coments:- Coments are statements that are ignored by the compiler & are used to enhance program readability. PL/SQL supports two ways of adding comments:- Single line comments:- These comments start with sign_ _ Multiline Comments:- These comments start with/ * & end with * /

SELECTION STATEMENT:

IF ThenStatement blockEND IF;This form of the 1F statement is used to control whether a code block should be executed or not. Here, the statement block 1 executes if the condition is true. IF ThenStatement block 1ELSEStatement block 2 END IF;This form of the 1F statement is used to choose which block out of two given block should be executed. Here, if condition is true, block 1 executes otherwise block 2 execute. IF ThenStatement block 1 ELSE IF THENStatement block 2ELSE IF THENStatement block 3ELSEStatement block 4END IF;This form of the If statement is used to choose one out of variable mutually exclusive choices. Here, the block, which is associated with the condition that evaluates to true, is executed. If none of the conditions is true, then the block associated with the ELSE part is executed.

LOOPING STRUCTURE:-a) Simple Loop:- LOOP. . .END LOOP. This construct creates an infinite loop by default. In order to terminate this loop, we can use the EXIT statement.eg:- . . .I:=1;LOOPSum:= Sum + I;I:= I + 1;EXIT WHEN I > 10;END LOOP;. . .b) Numeric FOR LOOP:- This looping construct is used to repeat a set of instruction for a fixed number of times.Eg: FOR I IN 1. . .10 LOOPSum:= Sum + 1END LOOP;c) WHILE LOOP:- This looping construct is used to repeat a set of statement till a condition holds good.Eg: . . .I : = 1;WHILE (I