Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.

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.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
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
Chapter 9: Advanced SQL and PL/SQL Topics Guide to Oracle 10g.
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.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
 2006 Pearson Education, Inc. All rights reserved Arrays.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
Introduction to PL/SQL
Guide To UNIX Using Linux Third Edition
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Introduction to PL/SQL
Bordoloi and Bock CURSORS. Bordoloi and Bock CURSOR MANIPULATION To process an SQL statement, ORACLE needs to create an area of memory known as the context.
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.
 2006 Pearson Education, Inc. All rights reserved Arrays.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
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
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 © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
LECTURE 1 INTRODUCTION TO PL/SQL Tasneem Ghnaimat.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
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.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced 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.
Database Application Development using PL/SQL Programming.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
1 PL/SQLPL/SQL Declaring Variables Declaring Variables Declaring Variables Declaring Variables Writing Executable Statements Writing Executable Statements.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
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 3 Syntax, Errors, and Debugging Fundamentals of Java.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
A Guide to SQL, Eighth Edition Chapter Eight SQL Functions and Procedures.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Using SQL in PL/SQL Oracle Database PL/SQL 10g Programming Chapter 4.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
Oracle10g Developer: PL/SQL Programming1 Objectives Named program units How to identify parameters The CREATE PROCEDURE statement Creating a procedure.
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.
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.
CS422 Principles of Database Systems Oracle PL/SQL Chengyu Sun California State University, Los Angeles.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
PL/SQL Part B.
A Guide to SQL, Seventh Edition
Working in the Forms Developer Environment
Chapter 1: Introduction to computers and C++ Programming
SQL and SQL*Plus Interaction
PL/SQL.
Using SQL*Plus.
Introduction to C++ Programming
Chapter 4: Introduction to PL/SQL
PL/SQL week10.
Chapter 8 Advanced SQL.
Presentation transcript:

Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data

Guide to Oracle 10g2 Lesson A Objectives After completing this lesson, you should be able to: Describe the fundamentals of the PL/SQL programming language Write and execute PL/SQL programs in SQL*Plus Execute PL/SQL data type conversion functions

Guide to Oracle 10g3 Display output through PL/SQL programs Manipulate character strings in PL/SQL programs Debug PL/SQL programs

Guide to Oracle 10g4 Fundamentals of PL/SQL Full-featured programming language Execute using Oracle 10g utilities SQL*Plus Forms Builder Interpreted language Semicolon ends each command Reserved words

Guide to Oracle 10g5 A procedural programming language is a programming language that uses detailed, sequential instructions to process data. A PL/SQL program combines SQL queries with procedural commands for task such as manipulating variable values, evaluating IF/THEN decision control structures, and creating loop structure that repeat instructions multiple times until the loop reaches an exit condition.

Guide to Oracle 10g6 PL/SQL interface directly with the Oracle 10g database and is available within Oracle development environments. Another advantage of using PL/SQL to create programs that interface with Oracle 10g database is that database developers can store PL/SQL programs directly in the database, which makes the programs valuable to all database users.

Guide to Oracle 10g7 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

Guide to Oracle 10g8 Scalar Variables Reference single value Data types correspond to Oracle 10g database data types VARCHAR2 CHAR DATE NUMBER

Guide to Oracle 10g9

10 General Scalar Data Types PL/SQL has general scalar data types that do not correspond to database data types.

Guide to Oracle 10g11 Composite Variables Data object made up of multiple individual data elements Data structure contains multiple scalar variables Types: RECORD, which specifies a structure that contains multiple scalar values, and is similar to a table record. TABLE, which specifies a tabular structure with multiple columns and rows. VARRAY, which specifies a variable-sized array. A variable-sized array is a tabular structure that can expand or contract based on the data values it contains.

Guide to Oracle 10g12 Reference Variables Directly reference specific database column or row and assume data type of associated column or row.

Guide to Oracle 10g13 LOB Data type PL/SQL LOB data types declare variables that reference binary data objects, such as image or sound. The LOB data type can store either binary or character data up to four gigabytes in size. The LOB values in PL/SQL programs must be manipulated using special set of programs, called the DBMS_LOB package.

Guide to Oracle 10g14 PL/SQL Program Blocks Declaration section Optional Execution section Required Exception section Optional Comment statements Enclosed within /* and */

Guide to Oracle 10g15 The structure of a PL/SQL program block is

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

Guide to Oracle 10g17 Assignment Statements Operator := Syntax variable_name := value; Ex: Current_s_first_name := ‘Tammy’;

Guide to Oracle 10g18 Recall that when you declare a new PL/SQL variable, the default value is NULL. You can place an assignment statement within a variable declaration to assign an initial value to a new variable. Ex: cuurent_student_Id NUMBER :=100; Or cuurent_student_Id NUMBER DEFAULT 100;

Guide to Oracle 10g19 If you use a NULL value in an assignment statement that perform an arithmetic operation, the resulting value is always NULL. DECLARE variable1 NUMBER; variable2 NUMBER :=0; BEGIN variable2:= variable1+1; END;

Guide to Oracle 10g20 Executing a PL/SQL Program in SQL*Plus Create and execute PL/SQL program blocks Within variety of Oracle 10g development environments Add PL/SQL programs to your Forms Builder Report Builder Execute PL/SQL programs in SQL*plus.

Guide to Oracle 10g21 Displaying PL/SQL Program Output in SQL*Plus PL/SQL output buffer Memory area on database server Stores program’s output values before they are displayed to user Should increase size SET SERVEROUTPUT ON SIZE buffer_size Default buffer size 2000 bytes. SET SERVEROUTPUT ON SIZE 4000

Guide to Oracle 10g22 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

Guide to Oracle 10g23 Writing a PL/SQL Program Write PL/SQL program in Notepad or another text editor Copy and paste program commands into SQL*Plus Press Enter after last program command Type front slash ( / ) Then press Enter again

Guide to Oracle 10g24

Guide to Oracle 10g25 Writing a PL/SQL Program (continued) Good programming practice Place DECLARE, BEGIN, and END commands flush with left edge of text editor window Indent commands within each section

Guide to Oracle 10g26 PL/SQL Program Commands

Guide to Oracle 10g27 PL/SQL Data Conversion Functions Implicit data conversions Interpreter automatically converts value from one data type to another If PL/SQL interpreter unable to implicitly convert value error occurs Explicit data conversions Convert variables to different data types Using data conversion functions

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

Guide to Oracle 10g29 Manipulating Character Strings with PL/SQL String Character data value Consists of one or more characters Concatenating Joining two separate strings Parse Separate single string consisting of two data items separated by commas or spaces

Guide to Oracle 10g30 Concatenating Character Strings Operator || Syntax: new_string := string1 || string2;

Guide to Oracle 10g31 Removing Blank Leading and Trailing 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 10g32 Finding the Length of Character Strings LENGTH function syntax string_length := LENGTH(string_variable_name); Ex: You use the following command to declare an integer variable named code_length, and assign to it the string length: Code-length as NUMBER(3) := LENGTH(bldg_code);

Guide to Oracle 10g33 Character String Case Functions Modify case of character strings Functions and syntax: string := UPPER(string_variable_name); string := LOWER(string_variable_name); string := INITCAP(string_variable_name);

Guide to Oracle 10g34

Guide to Oracle 10g35 Parsing Character Strings INSTR function Searches string for specific substring Syntax: start_position := INSTR(original_string, substring); SUBSTR function Extracts specific number of characters from character string Starting at given point

Guide to Oracle 10g36 Parsing Character Strings (continued) SUBSTR function (continued) Syntax: extracted_string := SUBSTR(string_variable, starting_point, number_of_characters); Use INSTR to find delimiter

Guide to Oracle 10g37

Guide to Oracle 10g38 Debugging PL/SQL Programs Syntax error Occurs when command does not follow guidelines of programming language Generate compiler or interpreter error messages Logic error Does not stop program from running Results in incorrect result

Guide to Oracle 10g39 Program with a Syntax Error

Guide to Oracle 10g40 Program with a Logic Error

Guide to Oracle 10g41 Finding Syntax Errors Often involve: Misspelling reserved word Omitting required character in command Using built-in function improperly Interpreter Flags line number and character location of syntax errors May actually be on preceding line Displays error code and message

Guide to Oracle 10g42 Finding Syntax Errors (continued) Comment out program lines To find error Cascading errors One syntax error can generate many more errors

Guide to Oracle 10g43 Finding Logic Errors Caused by: Not using proper order of operations in arithmetic functions Passing incorrect parameter values to built-in functions Creating loops that do not terminate properly Using data values that are out of range or not of right data type

Guide to Oracle 10g44 Finding Logic Errors (continued) Debugger Program that enables software developers to pause program execution and examine current variable values SQL*Plus environment does not provide PL/SQL debugger Use DBMS_OUTPUT to print variable values

Guide to Oracle 10g45