Script Writing. Objectives: Definition of script writing Types of script Creating/Modification and running script Execution of script Fundamental of Script.

Slides:



Advertisements
Similar presentations
BD05/06 PL/SQL  Introduction  Structure of a block  Variables and types  Accessing the database  Control flow  Cursors  Exceptions  Procedures.
Advertisements

Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
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.
PL/SQL.
Stored Procedure Language Stored Procedure Overview Stored Procedure is a function in a shared library accessible to the database server can also write.
PL/SQL (Procedural Language extensions to SQL) Prepared by: Manoj Kathpalia Edited by: M V Ramakrishna.
Lecture-5 Though SQL is the natural language of the DBA, it suffers from various inherent disadvantages, when used as a conventional programming language.
Sequential Statements Module F3.2. Sequential Statements Statements executed sequentially within a process If Statements Case Statements Loop Statements.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Using Oracle PL/SQL PL/SQL stands for Procedural Language/SQL. PL/SQL extends SQL by adding constructs found in procedural languages, resulting in a structural.
PL/SQL The Oracle Programming Language. Purpose SQL is a non-procedural language. Often we need to put structure on transactions, so we use the supplemental.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
Objectives Why PL-SQL ? Language features
PL/SQL Introduction Database 1. Practice. Sample Database The schema of the sample database is the following: Drinkers (name, occupation, birthday, salary)
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.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
SQL Training Procedures & Functions. Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. DB Procedures & Functions Procedures and Functions.
1 Introduction to PL/SQL. 2  Procedural programming language  Uses detailed instructions  Processes statements sequentially  Combines SQL commands.
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.
Oracle10g Developer: PL/SQL Programming1 Objectives Programming fundamentals The PL/SQL block Define and declare variables Initialize variables The NOT.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 2 Basic PL/SQL Block Structures.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
Distributed Database Applications COSC 5050 Week One.
PL/SQL A BRIEF OVERVIEW DAVID WILSON. PL/SQL User’s Guide and Reference PL/SQL User’s Guide and Reference.
PL SQL Block Structures. What is PL SQL A good way to get acquainted with PL/SQL is to look at a sample program. PL/SQL combines the data manipulating.
Program with PL/SQL Lesson 4. Writing Control Structure.
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
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:
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
PL/SQL Declaring Variables PL/SQL Block Structure DECLARE (Optional) Variables, cursors, user-defined exceptions BEGIN (Mandatory) - SQL statements -
PL/SQL. Introduction to PL/SQL block Declare declarations Begin executable statement Exception exception handlers End;
Database Application Development using PL/SQL Programming.
Bordoloi and Bock Control Structures: Iterative Control.
Copyright  Oracle Corporation, All rights reserved. 16 Declaring Variables.
CSC115 Introduction to Computer Programming Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383
Oracle 8i Exception Handling. General Syntax DECLARE --- BEGIN --- EXCEPTION WHEN exception_name1 THEN -Error handling statements WHEN exception_name2.
Chapter Seventeen Subprogramming Objective: –Procedures –Functions –Packages.
Advanced SQL: Cursors & Stored Procedures Instructor: Mohamed Eltabakh 1.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
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.
Database An introduction to using Oracle PL/SQL An introduction to using Oracle PL/SQL An introduction to using Oracle PL/SQL Definition: PL/SQL.
CS422 Principles of Database Systems Oracle PL/SQL Chengyu Sun California State University, Los Angeles.
Oracle 数据库应用 -- PL/SQL 进阶 (3) & Oracle DBA 2016/5/ /5/10.
C LANGUAGE MULITPLE CHOICE QUESTION SET-2
Program with PL/SQL Lesson 4.
Difference between Oracle PL/SQL and MySQL
Fundamentals of PL/SQL part 1 (Basics)
Oracle11g: PL/SQL Programming Chapter 2 Basic PL/SQL Block Structures.
Database Programming PL SQL.
SQL PL/SQL Presented by: Dr. Samir Tartir
PL/SQL – Session 1 of 4 Instructor: Jim Cody
جمل التحكم المحاضرة التاسعة T.Eman Alsqour.
جمل التحكم.
Arrays, For loop While loop Do while loop
Sequential Statements
Sa0951a PL/SQL 1: Introduction
Chapter 2 Handling Data in PL/SQL Blocks Oracle9i Developer:
PL/SQL week10.
Java Programming Review 1
PL/SQL Declaring Variables.
Stored Procedure Language
Database Programming Using Oracle 11g
Database Programming Using Oracle 11g
Database Programming Using Oracle 11g
Presentation transcript:

Script Writing

Objectives: Definition of script writing Types of script Creating/Modification and running script Execution of script Fundamental of Script Sequential and conditional control Iteration process

Facts: Procedural language is called PL/SQL Highly structured Embedded language Powerful exception handling Other programs may call PL/SQL 3

Script writing: 1. Unnamed Blocks 2. Procedures 3. Functions 4

PL/SQL Basic: Comments --(single line) /* */ (Multi line) Rem 5

PL/SQL Basic: Identifiers Constant Variables Exceptions Cursors Functions/Procedures Packages 6

Unnamed Blocks: [DECLARE] [Declarations] BEGIN [Execution Statements] [NULL;] END; / 7

Example: BEGIN NULL; END; / 8

Declarations: Variable Type [NOT NULL] [:= | Default] Value; OR Variable Type%TYPE; 9

Data Type: BOOLEAN CHAR CHARACTER STRING VARCHAR2 NUMBER DEC DECIMAL FLOAT INT 10

Data Type (More…) INTEGER SMALLINT REAL BINARY_INTEGER POSITIVE DATE 11

EXAMPLE: DECLARE Is_TrueBOOLEAN; FlagBOOLEAN := FALSE; B_DateDATE; TodayDATE := SYSDATE; TotalINTEGER; Sum1INTEGER := 20; Sum2INTEGER DEFAULT 20; CreditINTEGER RANGE ; GradeNUMBER(3, 2) NOT NULL :=1.00; ANUMBER :=Sum1 * 3; BB_Date%TYPE; S_IDStudent.ID%TYPE; S_RecStudent%TYPE; 12

CONSTANTS: DECLARE No_Days_Per_YearCONSTANTSINTEGER:=366; Max_No_StudentCONSTANTSINTEGER:=22; RegisteredCONSTANTSBOOLEAN:=FALSE; I_GradeCONSTANTSCHAR := ‘I’; GradeCONSTANTSCHARDEFAULT ‘o’; 13

NULL Value in Declaration: Max_No_StudentINTEGER (4) NOT NULL := 1000; ZipcodeINTEGER NOT NULL := 21532; 14

Example: DECLARE TOTALINTEGER;--? TotalINTEGER;--? BEGIN Total :=24; --Errors END; / 15

Expression: ** +, - (unary) *, / +,- >, >=, =, <>, <=, IN, LIKE, IS NULL NOT AND OR SYSDATE – B_Date/365;--? 16

Example: DECLARE AINTEGER; BBOOLEAN; CINTEGER := 5; BEGIN A :=10; B := C+2 = A; END; / 17

Load Data into Variables: DECLARE Field1Faculty.Name%TYPE; Field2Faculty.ID%TYPE; Field3Faculty.Salary%TYPE; BEGIN SELECT Name, ID, Salary INTO Field1, Field2, Field3 FROMFaculty WHERE ID=1111; DBMS_OUTPUT.PUT_LINE (‘Name: ’ || Field1 || ‘ ID: ’ || Field2); END; / 18

Load Data into Variables: DECLARE MyNameFaculty.Name%TYPE; MySalaryFaculty.Salary%TYPE; BEGIN SELECTName, Salary, SSN INTOMyName, MySalary FROMID=11111; DELETE FROM Faculty WHEREName = MyName; END; / 19

Conditional Statement: One way Selection: IF condition THEN action ; END IF; Two way Selection: IF condition THEN action_1; ELSE action_2; END IF; 20

Conditional Statement: Multiple way Selection: IF condition THEN action_1; ELSIF condition THEN action_2; …… ELSE action_3 END IF; 21

Example: DECLARE aNUMBER(2) := 22; bNUMBER(2) :=44; cVARCHAR2 (20); BEGIN IF a IS NULL OR b IS NULL THEN c:=‘Empty’; END IF; IF a>=b THEN c:=‘a is the largest’; ELSE c:=‘a is the smallest’; END IF; DBMS_OUTPUT.PUT_LINE(c); END; / 22

Example DECLARE ScoreNUMBER; GradeCHAR(1); BEGIN …….. ……… IF Score>=90 THEN Grade :=‘A’; ELSIF Score>=80 THEN Grade: =‘B’; ELSIF Score>=70 THEN Grade:=‘C’; ELSE Grade :=‘F’; END IF; DBMS_OUTPUT.PUT_LINE(Grade); END; / 23

Simple Iteration: LOOP statements; END LOOP; 24

Example: DECLARE iBINARY_INTEGER :=0; NumNUMBER:=4; BEGIN LOOP i:=i+1; Num := Num+2; IF i=5 THEN EXIT; END IF; DBMS_OUTPUT.PUT_LINE(Num); END LOOP; END; / 25

WHILE LOOP: WHILEconditionLOOP statement(s); END LOOP; 26

Example DECLARE iBINARY_INTEGER :=0; NumNUMBER:=4; BEGIN WHILE i<>5 LOOP Num := Num+2; i:=i+1; END LOOP; DBMS_OUTPUT.PUT_LINE(Num); END; / 27

FOR LOOP: FORindex IN[REVERSE] exp..exp LOOP statement(s); END LOOP; 28

Example DECLARE iBINARY_INTEGER ; BEGIN FOR i IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(i); END LOOP; END; / 29

Example – REVERSE: DECLARE iBINARY_INTEGER ; BEGIN FOR i IN REVERSE 1..5 LOOP DBMS_OUTPUT.PUT_LINE(i); END LOOP; END; / 30