SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
Database 3
Dr. Ramez Alkhatib
Applied Faculty
‫عامـة‬ ‫مراجعة‬
PL/SQL
‫األولى‬ ‫المحاضرة‬
PL/SQL

‫المتحوالت‬
Variables

‫الشروط‬
Conditions

‫الحلقات‬
Loops

‫االستثناءات‬
Exceptions

‫المؤشرات‬
Cursors

‫أنماط‬
‫المجردة‬ ‫البيانات‬
Abstract Data Types

‫المتغيرة‬ ‫المصفوفات‬
(varying arrays)

‫المتداخلة‬ ‫الجداول‬
Nested Tables

‫التوابع‬ ‫و‬ ‫اإلجرائيات‬
Procedures and Functions

‫البرمجية‬ ‫الحزم‬
Packages

‫القوادح‬
Triggers
‫البرنامج‬ ‫أجزاء‬
END;
BEGIN
<executable statements>
EXCEPTION
<exception handling>
DECLARE
<variable declarations>
‫لتصرحيات‬‫ا‬ ‫مقطع‬
‫لتنفيذي‬‫ا‬ ‫املقطع‬
‫االستثناءات‬ ‫معاجلة‬
‫نامج‬‫رب‬‫ل‬‫ا‬ ‫ية‬‫ا‬‫هن‬
‫مثال‬
DECLARE
Pi CONSTANT NUMBER(9,7) := 3.1415926;
radius INTEGER;
area NUMBER(14,2);
BEGIN
radius := 3;
area := Pi * Power(radius,2);
INSERT INTO areas VALUES (radius, area);
END;
/ SQL> start d:/plsql/3.sql;
PL/SQL procedure successfully completed.
SQL> select * from areas;
RADIUS AREA
---------- ----------
3 28.27
‫المتحوالت‬
%TYPE , %ROWTYPE
lname employee.last_name%TYPE;
Dept_var Department%ROWTYPE;
Dept_var.department_name
‫الشروط‬
IF <some condition> THEN
<some command>
ELSIF <some condition> THEN
<some command>
ELSE
<some command>
END IF;
IF <some condition> THEN
IF <some condition> THEN
<some command>
END IF;
ELSE
<some command>
END IF;
‫الشروط‬
DECLARE
I INTEGER := 3;
BEGIN
CASE I
WHEN 1 THEN DBMS_OUTPUT.PUT_LINE('ONE');
WHEN 2 THEN DBMS_OUTPUT.PUT_LINE('TOW');
WHEN 3 THEN DBMS_OUTPUT.PUT_LINE('THREE');
WHEN 4 THEN DBMS_OUTPUT.PUT_LINE('FOUR');
WHEN 5 THEN DBMS_OUTPUT.PUT_LINE('FIVE');
ELSE DBMS_OUTPUT.PUT_LINE('?');
END CASE;
END;
/
‫الحلقات‬
 LOOP
 FOR
 WHILE
‫مثال‬
Loop
DECLARE
Pi CONSTANT NUMBER(9,7) := 3.1415926;
radius INTEGER;
area NUMBER(14,2);
BEGIN
radius := 3;
LOOP
area := Pi * Power (radius, 2);
INSERT INTO areas VALUES (radius, area);
radius := radius + 1;
EXIT WHEN area > 100;
END LOOP;
END;
/
SQL> select * from areas;
RADIUS AREA
---------- ----------
3 28.27
4 50.27
5 78.54
6 113.1
‫مثال‬
FOR
DECLARE
Pi CONSTANT NUMBER(9,7) := 3.1415926;
radius INTEGER;
area NUMBER(14,2);
BEGIN
FOR radius IN 1..7 LOOP
area := Pi * Power (radius, 2);
INSERT INTO areas VALUES (radius, area);
END LOOP;
END;
/
‫مثال‬
WHILE
DECLARE
Pi CONSTANT NUMBER(9,7) := 3.1415926;
radius INTEGER;
area NUMBER(14,2);
BEGIN
radius := 3;
WHILE radius <= 7 LOOP
area := Pi * Power (radius, 2);
INSERT INTO areas VALUES (radius, area);
radius := radius + 1;
END LOOP;
END;
/
‫االستثناءات‬
DECLARE
Pi CONSTANT NUMBER(9,7) := 3.1415926;
radius INTEGER;
area NUMBER(14,2);
some_variable NUMBER(14,2);
BEGIN
radius := 3;
LOOP
some_variable := 1/(radius-4);
area := Pi * Power (radius, 2);
INSERT INTO areas VALUES (radius, area);
radius := radius + 1;
EXIT WHEN area > 100;
END LOOP;
END;
/
DECLARE
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at line 9
‫االستثناءات‬
DECLARE
Pi CONSTANT NUMBER(9,7) := 3.1415926;
radius INTEGER;
area NUMBER(14,2);
some_variable NUMBER(14,2);
BEGIN
radius := 3;
LOOP
some_variable := 1/(radius-4);
area := Pi * Power (radius, 2);
INSERT INTO areas VALUES (radius, area);
radius := radius + 1;
EXIT WHEN area > 100;
END LOOP;
EXCEPTION
WHEN ZERO_DIVIDE THEN
INSERT INTO areas VALUES (0, 0);
END;
/
‫المؤشرات‬
(
‫الضمني‬
)
SELECT / INTO
DECLARE
min_salary NUMBER;
max_salary NUMBER;
BEGIN
SELECT MIN(salary), MAX(salary)
INTO min_salary, max_salary
FROM employee;
DBMS_OUTPUT.PUT_LINE('Smallest salary is: '||min_salary);
DBMS_OUTPUT.PUT_LINE('Biggest salary is: '||max_salary);
END;
/
‫الصريحة‬ ‫المؤشرات‬
DECLARE
Pi CONSTANT NUMBER(9,7) := 3.1415926;
area NUMBER(14,2);
CURSOR rad_cursor IS
SELECT * FROM radius_vals;
rad_val rad_cursor%ROWTYPE;
BEGIN
OPEN rad_cursor;
FETCH rad_cursor INTO rad_val;
area := Pi * Power(rad_val.radius,2);
INSERT INTO areas VALUES (rad_val.radius, area);
CLOSE rad_cursor;
END;
/
‫الحلقات‬ ‫مع‬ ‫المؤشرات‬
DECLARE
Pi CONSTANT NUMBER(9,7) := 3.1415926;
area NUMBER(14,2);
CURSOR rad_cursor IS
SELECT * FROM radius_vals;
rad_val rad_cursor%ROWTYPE;
BEGIN
OPEN rad_cursor;
LOOP
FETCH rad_cursor INTO rad_val;
EXIT WHEN rad_cursor%NOTFOUND;
area := Pi * Power(rad_val.radius,2);
INSERT INTO areas VALUES (rad_val.radius, area);
END LOOP;
CLOSE rad_cursor;
END;
/
‫المجردة‬ ‫البيانات‬ ‫أنماط‬
CREATE TYPE ADDRESS_TY AS OBJECT
(
street VARCHAR2(50),
city VARCHAR2(25),
state CHAR(2),
zip NUMBER
)
/
INSERT INTO CUSTOMER VALUES
(1,
PERSON_TY('John Smith',
ADDRESS_TY('57 PLEASANET ST', 'FINN','NH',11111)));
‫المتغيرة‬ ‫المصفوفات‬
CREATE OR REPLACE TYPE TOOLS_VA
AS VARRAY(5) OF VARCHAR2(25);
CREATE TABLE Borrower (
name VARCHAR2(25) PRIMARY KEY ,
tools TOOLS_VA
);
BORROWER
NAME TOOL
Jed Hopkins {Shovel, Axe, Hammer}
John Smith {Shovel, Saw}
‫مسألة‬
‫يرغب‬
‫أحد‬
‫معارض‬
‫األلبسة‬
‫بتخزين‬
‫بيانات‬
‫السلع‬
‫والزبائن‬
‫وطلبات‬
‫الشراء‬
‫المتوفرة‬
‫لديه‬
‫بحيث‬
‫يتم‬
‫انشاء‬
‫التالي‬
:

‫جدول‬
‫السلع‬
‫ويتضمن‬
‫الحقول‬
‫التالية‬
:
‫رقم‬
‫السلعة‬
-
‫اسم‬
‫السلعة‬
–
‫تاريخ‬
‫االنتاج‬
(
‫يوم‬
-
‫شهر‬
-
‫سنة‬
)
–
‫الكمية‬
‫المتوفرة‬
–
‫الشركة‬
‫المنتجة‬
.

‫جدول‬
‫طلبات‬
‫الشراء‬
‫ويتضمن‬
‫الحقول‬
‫التالية‬
:
‫رقم‬
‫الطلب‬
-
‫اسم‬
‫الزبون‬
(
‫اسم‬
‫أول‬
–
‫اسم‬
‫األب‬
-
‫الكنية‬
)
–
‫البريد‬
‫االلكتروني‬
(
‫أكثر‬
‫من‬
‫بريد‬
‫الكتروني‬
)
–
‫بطاقة‬
‫اعتماد‬
(
‫رقم‬
‫البطاقة‬
–
‫تاريخ‬
‫االنتهاء‬
–
‫رمز‬
‫األمان‬
)
–
‫الكمية‬
‫المطلوبة‬
–
‫الرقم‬
‫الوطني‬
–
‫رقم‬
‫الزبون‬
‫رقم‬
‫السلعة‬
.
‫المطلوب‬
:
(1
‫انشاء‬
‫الجداول‬
‫السابقة‬
‫مستخدما‬
‫ما‬
‫تراه‬
‫مناسبا‬
‫من‬
‫األنماط‬
‫والمصفوفات‬
‫اذا‬
‫استدعى‬
‫األمر‬
‫ذلك‬
‫ومضيفا‬
‫ما‬
‫تراه‬
‫مناسبا‬
‫من‬
‫القيود‬
.
(2
‫انشاء‬
‫كتلة‬
‫برمجية‬
‫تقوم‬
‫بإيجاد‬
‫اغلى‬
‫سلعة‬
‫متوفرة‬
‫في‬
‫المعرض‬
‫باستخدام‬
‫مفهوم‬
‫المؤشرات‬
.
(3
‫انشاء‬
‫كتلة‬
‫برمجية‬
‫تقوم‬
‫بإعطاء‬
‫معلومات‬
‫عن‬
‫السلع‬
‫وكل‬
‫طلبات‬
‫الشراء‬
‫التي‬
‫تخصها‬
‫باستخدام‬
‫مفهوم‬
‫المؤشرات‬
.

Weitere ähnliche Inhalte

Empfohlen

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

Empfohlen (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

DB3-Lecture1-PLSQL.pdf