Day 2 - Intro to PL/SQL @ De Anza College.
Question - Where do I find the practice exercises?
Introduction to PL/SQL Environment
Benefits of PL/SQL
Writing procedures and functions.
x INTEGER := 55;
BIND VARIABLES <-- Declared in PL/SQL Environment.
Reviewed video lecture:
Difference between Binary_integer and PLS_Integer
What is the difference between Long RAW, LONG and VARCHAR2?
Different types of Timestamp? <-- Illustrate the usage of timestamp datatypes using an example.
usage of %TYPE keyword.
How to create a script?
Use notepad or your favorite text editor -- create your script and save it.
Run it --> Simply copy and paste in your telnet session.
Writing Executable Statements:
--CODE IS WRITTEIN IN BETWEEN BEGIN AND EXCEPTION.
--EXCEPTION PART OF CODE IS EXECUTED IF THERE IS AN ISSUE WITH CODE UNDER BEGIN CLAUSE.
WRITING COMMENTS IN PL/SQL
--SINGLE LINE COMMENT
WHEN WRITING PROGRAM BLOCKS -
x := y || CHR(10) || z;
SQL functions --
number, character, data conversion, date etc.
scope of a variables and nested blocks.
Variable declared in outer block is accessible in the inner blocks - but not the other way around.
y := y + x;
x := x + y; -- error
All SQL operators
Logical, arithmetic, like, || % etc,
1 0 N
1 1 0 N
0 0 0 0
N N 0 N
1 0 N
1 1 1 1
0 1 0 N
N T N N
All operations in PL/SQL are solved in Precedence and Associativity.
Using DML ops in PL/SQL::
Revision to Select statment -- to read values in bind variables or PL/SQL variables.
SELECT col1, col2
INTO var1, var2
Use bind variables for data input and then associate/use in DML Statements:
slide 3.11, 3.12..
MERGE - INSERTS OR UPDATES DATA INTO A NEW TABLE USING DATA FROM AN EXISTING TABLE
USING SOME CONDITIONAL LOGIC.
MERGE INTO <TABLENAME>
USING <SRC TABLE NAME>
ON < CONDITION USING COLUMNS>
WHEN MATCHED THEN
WHEN NOT MATCHED THEN
CURSOR ATTRIBUTES (IMPLICIT AND EXPLICIT CURSOR TYPES)
WORK WITH INSERT/UPDATE -- COMMIT/ROLLBACK.
WORKING WITH CONTROL STRUCTURES
IF, ELSE AND ELSIF
WHEN <VAL> THEN ACTION1;
WHEN <VAL2> THEN ACTION2;
WHEN <VAL3> THEN ACTION3;
ELSE <DEFAULT ACTION>
EXIT (WHEN CONDITION);
WHILE (CONDITION) LOOP --PRE-TEST LOOP.
FOR COUNTER IN LOW..HIGH LOOP
FOR i in 1..22 loop
EXIT WHEN CONDITION..
ACTION - WATCH VIDEO LECTURE FOR COMPOSITE DATATYPES -
Whiteboard from July 2nd 2012.
Introduction PL/SQL Programming -
Sukhjit Singh -
Orientation - July 2nd 2012
>>About the course
About Language and Setting up your environment
Starting your labs.
..Cover the underlying topic concepts.
This orientation is being recorded and running in lecture mode (for audio).
If you have questions kindly type those in chat room.
PL/SQL - Procedural Language
SQL is an interpreted language --
Client and Server
..10 statements as a program block --> Put it in the server (Pre-compiled)
From Client we simply execute it.
Reduced the traffic between Client and Server
Application Platform - SAP, PeopleSoft, JDEdward, Siebel...
What will you learn after this course?
procedures, functions, triggers, pacakges, cursors
manage these objects
Working with Large Objects -
Writing simple statement and executing them
Control Blocks (decision-making and looping)
Packages --> Procedure and Functions
18 small units.
..Review the powerpoints and work on exercises.
Learning by Doing.
Unix acct -->
Oracle acct -->
Setup files -- are on the website.
Working with Oracle Environment:
Unix acct --> Login --> Start sqlplus
sqlplus - Oracle Id/pwd. (which instructor will provide).
To setup your environment - look up the setup file on the website.
Overview of PL/SQL.
Oracle 4GL - Transact-SQL (MS SQL Server)
Procedural SQL - used for Data Manipulation of record set (through usage of Procedures or Functions).
PL/SQL Block --> Compiled to p-code --> Saved in the data dictionary.
Client access --> Call the procedure --> Loads the p-code
Procedural statement are executed by PL/SQL engine
SQL Statements (that are part of Procedures) are executed by SQL Engine
Reduced I/O between Client and Server
Code Manageability --> Blocks.
Structured Programming --Modularize your code.
Portability -- code xfer from one Oracle system to another.
Exception Mgmt - Problem recovery
name CONSTANT varchar2(20) := 'Andrew';
SSN varchar(11) NOT NULL := DEFAULT '111-11-1111';
Learn all the datatypes
True, false and null
RECORD and VARRAYS
Temp variable to store values from the db records to manipulate
Rich Media - Large Objects
text and binary.
Bind Variables -
Declare varibles in SQL/Plus
Variable a DATE;
Chapter 2 - BEGIN and END Block.
Operators used in expressions. (pg 2-18)
Interact with variables.(30+ operators)
+, -, /, MOD, *, || etc.
Scope Mgmt - Nested Blocks - values from inner blocks cannot be seen by outer. Outer block variable values are accessible by inner blocks.
SQL Functions from chapter 4.
TO_CHAR, TO_DATE.. Datatype conversion functions.
Two exercises - Chapter 1 and 2.
Send two text files (including test runs) --> firstname.lastname@example.org
Start watching lecture for chapter 3 and 4.
No review session on 7/4 -
Meet on July 9th 2012.
Weekly review sessions on Mon and Wed (8:15pm to 10:15pm)
Email all registered students with conf. information.
Go to the following link and
and download the Oracle Concepts manual and SQL Reference Manual.
Oracle 9i Documentation is also available at
You can go through the attached document to get started with Formatting get result.
Go through the attached document - it should help you get started with PL/SQL.
Attached is a list of files with instructions to help you setup the schema for lab assignments out of the reader. You also have access to misc files that will be needed for other exercises for the rest of the quarter.
You have to be a registered student to be able to create unix account.
Go to the following link - http://cis.deanza.edu/cis/overview.html
and click on - Create your Bus/CIS Lab account.
1-8 of 8