PL/SQL Writing Executable Statements. PL/SQL Block Syntax and Guidelines Statement can be split across lines, but keywords must not be split Lexical units.

Slides:



Advertisements
Similar presentations
PL/SQL.
Advertisements

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.
Advanced Package Concepts. 2 home back first prev next last What Will I Learn? Write packages that use the overloading feature Write packages that use.
JavaScript, Fourth Edition
Chapter 2: Introduction to C++.
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
SQL enables us to create, organize, retrieve and maintain data stored in database it does not provide the features which a typical programming language.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Module 1: Introduction to Transact-SQL
Input, Output, and Processing
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Introduction to Scheme Lectures on The Scheme Programming Language, 2 nd Ed. R. Kent Dybvig.
L/O/G/O Introduction to PL/SQL Oracle Database 10g Develop PLSQL Program Units.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
Program with PL/SQL Lesson 5. Working with Composite Data Types.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
LECTURE 1 INTRODUCTION TO PL/SQL Tasneem Ghnaimat.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
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.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
PL/SQL Declaring Variables PL/SQL Block Structure DECLARE (Optional) Variables, cursors, user-defined exceptions BEGIN (Mandatory) - SQL statements -
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
Database Application Development using PL/SQL Programming.
Recognizing PL/SQL Lexical Units. 2 home back first prev next last What Will I Learn? List and define the different types of lexical units available in.
Introduction to PL/SQL. Objectives  After completing this lesson, you should be able to do the following:  Explain the need for PL/SQL  Explain the.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Copyright  Oracle Corporation, All rights reserved. 16 Declaring Variables.
Conversion Functions.
Variables and control statements in PL\SQL Chapter 10.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
Declaring PL/SQL Variables
PL/SQL INTRODUCTION.
1 PL/SQL Part C Scope and Interacting with the Oracle Server.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
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,
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Lab 2 Writing PL/SQL Blocks CISB514 Advanced Database Systems.
Sheffield Hallam University – November 2006 Advanced Databases PL/SQL 1 Blocks, Variables & Control Structures Lynne Dawson November 2006.
3 Copyright © 2004, Oracle. All rights reserved. Writing Executable Statements.
4 Copyright © 2009, Oracle. All rights reserved. Using Conversion Functions and Conditional Expressions.
PL/SQL Part B.
Egyptian Language School Computer Department
CS322: Database Systems PL/ SQL PL/SQL by Ivan Bayross.
Topics Designing a Program Input, Processing, and Output
Chapter 6 JavaScript: Introduction to Scripting
Writing Executable Statements
Writing Control Structures
PL / SQL Basics Chapter 3.
Java Programming: From Problem Analysis to Program Design, 4e
كتابة الجمل التنفيذية في PL/SQL
Database Management Systems 2
2.1 Parts of a C++ Program.
Chapter 3 The DATA DIVISION.
Writing Control Structures
variables and control statements in PL\SQL
elementary programming
Chapter 2: Introduction to C++.
PL/SQL Declaring Variables.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Presentation transcript:

PL/SQL Writing Executable Statements

PL/SQL Block Syntax and Guidelines Statement can be split across lines, but keywords must not be split Lexical units can be classified as: –Delimiters (simple and compound symbols) These are characters that have special meaning to PL/SQL, such as arithmetic operators and quotation marks –Identifiers, which include reserved words –Literals (is any value (character, numeric, or Boolean [true/false]) that is not an identifier. 123, "Declaration of Independence," and FALSE are examples of literals ) –Comments

Identifiers Can contain up to 30 characters Must begin with an alphabetic character Can contain numerals, dollar signs, underscores, and number signs CANNOT contain character such as hyphens, slashes, and spaces Should NOT have the same name as a database table column name Should NOT be reserved words

PL/SQL Block Syntax and Guidelines –Literals Character and date literals must be enclosed in single quotation marks. Numbers can be simple values or scientific notation. –A PL/SQL block is terminated by a slash ( / ) on a line by itself. v_ename := 'Henderson';

Commenting Code –Prefix single-line comments with two dashes (--). –Place multi-line comments between the symbols /* and */. Example... v_sal NUMBER (9,2); BEGIN /* Compute the annual salary based on the monthly salary input from the user */ v_sal := &p_monthly_sal * 12; END; -- This is the end of the block

SQL Functions in PL/SQL Available in procedural statements: –Single-row number –Single-row character –Data type conversion –Date –Timestamp –GREATEST and LEAST –Miscellaneous functions NOT available in procedural statements: –DECODE –GROUP functions

Datatype Conversion –Convert data to comparable datatypes. –Mixed datatypes can result in an error and affect performance. –Conversion functions: TO_CHAR TO_DATE TO_NUMBER DECLARE v_date VARCHAR2(15); BEGIN SELECT TO_CHAR(hiredate, 'MON. DD, YYYY') INTO v_date FROM emp WHERE empno = 7839; END;

Nested Blocks and Variable Scope PL/SQL blocks can be nested wherever an executable statement is allowed A nested block becomes a statements An exception section can contain nested blocks The scope of an identifier is that region of a program unit (block, subprogram, or package) from which you can reference the identifier

Identifier Scope An identifier is visible in the regions where you can reference the identifier without having to qualify it: –A block can look up to the enclosing block –A block cannot look down to enclosed blocks

Qualify an Identifier The qualifier can be the label of an enclosing block Qualify an identifier by using the block label prefix > DECLARE birthdate DATE; BEGIN DECLARE birthdate DATE; BEGIN... outer.birtdate := TO_DATE(’03-AUG-1976’, ‘DD-MON-YYYY’); END;... END;

Operators in PL/SQL Logical Arithmatic Concatenation Parentheses to control order of operations Exponential operator (**)

Determining Variable Scope Class Exercise > DECLARE V_SALNUMBER(7,2) := 60000; V_COMMNUMBER(7,2) := V_SAL * 0.20; V_MESSAGEVARCHAR2(255) := ' eligible for commission'; BEGIN DECLARE V_SALNUMBER(7,2) := 50000; V_COMM NUMBER(7,2) := 0; V_TOTAL_COMPNUMBER(7,2) := V_SAL + V_COMM; BEGIN... V_MESSAGE := 'CLERK not'||V_MESSAGE; outer.V_COMM := V_SAL * 0.30; END; V_MESSAGE := 'SALESMAN'||V_MESSAGE; END;