PACKAGES, Package Specification and Scope, Create Package Syntax, Declaring Procedures and Functions within a Package, Package Body, Create Package Body Syntax,Example –Package, Example– Package Body, Example – Calling Package Procedure, mResults of Calling Package Procedure, Cursors in Packages , cursor Example – Package Body, Example – Use Cursor Variable
Procedures in pl/sql,CREATE PROCEDURE Syntax, Compiling and Showing Errors, Parameters, Defining the IN, OUT, and IN OUT Parameter Modes, Parameter Constraint Restrictions, Example – Procedure with No Parameters,Example – Passing IN and OUT Parameters, Dropping a Procedure
PL/SQL is a combination of SQL along with the procedural features of programming languages.
It provides specific syntax for this purpose and supports exactly the same datatypes as SQL.
Using and Creating SQL Functions with Ammar Hassan Brohi.
String Functions
Numeric Functions
String / Number Conversion Functions
Group Functions
Date and Time Functions
Date Conversion Functions
Procedures in pl/sql,CREATE PROCEDURE Syntax, Compiling and Showing Errors, Parameters, Defining the IN, OUT, and IN OUT Parameter Modes, Parameter Constraint Restrictions, Example – Procedure with No Parameters,Example – Passing IN and OUT Parameters, Dropping a Procedure
PL/SQL is a combination of SQL along with the procedural features of programming languages.
It provides specific syntax for this purpose and supports exactly the same datatypes as SQL.
Using and Creating SQL Functions with Ammar Hassan Brohi.
String Functions
Numeric Functions
String / Number Conversion Functions
Group Functions
Date and Time Functions
Date Conversion Functions
Function in PL/SQL, Create Function Syntax, Example – No Parameters in Function , Example – Testing RetrieveSalary Function, Example Function with Parameter, Dropping a Function
Aggregate functions are functions that take a collection of values as input and return a single value.The ISO standard defines five (5) aggregate functions namely :-
1) COUNT
2) SUM
3) AVG
4) MIN
5) MAX
1.COUNT Function
The COUNT function returns the total number of values in the specified field. It works on both numeric and non-numeric data types. All aggregate functions by default exclude nulls values before working on the data.
MIN function
The MIN function returns the smallest value in the specified table field.
2.MAX function
Just as the name suggests, the MAX function is the opposite of the MIN function. It returns the largest value from the specified table field.
3.SUM function
Suppose we want a report that gives total amount of payments made so far. We can use the MySQL SUM function which returns the sum of all the values in the specified column. SUM works on numeric fields only. Null values are excluded from the result returned.
4.AVG function
MySQL AVG function returns the average of the values in a specified column. Just like the SUM function, it works only on numeric data types.
5.MIN function
The MIN function returns the smallest value in the specified table field.
Data Definition Language (DDL), Data Definition Language (DDL), Data Manipulation Language (DML) , Transaction Control Language (TCL) , Data Control Language (DCL) - , SQL Constraints
Function in PL/SQL, Create Function Syntax, Example – No Parameters in Function , Example – Testing RetrieveSalary Function, Example Function with Parameter, Dropping a Function
Aggregate functions are functions that take a collection of values as input and return a single value.The ISO standard defines five (5) aggregate functions namely :-
1) COUNT
2) SUM
3) AVG
4) MIN
5) MAX
1.COUNT Function
The COUNT function returns the total number of values in the specified field. It works on both numeric and non-numeric data types. All aggregate functions by default exclude nulls values before working on the data.
MIN function
The MIN function returns the smallest value in the specified table field.
2.MAX function
Just as the name suggests, the MAX function is the opposite of the MIN function. It returns the largest value from the specified table field.
3.SUM function
Suppose we want a report that gives total amount of payments made so far. We can use the MySQL SUM function which returns the sum of all the values in the specified column. SUM works on numeric fields only. Null values are excluded from the result returned.
4.AVG function
MySQL AVG function returns the average of the values in a specified column. Just like the SUM function, it works only on numeric data types.
5.MIN function
The MIN function returns the smallest value in the specified table field.
Data Definition Language (DDL), Data Definition Language (DDL), Data Manipulation Language (DML) , Transaction Control Language (TCL) , Data Control Language (DCL) - , SQL Constraints
How to Add Chatter in the odoo 17 ERP ModuleCeline George
In Odoo, the chatter is like a chat tool that helps you work together on records. You can leave notes and track things, making it easier to talk with your team and partners. Inside chatter, all communication history, activity, and changes will be displayed.
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
Delivering Micro-Credentials in Technical and Vocational Education and TrainingAG2 Design
Explore how micro-credentials are transforming Technical and Vocational Education and Training (TVET) with this comprehensive slide deck. Discover what micro-credentials are, their importance in TVET, the advantages they offer, and the insights from industry experts. Additionally, learn about the top software applications available for creating and managing micro-credentials. This presentation also includes valuable resources and a discussion on the future of these specialised certifications.
For more detailed information on delivering micro-credentials in TVET, visit this https://tvettrainer.com/delivering-micro-credentials-in-tvet/
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
Packages in PL/SQL
1. Prof. Neeraj Bhargava
Pooja Dixit
Department of Computer Science
School of Engineering & System Science
MDS, University Ajmer, Rajasthan, India
1
2. A package is a collection of PL/SQL objects
grouped together under one package name.
Packages provide a means to collect related
procedures, functions, cursors, declarations,
types, and variables into a single, named
database object that is more flexible than the
related database objects are by themselves.
Package variables – can be referenced in any
procedure, function, (other object) defined
within a package.
2
3. A package consists of a package specification and a
package body.
◦ The package specification, also called the package header.
◦ Declares global variables, cursors, exceptions, procedures, and
functions that can be called or accessed by other program units.
◦ A package specification must be a uniquely named database
object.
◦ Elements of a package can declared in any order. If element “A”
is referenced by another element, then element “A” must be
declared before it is referenced by another element. For
example, a variable referenced by a cursor must be declared
before it is used by the cursor.
Declarations of subprograms must be forward
declarations.
◦ This means the declaration only includes the subprogram name
and arguments, but does not include the actual program code.
3
4. Basically, a package is a named declaration
section.
◦ Any object that can be declared in a PL/SQL block
can be declared in a package.
◦ Use the CREATE OR REPLACE PACKAGE clause.
◦ Include the specification of each named PL/SQL
block header that will be public within the
package.
◦ Procedures, functions, cursors, and variables that
are declared in the package specification are
global.
The basic syntax for a package is:
CREATE [OR REPLACE PACKAGE[ <package name> {AS|IS}
<variable declarations>;
<cursor declarations>;
<procedure and function declarations>;
END <package name>;
4
5. To declare a procedure in a package – specify
the procedure name, followed by the
parameters and variable types:
PROCEDURE <procedure_name> (param1 param1datatype,
param2 param2datatype, ...);
To declare a function in a package, you must
specify the function name, parameters and
return variable type:
FUNCTION <function_name> (param1 param1datatype,
param2 param2datatype, ...)
RETURN <return data type>;
5
6. Contains the code for the subprograms and
other constructs, such as exceptions, declared in
the package specification.
Is optional – a package that contains only
variable declarations, cursors, and the like, but
no procedure or function declarations does not
require a package body.
Any subprograms declared in a package must be
coded completely in the package body. The
procedure and function specifications of the
package body must match the package
declarations including subprogram names,
parameter names, and parameter modes.
6
7. Use the CREATE OR REPLACE PACKAGE
BODY clause to create a package body.
The basic syntax is:
CREATE [OR REPLACE] PACKAGE BODY
<package name> AS
<cursor specifications>
<subprogram specifications and code>
END <package name>;
7
8. CREATE OR REPLACE PACKAGE ManageEmployee AS
-- Global variable declarations go here
-- Procedure to find employees
PROCEDURE FindEmployee(
emp_ID IN employee.EmployeeID%TYPE,
emp_FirstName OUT employee.FirstName%TYPE,
emp_LastName OUT employee.LastName%TYPE);
-- Exception raised by FindEmployee
e_EmployeeIDNotFound EXCEPTION;
-- Function to determine if employee identifier is
valid
FUNCTION GoodIdentifier(
emp_ID IN employee.EmployeeID%TYPE)
RETURN BOOLEAN;
END ManageEmployee;
/
8
9. CREATE OR REPLACE PACKAGE BODY ManageEmployee AS
-- Procedure to find employees
PROCEDURE FindEmployee(
emp_ID IN employee.EmployeeID%TYPE,
emp_FirstName OUT employee.FirstName%TYPE,
emp_LastName OUT employee.LastName%TYPE ) AS
BEGIN
SELECT FirstName, LastName
INTO emp_FirstName, emp_LastName
FROM Employee
WHERE EmployeeID = emp_ID;
-- Check for existence of employee
IF SQL%ROWCOUNT = 0 THEN
RAISE e_EmployeeIDNotFound;
END IF;
END FindEmployee;
9
10. -- Function to determine if employee identifier is valid
FUNCTION GoodIdentifier(
emp_ID IN employee.EmployeeID%TYPE)
RETURN BOOLEAN
IS
v_ID_Count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_ID_Count
FROM Employee
WHERE EmployeeID = emp_ID;
-- return TRUE if v_ID_COUNT is 1
RETURN (1 = v_ID_Count);
EXCEPTION
WHEN OTHERS THEN
RETURN FALSE;
END GoodIdentifier;
END ManageEmployee;
10
11. DECLARE
v_FirstName employee.FirstName%TYPE;
v_LastName employee.LastName%TYPE;
search_ID employee.EmployeeID%TYPE;
BEGIN
ManageEmployee.FindEmployee (&search_ID, v_FirstName,
v_LastName);
DBMS_OUTPUT.PUT_LINE ('The employee name is: ' ||
v_LastName || ', ' || v_FirstName);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('Cannot find an employee
with that ID.');
END;
/
11
12. When the employee identifier is valid, the code
displays the employee name as shown here.
Enter value for search_id: '01885'
The employee name is: Bock, Douglas
PL/SQL procedure successfully completed.
When the identifier is not valid, the exception
raised within the called procedure is propagated
back to the calling procedure and is trapped by
the EXCEPTION section’s WHEN OTHERS clause
and an appropriate message is displayed as
shown here.
Enter value for search_id: '99999'
Cannot find an employee with that ID.
PL/SQL procedure successfully completed.
12
13. A cursor variable can make a cursor dynamic so that it is
reusable and sharable among different procedures and
functions such as those created as part of a package.
A cursor variable has data type REF CURSOR. It is like a
pointer in the C language, and it points to a query work
area where a result set is stored.
First you must define a REF CURSOR type.
Next, you define a cursor variable of that type. In this
general syntactic example, the <return_type> object
represents a row in a database table.
TYPE ref_type_name IS REF CURSOR
[RETURN <return_type>];
This provides an example of declaring a cursor variable
that can be used to process data rows for the equipment
table of the Madison Hospital database.
DECLARE
TYPE equipment_Type IS REF CURSOR
RETURN equipment%ROWTYPE;
cv_Equipment IN OUT equipment_Type;
13
14. /* PL SQL Example 13.16 File: ch13-16.sql */
CREATE OR REPLACE PACKAGE BODY ManageEquipment AS
-- Procedure to get a specific item of equipment
PROCEDURE OpenItem (cv_Equipment IN OUT equipment_Type,
p_EquipmentNumber IN CHAR) AS
BEGIN
-- Populate the cursor
OPEN cv_Equipment FOR
SELECT * FROM Equipment
WHERE EquipmentNumber = p_EquipmentNumber;
END OpenItem;
PROCEDURE FetchItem (cv_Equipment IN equipment_Type,
equipment_Row OUT equipment%ROWTYPE) AS
BEGIN
FETCH cv_Equipment INTO equipment_Row;
END FetchItem;
END ManageEquipment;
14
15. /* PL SQL Example 13.16 File: ch13-16.sql */
DECLARE
-- Declare a cursor variable of the REF CURSOR type
item_Cursor ManageEquipment.equipment_Type;
v_EquipmentNumber equipment.EquipmentNumber%TYPE;
equipment_Row equipment%ROWTYPE;
BEGIN
-- Assign a equipment number to the variable
v_EquipmentNumber := '5001';
-- Open the cursor using a variable
ManageEquipment.OpenItem (item_Cursor, v_EquipmentNumber);
-- Fetch the equipment data and display it
LOOP
ManageEquipment.FetchItem( item_Cursor, equipment_Row);
EXIT WHEN item_cursor%NOTFOUND;
DBMS_OUTPUT.PUT (equipment_Row.EquipmentNumber || ' ');
DBMS_OUTPUT.PUT_LINE (equipment_Row.Description);
END LOOP;
END;
5001 Computer, Desktop
PL/SQL procedure successfully completed.
15