introduction to database sql & pl/sql

16
Introduction to Database www.collaborationtech.co.in Bengaluru INDIA Presentation By Ramananda M.S Rao

Upload: collaboration-technologies

Post on 14-Feb-2017

114 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Introduction to Database SQL & PL/SQL

Introduction to Database

www.collaborationtech.co.inBengaluru INDIA

Presentation By Ramananda M.S Rao

Page 2: Introduction to Database SQL & PL/SQL

ContentContentOverviewDatabase ConceptsDatabase FundamentalsIntroduction to Database Management SystemsDifferent Models Three Layer ArchitectureData Independence, DDL, DML, DCL, Functions of DBA, DBM Introduction to ORACLE technology stack SQL LanguageIntroduction & Using SQL*PlusSQL History and Standards, SQL BasicsSQL Data TypesWriting Basic SQL statementsCreating and Managing TablesInsert, Update, Delete commandsAlter, Drop commandsSelect CommandConstraints

www.collaborationtech.co.in

Page 3: Introduction to Database SQL & PL/SQL

ContentSQL Operators and FunctionsSingle row functionsAggregating data using group functionsGroup By clause Set OperatorsJoinsCreating ViewsSubqueryNested QueriesCo-related Sub-queriesControlling user accessGrant and Revoke StatementsOptimization and Performance SQL Tuning

www.collaborationtech.co.in

Page 4: Introduction to Database SQL & PL/SQL

ContentER ModelAssignments on E-R Model E-R to Relational MappingAssignments on E-R to Relational Mapping Normalization Assignments on Normalization Using simple modeling ToolBuilding model for Simple ApplicationsSimple Fund Management exampleSimple Inventory exampleSimple Security examplePL/SQL Programming PL/SQL Variables and ConstantsUsing %TYPE and %ROWTYPE AttributesPL/SQL Variable ScopeCreating Anonymous PL/SQL BlockUsing DBMS_OUTPUT.PUT_LINEPL/SQL Control Structures and VariablesWriting Interactive PL/SQL programEmbedding SELECT Statement inside PL/SQL Block, Embedding DML Statements inside PL/SQL Block

www.collaborationtech.co.in

Page 5: Introduction to Database SQL & PL/SQL

ContentCursors and ExceptionsCursors - Definition Cursor Using Implicit and Explicit CursorsCursor Attributes, Cursor FOR loops, Parameterized CursorsFOR UPDATE and WHERE CURRENT OF with Explicit CursorsException Definition Handling user defined, Oracle predefined and non-predefined exceptions. Propagating exceptionsProcedures , functions and TriggersCreating Stored Procedures and functionsInvoking stored procedures Parameter Modes – IN, OUT and IN OUTCalling Stored Functions PackagesDefinition PackagesAdvantages of using PackagesComponents of a Package Creating and using Package

www.collaborationtech.co.in

Page 6: Introduction to Database SQL & PL/SQL

ContentTriggers - Definition TriggersDatabase Triggers Difference between Stored Procedure and Database TriggersTrigger Components and typesCreating and using Database TriggersObjects In database Objects Types and Using Object TableCreating and Using Collection TypesDynamic SQLNative Dynamic SQLUsing Packages like DBMS_OUTPUT, DBMS_PIPE, UTL_FILE, DBMS_SQLBulk statements in PL/SQLCreating Indexes

www.collaborationtech.co.in

Page 7: Introduction to Database SQL & PL/SQL

OverviewSQL stands for Structured Query Language. SQL is used to communicate with a database.SQL statements are used to perform tasks such as update

data on a database, or retrieve data from a database. SQL commands are divided into several different types,

among them data manipulation language (DML) and data definition language (DDL) statements, transaction controls and security measures.

The DML vocabulary is used to retrieve and manipulate data.

DDL statements are for defining and modifying database structures.

www.collaborationtech.co.in

Page 8: Introduction to Database SQL & PL/SQL

OverviewPL/SQL is an Oracle procedural extension for SQL. They

have designed this language for easy use of complex SQL statements.

PL SQL basically stands for "Procedural Language extensions to SQL".

It combines the data manipulation power of SQL with the processing power of procedural language to create a super powerful SQL queries.

Similar to other database languages, it gives more control to the programmers by the use of loops, conditions and object oriented concepts.

www.collaborationtech.co.in

Page 9: Introduction to Database SQL & PL/SQL

SQLSQL> create database studentSQL>show databaseSQL>create table employee(id int(11),ename varchar(45),address varchar(45),Dob date);SQL>insert into employee values(1,’raj’,’vijayanagar bengaluru’,’02-02-2017’);SQL>desc employeeSQL>select * from employeeSQL> update employee set ename=‘Sunilkumar' where id=1;SQL>DELETE FROM employee WHERE id=1;

www.collaborationtech.co.in

Page 10: Introduction to Database SQL & PL/SQL

SQLSQL>create table student(id int(11),sname varchar(45),address varchar(45),Dob date,age int(11));SQL>insert into employee values(1,’kumar’,’vijayanagar mysore’,’01-02-2017’,20);SQL>insert into employee values(2,’sunil’,’vijayanagar bangalore’,’05-02-2017’,25);SQL>desc studentSQL>select * from studentSQL> update student set ename=‘Anilkumar' where id=2;SQL>DELETE FROM student WHERE id=1;

SQL>create table customer(id int(11),cname varchar(45),address varchar(45),mno varchar(45));SQL>insert into customer values(1,’chetan’,’btm bangalore’,’9865324175’);SQL>insert into customer values(2,guru’,’rpc layout bangalore’,’9586231475’);SQL>desc customerSQL>select * from customerSQL> update customer set ename=‘Vishal' where id=2;SQL>DELETE FROM customer WHERE id=1;

Alter Command ALTER TABLE customer ADD Gender char(1);ALTER TABLE customer MODIFY Location char(100);

www.collaborationtech.co.in

Page 11: Introduction to Database SQL & PL/SQL

PL/SQLBEGINdbms_output.put_line(‘Hello World..’);END;\Declaring and usage of variables in programDECLAREtext VARCHAR2(45);BEGINtext:= ‘Hello World’;dbms_output.put_line(text);END;\

www.collaborationtech.co.in

Page 12: Introduction to Database SQL & PL/SQL

Ratiodeclarenumerator number;denominator number;the_ratio number;lower_limit constant number:=0.72;samp_num constant number:=132;BEGINSELECT X, Y INTO numerator, denominator from result_table where sample_id = samp_num;the_ratio := numerator/denominator;if the_ratio > lower_limit theninsert into ratio values(samp_num, the_ratio);ELSEInsert into ratio values (samp_num,-1);END IF;commit;exceptionwhen zero_divide theninsert into ratio values(samp_num,0);commit;when others then rollback; end;

www.collaborationtech.co.in

Page 13: Introduction to Database SQL & PL/SQL

WagesCREATE FUNCTION dept-sal (dnum NUMBER) RETURN NUMBER IS CURSOR emp-cursor ISoSELECT sal, comm FROM emp WHERE deptno = dnum;total-wages NUMBER(,(:=0;cnt NUMBER(10) :=1;BEGINFOR emp-record IN emp-cursor LOOPemp-record.comm := NVL (emp-record.comm, 0);total-wages := total-wages + emp.record, sal+emp-record-comm;PUT-LINE (LOOP number = '|| cnt ||', 'wages ='|| TO-CHAR (total-wages));cnt := cnt+1;ENDLOOP:/* Debug Line */PUT-LINE (Total wages ='|| TO-CHAR (total-wages));RETURN total-wages;END dept-sal:

www.collaborationtech.co.in

Page 14: Introduction to Database SQL & PL/SQL

Procedures and Functions in PL/SQLProcedure is a subprogram unit that consists of a group of PL/SQL statements.Procedure can have a RETURN tatement to return the control to the calling block, but it cannot return any values through the RETURN statement.CREATE OR REPLACE PROCEDURE welcome_msg(p_name IN VARCHAR2)ISBEGINDbms_output.put_line(‘Welcome’||p_name);END\EXEC welcome_msg(‘Collaboration Technologies’);

www.collaborationtech.co.in

Page 15: Introduction to Database SQL & PL/SQL

Follow us on SocialFacebook: https://www.facebook.com/collaborationtechnologies/Twitter : https://twitter.com/collaboration09Google Plus : https://plus.google.com/100704494006819853579LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545Instagram : https://instagram.com/collaborationtechnologiesYouTube : https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUgSkype : facebook:ramananda.rao.7WhatsApp : +91 9886272445

www.collaborationtech.co.in

THANK YOU

Page 16: Introduction to Database SQL & PL/SQL

About Us