SlideShare una empresa de Scribd logo
1 de 30
Sadıqov Xəyyam
Prosedurlar, Funksiyalar və Paketler
http://www.azeroug.org
http://www.azeroug.org
2/
Özüm haqqda
Şənbə, 14 Sentyabr 2013
Sadıqov Xəyyam
Azerfon LLC
Billing and VAS Engineer
SQL and PL/SQL Trainer
Sadıgov Xəyyam
http://www.azeroug.org
3/
PL/SQL
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
http://www.azeroug.org
4/
Procedurlar və Functionlar nədi ?
Şənbə, 14 Sentyabr 2013
– PL/SQL bloklar
– PL/SQL subprogram adlanırlar
– Anonym bloklar kimi blok strukturları var
• Könüllü deklarativ bölmə (DECLARE -siz)
• Məcburi işləyən bölmə
• Istisnalar idarə etmək ücün könüllü bölmə
Sadıgov Xəyyam
http://www.azeroug.org
5/
Anonym blokların ve Subprogramların
fərqi nedi ?
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
http://www.azeroug.org
6/
Anonym blokların ve Subprogramların
fərqi nedi ?
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
http://www.azeroug.org
7/
Subprogramlarin üstünlükləri
Şənbə, 14 Sentyabr 2013
• Easy maintenance
• Code Reuse
• Improved data security
• Improved performance
• Improved code clarity
Sadıgov Xəyyam
http://www.azeroug.org
8/
Procedure
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
CREATE [OR REPLACE] PROCEDURE procedure_name
[(argument1 [mode1] datatype1,
argument2 [mode2] datatype2,
. . .)]
[ AUTHID DEFINER | CURRENT_USER ]
IS|AS
procedure_body;
http://www.azeroug.org
9/
Procedure
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
...
CREATE TABLE dept AS SELECT * FROM departments;
CREATE PROCEDURE add_dept IS
v_dept_id dept.department_id%TYPE;
v_dept_name dept.department_name%TYPE;
BEGIN
v_dept_id:=280;
v_dept_name:='ST-Curriculum';
INSERT INTO dept(department_id,department_name)
VALUES(v_dept_id,v_dept_name);
DBMS_OUTPUT.PUT_LINE(' Inserted '|| SQL%ROWCOUNT
||' row ');
END;
http://www.azeroug.org
10/
Procedure parameterler
Şənbə, 14 Sentyabr 2013
• Formal və Faktiki
• İN – read-only
• OUT – write-only
• İN OUT – read-write
Sadıgov Xəyyam
http://www.azeroug.org
11/
Procedure
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
http://www.azeroug.org
12/
Invoking Procedures
Şənbə, 14 Sentyabr 2013
Haradan proceduru execute ede bilersiz:
– Anonim blok
– Başqa procedur
– Applicationdan
• Oracle Job
• Third-party application
Note: proceduru SQL de istifade etmek olmaz.
Sadıgov Xəyyam
http://www.azeroug.org
13/
Notation by name, by position
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
http://www.azeroug.org
14/
Function
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
CREATE [OR REPLACE] FUNCTION function_name
[(argument1 [mode1] datatype1,
argument2 [mode2] datatype2,
. . .)]
RETURN datatype
[ AUTHID [ DEFINER | CURRENT_USER ]]
IS|AS
function_body;
http://www.azeroug.org
15/
Function
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
CREATE FUNCTION check_sal RETURN Boolean IS
v_dept_id employees.department_id%TYPE;
v_empno employees.employee_id%TYPE;
v_sal employees.salary%TYPE;
v_avg_sal employees.salary%TYPE;
BEGIN
v_empno:=205;
SELECT salary,department_id INTO v_sal,v_dept_id FROM employees
WHERE employee_id= v_empno;
SELECT avg(salary) INTO v_avg_sal FROM employees WHERE
department_id=v_dept_id;
IF v_sal > v_avg_sal THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN NULL;
END;
http://www.azeroug.org
16/
Invoking a Function
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
BEGIN
IF (check_sal IS NULL) THEN
DBMS_OUTPUT.PUT_LINE('The function returned
NULL due to exception');
ELSIF (check_sal) THEN
DBMS_OUTPUT.PUT_LINE('Salary > average');
ELSE
DBMS_OUTPUT.PUT_LINE('Salary < average');
END IF;
END;
/
http://www.azeroug.org
17/
Function
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
DROP FUNCTION check_sal;
CREATE FUNCTION check_sal(p_empno employees.employee_id%TYPE)
RETURN Boolean IS
v_dept_id employees.department_id%TYPE;
v_sal employees.salary%TYPE;
v_avg_sal employees.salary%TYPE;
BEGIN
SELECT salary,department_id INTO v_sal,v_dept_id FROM employees
WHERE employee_id=p_empno;
SELECT avg(salary) INTO v_avg_sal FROM employees
WHERE department_id=v_dept_id;
IF v_sal > v_avg_sal THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
EXCEPTION
...
http://www.azeroug.org
18/
Invoking Function
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
BEGIN
DBMS_OUTPUT.PUT_LINE('Checking for employee with id 205');
IF (check_sal(205) IS NULL) THEN
DBMS_OUTPUT.PUT_LINE('The function returned
NULL due to exception');
ELSIF (check_sal(205)) THEN
DBMS_OUTPUT.PUT_LINE('Salary > average');
ELSE
DBMS_OUTPUT.PUT_LINE('Salary < average');
END IF;
DBMS_OUTPUT.PUT_LINE('Checking for employee with id 70');
IF (check_sal(70) IS NULL) THEN
DBMS_OUTPUT.PUT_LINE('The function returned
NULL due to exception');
ELSIF (check_sal(70)) THEN
...
END IF;
END;
/
http://www.azeroug.org
19/
Restrictions on User-Defined Functions
Şənbə, 14 Sentyabr 2013
Query və DML da işlənilen funkciyada olmaz:
• OUT yada IN OUT parametler
• Commit yada roll back
• create a savepoint or roll back to a savepoint,
• alter the session or the system.
• DDL
• Eyni tablicada deyişiklik etmek
Amma
• INSERT etmek (from SELECT statement)
• INSERT from a subquery in a DML statement
Sadıgov Xəyyam
http://www.azeroug.org
20/
Package Architecture
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
http://www.azeroug.org
21/
Package spec
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
http://www.azeroug.org
22/
Package body
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
http://www.azeroug.org
23/
Example
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
http://www.azeroug.org
24/
Execute
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
http://www.azeroug.org
25/
Advantages of PL/SQL Packages
Şənbə, 14 Sentyabr 2013
• Modularity
• Easier Application Design
• Information Hiding
• Added Functionality
• Better Performance
Sadıgov Xəyyam
http://www.azeroug.org
26/
Product-Specific Packages
Şənbə, 14 Sentyabr 2013
• DBMS_ALERT
• DBMS_OUTPUT
• DBMS_PIPE
• UTL_FILE
• UTL_HTTP
• UTL_SMTP
Sadıgov Xəyyam
http://www.azeroug.org
27/
Drop
Şənbə, 14 Sentyabr 2013
• Procedures
• DROP PROCEDURE procedure_name
• Function
• DROP FUNCTION function_name
• Package
• DROP PACKAGE package_name
Sadıgov Xəyyam
http://www.azeroug.org
28/
Data dictionary
Şənbə, 14 Sentyabr 2013
• user_procedures
• OBJECT_TYPE=‘PROCEDURE’
• OBJECT_TYPE=‘FUNCTION’
• OBJECT_TYPE=‘PACKAGE’
• user_source
• TYPE=‘PROCEDURE’
• TYPE=‘FUNCTION’
• TYPE=‘PACKAGE’
• user_errors
Sadıgov Xəyyam
http://www.azeroug.org
29/
Sizin suallarınız
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
http://www.azeroug.org
30/
Son
Şənbə, 14 Sentyabr 2013 Sadıgov Xəyyam
Sadıgov Xəyyam
khsadigov@azerfon.az
Mob: (070) 201 - 13 - 93
Skype: khsadigov

Más contenido relacionado

Destacado

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
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
Kurio // The Social Media Age(ncy)
 

Destacado (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
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
 

Azer oug sadigov xayyam

Notas del editor

  1. Sizin suallarınız
  2. Təşəkkürlər AZEROUG