LECTURE 1 INTRODUCTION TO PL/SQL Tasneem Ghnaimat.

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

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.
Lecture-5 Though SQL is the natural language of the DBA, it suffers from various inherent disadvantages, when used as a conventional programming language.
Chapter 4B: More Advanced PL/SQL Programming
1 A GUIDE TO ORACLE8 CHAPTER 2: Creating and ModifyingDatabaseTables 2.
Chapter 4: Introduction to PL/SQL. 2 Lesson A Objectives After completing this lesson, you should be able to: Describe the fundamentals of the PL/SQL.
Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Introduction to PL/SQL
Writing Basic SQL statement 2 July July July Create By Pantharee Sawasdimongkol.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Introduction to PL/SQL
Ceng 356-Lab1. Objectives After completing this lesson, you should be able to do the following: Get Familiar with the development environment List the.
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.
Chapter 2 Basic SQL SELECT Statements
1 Introduction to PL/SQL. 2  Procedural programming language  Uses detailed instructions  Processes statements sequentially  Combines SQL commands.
PL/SQL Anonymous Blocks
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
1 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
Chapter 4: Introduction to PL/SQL
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.
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
CS178 Database Management PL/SQL session 8 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
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.
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
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.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
Introduction to SQL PART Ⅰ 第一讲 Writing Basic SQL SELECT Statements.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
1 PL/SQLPL/SQL Declaring Variables Declaring Variables Declaring Variables Declaring Variables Writing Executable Statements Writing Executable Statements.
1 Writing Basic SQL Statements. 1-2 Objectives At the end of this lesson, you should be able to: List the capabilities of SQL SELECT statements Execute.
Conversion Functions.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
1 Chapter 2 Basic SQL SELECT Statements. 2 Chapter Objectives Distinguish between an RDBMS and an ORDBMS Identify keywords, mandatory clauses, and optional.
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,
Lab 2 Writing PL/SQL Blocks CISB514 Advanced Database Systems.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following: –List the capabilities of SQL SELECT statements.
Writing Basic SQL SELECT Statements Lecture
Gollis University Faculty of Computer Engineering Chapter Five: Retrieval, Functions Instructor: Mukhtar M Ali “Hakaale” BCS.
1 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Oracle 10g Retrieving Data Using the SQL SELECT Statement.
1 Copyright © 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
1 Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
PL/SQL Part B.
C LANGUAGE MULITPLE CHOICE QUESTION SET-2
Retrieving Data Using the SQL SELECT Statement
Writing Basic SQL SELECT Statements
Chapter 4: Introduction to PL/SQL
PL/SQL week10.
Chapter 8 Advanced SQL.
Trainer: Bach Ngoc Toan– TEDU Website:
Presentation transcript:

LECTURE 1 INTRODUCTION TO PL/SQL Tasneem Ghnaimat

Lesson A Objectives After completing this lesson, you should be able to: Describe the fundamentals of the PL/SQL programming language Execute PL/SQL data type conversion functions Display output through PL/SQL programs Manipulate character strings in PL/SQL programs Guide to Oracle 10g2

Fundamentals of PL/SQL PL/SQL is a procedural programming language that Oracle utilities use to manipulate DB data. PL/SQL program combines SQL queries with procedural commands (if/then, loops, variables). It is a full-featured programming language Executed using Oracle 10g It is an interpreted language Its commands are not a case sensitive. Inside single quotes are case sensitive.. ‘M’ != ‘m’ Semicolon ends each command It contains reserved words and built in functions. Guide to Oracle 10g3

PL/SQL Command Capitalization Styles Guide to Oracle 10g4

PL/SQL Variables and Data Types Variable names must follow the Oracle naming standard Strongly typed language: Explicitly declare each variable including data type before using variable Variable declaration syntax: variable_name data_type_declaration; Default value always NULL PL/SQL supports: scalar, composite, reference and LOB. Guide to Oracle 10g5

Scalar Variables Single value Data types correspond to Oracle 10g database data types VARCHAR2 CHAR DATE NUMBER Guide to Oracle 10g6

Composite Variables Data Structure is a data object made up of multiple individual data elements Composite variable is a data structure contains multiple scalar variables Types: RECORD TABLE VARRAY Guide to Oracle 10g7

Reference Variables Reference variables directly reference specific database column or row Reference variables assume data type of associated column or row %TYPE data declaration syntax: variable_name tablename.fieldname%TYPE; %ROWTYPE data declaration syntax: variable_name tablename%ROWTYPE; Guide to Oracle 10g8

Reference Variables The (%TYPE) reference data type specifies a variable that references a single DB field. current_f_last FACULTY.F_LAST%TYPE; The current_f_last variable assumes a data type of VARCHAR2(30), because this is the data type of the f_last column in the FACULTY table. Guide to Oracle 10g9

Reference Variables The (%ROWTYPE) reference data type creates composite variables that reference the entire data record. Faculty_row FACULTY%ROWTYPE; The variable faculty_row references all of the columns in the FACULTY table, and each column has the same data type as its associated DB column. Guide to Oracle 10g10

PL/SQL Program Blocks Declaration section (DECLARE) Optional (variable declaration) Execution section (BEGIN) Required (Program statements) Exception section (EXCEPTION) Optional (Error handling statements) Comment statements Enclosed within /* and */ Two hyphens (--) for a single line comment END; Guide to Oracle 10g11

PL/SQL Arithmetic Operators in Describing Order of Precedence Guide to Oracle 10g12

Assignment Statements Assigns value to variable Operator := Syntax variable_name := value; String literal must be enclosed in a single quotation marks. Guide to Oracle 10g13

Assignment Statements You can use the := in the declaration section to give initial values. s_id NUMBER := 100; You can use DEFAULT instead: s_id NUMBER DEFAULT 100; If NULL value is used in an assignment statement with arithmetic operation, the result is always NULL. Guide to Oracle 10g14

Executing a PL/SQL Program in SQL*Plus Create and execute PL/SQL program blocks within variety of Oracle 10g development environments: SQL *Plus Forms Reports Guide to Oracle 10g15

Displaying PL/SQL Program Output in SQL*Plus (continued) Display program output DBMS_OUTPUT.PUT_LINE('display_text'); Display maximum of 255 characters of text data. More than 255 characters gives an error. Example: s_name := ‘Ahmed Mahmoud’; DBMS_OUTPUT.PUT_LINE(s_name); Guide to Oracle 10g16

Writing a PL/SQL Program Write PL/SQL program in Notepad or another text editor Copy and paste program commands into SQL*Plus Press Run Guide to Oracle 10g17

Writing a PL/SQL Program (continued) Good programming practice Place DECLARE, BEGIN, and END commands Indent commands within each section Guide to Oracle 10g18

PL/SQL Program Commands Guide to Oracle 10g19 Output: Today’s data is 18-OCT-07 PL/SQL procedure successfully completed

PL/SQL Data Conversion Functions Implicit data conversions Interpreter automatically converts value from one data type to another (the command DBMS_OUTPUT.PUT_LINE(todays_date), the interpreter automatically converted the todas_date DATE variable to a text string for output). If PL/SQL interpreter unable to implicitly convert value error occurs Explicit data conversions Convert variables to different data types Using built in data conversion functions Guide to Oracle 10g20

PL/SQL Data Conversion Functions of PL/SQL Guide to Oracle 10g21

Manipulating Character Strings with PL/SQL String Character data value Consists of one or more characters Concatenating Joining two separate strings Built in functions to concatenate and parse strings in SQL*Plus are as follows: Guide to Oracle 10g22

Concatenating Character Strings Double bar Operator || Syntax: new_string := string1 || string2; Example: Full_name := ‘Qusai’ || ‘ ‘ || ‘Abuein’ You must convert NUMBER and DATE data type variables (TO_CHAR)into a string before concatenating it. Guide to Oracle 10g23

Removing Spaces from Strings LTRIM function Remove blank leading spaces string := LTRIM(string_variable_name); RTRIM function Remove blank trailing spaces string := RTRIM(string_variable_name); Guide to Oracle 10g24

Finding the Length of Character Strings LENGTH function syntax string_length := LENGTH(string_variable_name); Space is included wherever it appears. DBMS_OUTPUT.PUT_LINE(LENGTH('Today''s date is ')); Gives 20. Guide to Oracle 10g25

Parsing Character Strings INSTR function Searches string for specific substring If substring is found, the starting position of it within the original_string is returned as integer value. Otherwise, zero is returned. Syntax: start_position := INSTR(original_string, substring); start_positioin should be integer data type. Guide to Oracle 10g26

Parsing Character Strings SUBSTR function Extracts specific number of characters from character string starting at given point Syntax: extracted_string := SUBSTR(string_variable, starting_point, number_of_characters); Guide to Oracle 10g27