Difference between Oracle PL/SQL and MySQL

Slides:



Advertisements
Similar presentations
PL/SQL.
Advertisements

BD05/06 PL/SQL  Introduction  Structure of a block  Variables and types  Accessing the database  Control flow  Cursors  Exceptions  Procedures.
AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
PL/SQL. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
SQL*PLUS, PLSQL and SQLLDR Ali Obaidi. SQL Advantages High level – Builds on relational algebra and calculus – Powerful operations – Enables automatic.
INTRODUCTION TO ORACLE Lynnwood Brown System Managers LLC Introduction to PL/SQL – Lecture 6.
Murali Mani Persistent Stored Modules (Stored Procedures) : PSM.
Chapter 4B: More Advanced PL/SQL Programming
PL/SQL Agenda: Basic PL/SQL block structure
Oracle PL/SQL Eyad Husni Elshami. Why PL/SQL Block Structures: – PL/SQL consists of blocks of code, which can be nested within each other. Each block.
Programming in Oracle with PL/SQL
Advanced SQL: Stored Procedures Instructor: Mohamed Eltabakh 1.
Bordoloi and Bock PROCEDURES, FUNCTIONS & TRIGGERS.
Introduction to PL/SQL Chapter 9. Objectives Explain the need for PL/SQL Explain the benefits of PL/SQL Identify the different types of PL/SQL blocks.
Dr. James Dullea, CSC8490 Introduction to PL/SQLSlide 1 of 36 7From Prof. Dullea CSC8490 Introduction to PL/SQL Module 01-9 Revised: June 12, 2005 Dr.
Introduction to PL/SQL. Procedural Language extension for SQL Oracle Proprietary 3GL Capabilities Integration of SQL Portable within Oracle data bases.
Session Title: Using SQL and PL/SQL for Queries and Reporting Presented By: Stephen Frederic Institution: IHL September 16, 2013.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
Stored Procedures Functions Packages
 Allows sophisticated data processing  Build complex business logic in a modular fashion  Use over and over  Execute rapidly – little network traffic.
Lecture 4 PL/SQL language. PL/SQL – procedural SQL Allows combining procedural and SQL code PL/SQL code is compiled, including SQL commands PL/SQL code.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
Session Title: Using SQL and PL/SQL for Queries and Reporting Presented By: Stephen Frederic Institution: IHL September 16, 2014.
Advanced SQL: Cursors & Stored Procedures
CS178 Database Management PL/SQL session 8 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman.
PL / SQL By Mohammed Baihan. What is PL/SQL? PL/SQL stands for Procedural Language extension of SQL. PL/SQL is a combination of SQL along with the procedural.
PL/SQL Oracle's Database Programming Language. Remember: Set serveroutput on With serveroutput off (default) executing procedure: With serveroutput on:
PL/SQL Procedural Language / Structured Query Language.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
PL/SQL. Introduction to PL/SQL block Declare declarations Begin executable statement Exception exception handlers End;
School of Computing and Management Sciences © Sheffield Hallam University SQL is non-procedural –designed to be relatively approachable to non- programmers.
Stored Procedures. Definition a stored procedure is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
ITEC 224 Database Programming PL/SQL Lab Cursors.
1 Handling Exceptions Part F. 2 Handling Exceptions with PL/SQL What is an exception? Identifier in PL/SQL that is raised during execution What is an.
Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 
CREATING STORED PROCEDURES AND FUNCTIONS. Objectives After completing this lecture, you should be able to do the following: Differentiate between anonymous.
DATABASE PROGRAMS CS 260 Database Systems. Overview  Introduction  Anonymous blocks  Oracle’s PL/SQL language basics  Conditions and loops  Cursors.
Chapter 18: Exception Handling1 Chapter Eighteen Exception Handling Objective: – Define exceptions – List types of exception handlers – Trap errors – Exception.
Handling Exceptions. Objectives What is exception Types of exceptions How to handle exceptions Trapping pre defined oracle errors.
A procedure is a module performing one or more actions; it does not need to return any values. The syntax for creating a procedure is as follows: CREATE.
Copyright  Oracle Corporation, All rights reserved. 23 Handling Exceptions.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Introduction to PL/SQL Francis Thottungal. The outline The basic PL/SQL code structure is : DECLARE -- optional, which declares and define variables,
Advanced SQL: Cursors & Stored Procedures Instructor: Mohamed Eltabakh 1.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Overview.
Introduction to PL/SQL N. Dimililer. About PL/SQL –PL/SQL is an extension to SQL with design features of programming languages. –Data manipulation and.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
Creating Stored Procedures and Functions
PL/SQL.
UNIT - V STORED PROCEDURE.
Handling Exceptions.
SQL PL/SQL Presented by: Dr. Samir Tartir
PL/SQL Scripting in Oracle:
Oracle Stored Procedures and Functions
Advanced PL/SQL Programing
Handling Exceptions.
PL/SQL week10.
CS122B: Projects in Databases and Web Applications Winter 2018
PL/SQL Declaring Variables.
CS122B: Projects in Databases and Web Applications Spring 2018
Chapter 8 Advanced SQL Pearson Education © 2009.
Oracle Stored Procedures and Functions
CS122B: Projects in Databases and Web Applications Winter 2019
Presentation transcript:

Difference between Oracle PL/SQL and MySQL

MySQL PL/SQL control statements

PL/SQL Introduction PL/SQL is a combination of SQL along with the procedural features of programming languages. Basic Syntax of PL/SQL which is a block-structured language; this means that the PL/SQL programs are divided and written in logical blocks of code. Each block consists of three sub-parts

Pl/SQL Block structure

Pl/SQL Block structure Explanation Sections Description Declarations This section starts with the keyword DECLARE. It is an optional section and defines all variables, cursors, and other elements to be used in the program. Executable Commands This section is enclosed between the keywords BEGIN and END and it is a mandatory section. It consists of the executable PL/SQL statements of the program. It should have at least one executable line of code. Exception Handling This section starts with the keyword EXCEPTION. This optional section contains exception(s) that handle errors in the program.

The 'Hello World' Example DECLARE Message varchar(20):= 'Hello World!'; BEGIN dbms_output.put_line(Message); END; /

PL/SQL blocks are of mainly two types. Types of PL/SQL block PL/SQL blocks are of mainly two types. Anonymous blocks Named Blocks

Unnamed block Examples Not possible in MySQL but possible with oracle SQL

Unnamed block in oracle SQL> set serveroutput on; // to show output on screen SQL> declare // For loop 2 A number:=1; 3 begin 4 for A in 1..10 loop 5 dbms_output.put_line(A); 6 end loop; 7 end;

Unnamed block in oracle SQL> declare // if-else 2 a number(4); 3 begin 4 for a in 5..15 loop 5 if mod(a,5)=0 then 6 dbms_output.put_line(a); 7 else 8 dbms_output.put_line('value'||a); 9 end if; 10 end loop; 11 end;

Named block Examples: Procedures Functions

Some basic difference in PL/SQL (Oracle & MySQL) set serveroutput on; Delimiter // dbms_output.put_line Not available in MySQL Unnamed block Named block: Stored procedure and function Cursor: Implicit, Explicit Cursor: only Explicit Trigger: Row level and statement level Trigger: Row level

Procedure syntax CREATE [OR REPLACE] PROCEDURE procedure_name [ (parameter [,parameter]) ] as [declaration_section] BEGIN executable_section [EXCEPTION exception_section] END CREATE [OR REPLACE] PROCEDURE procedure_name [ (parameter [,parameter]) ] [declaration_section] BEGIN executable_section [EXCEPTION exception_section] END

Procedure Example and running the procedure SQL> Set Server output on; SQL> create or replace procedure delcust(id number)as begin delete from cust where cid=id; end; /   SQL> exec delcust(1); MySQL> delimiter // MySQL>create procedure delcust(IN id int(3)) begin delete from cust where cid=id; end; // MySQL> delimiter ; MySQL>call delcust(1) ;

Function Example SQL> create or replace function Rname(rno1 number)return varchar is sname stud.name%type; Begin select name into sname from Stud where rno=rno1; return sname; end; SQL> select Rname(1)from dual; mysql> create function Rname(rno1 int)returns varchar begin declare sname varcahr(20); select name into sname from Stud where rno=rno1; return sname; end; mysql> select Rname(1) ;

Cursor Example MySQL>call Stud1(); SQL> declare cursor c1 is select rno,name from stud; rno1 stud.rno%type; name1 stud.name%type; begin open c1; loop fetch c1 into rno1,name1; exit when c1%notfound; dbms_output.put_line(cust1.cid ||' '|| cust1.name); end loop; close c1; end; MySQL>CREATE PROCEDURE Stud1()  BEGIN    DECLARE c1 CURSOR FOR select rno,name from stud; DECLARE rno1 int(3);    DECLARE name1 varchar(20);    DECLARE exit_loop BOOLEAN;    DECLARE CONTINUE HANDLER FOR NOT FOUND SET exit_loop = TRUE;   OPEN c1;   emp_loop: LOOP     FETCH  c1 INTO rno1,name1;           select rno1,name1;           IF exit_loop THEN          CLOSE c1;          LEAVE emp_loop;      END IF;    END LOOP emp_loop;  END MySQL>call Stud1();

Trigger Example SQL> create trigger t1 after insert on emp for each row when(new.sal>10000) begin insert into emphigh values(:new.ename,:new.sal); End; / MySQL> create trigger t1 after insert on emp for each row begin IF NEW.sal >10000 THEN insert into emphigh values(new.ename,new.sal); End; /