SQL Training Procedures & Functions. Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. DB Procedures & Functions Procedures and Functions.

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. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
PL/SQL.
Murali Mani Persistent Stored Modules (Stored Procedures) : PSM.
PL/SQL (Procedural Language extensions to SQL) Prepared by: Manoj Kathpalia Edited by: M V Ramakrishna.
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
Using Oracle PL/SQL PL/SQL stands for Procedural Language/SQL. PL/SQL extends SQL by adding constructs found in procedural languages, resulting in a structural.
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
PL/SQL Introduction Database 1. Practice. Sample Database The schema of the sample database is the following: Drinkers (name, occupation, birthday, salary)
Dr. James Dullea, CSC8490 Introduction to PL/SQLSlide 1 of 36 7From Prof. Dullea CSC8490 Introduction to PL/SQL Module 01-9 Revised: June 12, 2005 Dr.
Introduction to PL/SQL. Procedural Language extension for SQL Oracle Proprietary 3GL Capabilities Integration of SQL Portable within Oracle data bases.
SQL Within PL / SQL Chapter 4. 2 SQL Within PL / SQL SQL Statements DML in PL / SQL Pseudocolums Transaction Control.
Session Title: Using SQL and PL/SQL for Queries and Reporting Presented By: Stephen Frederic Institution: IHL September 16, 2013.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
1 Introduction to PL/SQL. 2  Procedural programming language  Uses detailed instructions  Processes statements sequentially  Combines SQL commands.
SQL Training SQL Statements – Part 1. Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. Lesson Objectives Explain the role of SQL.
EE Copyright س Oracle Corporation, All rights reserved. ® Review of PL/SQL.
Lecture 4 PL/SQL language. PL/SQL – procedural SQL Allows combining procedural and SQL code PL/SQL code is compiled, including SQL commands PL/SQL code.
CPS120: Introduction to Computer Science Lecture 19 Introduction to 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.
PL SQL Block Structures. What is PL SQL A good way to get acquainted with PL/SQL is to look at a sample program. PL/SQL combines the data manipulating.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Session Title: Using SQL and PL/SQL for Queries and Reporting Presented By: Stephen Frederic Institution: IHL September 16, 2014.
Advanced SQL: Cursors & Stored Procedures
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
CS178 Database Management PL/SQL session 8 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman.
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.
Programmatic SQL Shaista Khan CS 157B. Topic Embedded SQL statements in high-level programming languages.
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
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.
Guide to Oracle 10g ITBIS373 Database Development Lecture 4a - Chapter 4: Using SQL Queries to Insert, Update, Delete, and View Data.
Database Management COP4540, SCS, FIU Oracle PL/SQL (Ch 10.5)
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
ITEC 224 Database Programming PL/SQL Lab Cursors.
Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 
A Guide to SQL, Eighth Edition Chapter Eight SQL Functions and Procedures.
Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Function, Trigger used in PosgreSQL.
PL/SQL programming Procedures and Cursors Lecture 1 [Part 2]
PL/SQL INTRODUCTION.
PRACTICE OVERVIEW PL/SQL Part Your stored procedure, GET_BUDGET, has a logic problem and must be modified. The script that contains the procedure.
1 Stored Procedures in MySQL Part I. 2 Objectives SQL Vs. MySQL SP MySQL SP Parameters MySQL SP Control Structures.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Program with PL/SQL Lesson 3. Interacting with the Oracle Server.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Overview.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
1 Section 10 - Embedded SQL u Many computer languages allow you to embed SQL statements within the code (e.g. COBOL, PowerBuilder, C++, PL/SQL, etc.) u.
CS422 Principles of Database Systems Oracle PL/SQL Chengyu Sun California State University, Los Angeles.
CS422 Principles of Database Systems Stored Procedures and Triggers Chengyu Sun California State University, Los Angeles.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
Chapter 5 Introduction to SQL.
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
A Guide to SQL, Seventh Edition
Program with PL/SQL Lesson 4.
PL/pgSQL
Interacting with the Oracle Server
PL/SQL.
Oracle9i Developer: PL/SQL Programming Chapter 3 PL/SQL Processing.
Handling Exceptions.
PL/SQL – Session 1 of 4 Instructor: Jim Cody
PL/SQL Scripting in Oracle:
Chapter 4: Introduction to PL/SQL
Chapter 2 Handling Data in PL/SQL Blocks Oracle9i Developer:
PRACTICE OVERVIEW PL/SQL Part - 1.
Chapter 8 Advanced SQL.
Presentation transcript:

SQL Training Procedures & Functions

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. DB Procedures & Functions Procedures and Functions are pre-defined pieces of code that perform database work (like a view). Procedures are typically used to perform and action - insert, update and delete statements. They do not return data. Functions run select statements and return a single* value. Functions can be run from a select statement. Procedures cannot. * Functions can be modified to return multiple values but then cannot be used in a select statement which is how they provide their value.

Procedures

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL –DB Procedure Sample Create or Replace Procedure DistributorUpdate (in_DistributorID IN Integer, in_Distributorname IN VarChar2, in_DistributorFirstName IN VarChar2, in_DistributorLastName IN VarChar2, in_Phone IN VarChar2, in_Fax IN VarChar2, in_City IN VarChar2, in_PostalCode IN VarChar2, in_DiscountRate IN Number) as begin Update distributor Set distributorname = in_DistributorName, distributorfirstname = in_DistributorFirstName, distributorlastname = in_DistributorLastName, phone = in_Phone, fax = in_Fax, city = in_City, postalcode = in_PostalCode, discountrate = in_DiscountRate where distributorid = in_DistributorID; Commit; end; /

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. Using a DB Procedure Create or Replace Procedure UpdateAddress (in_distributorid In Integer, in_street IN VarChar2, in_city IN VarChar2, in_statecode IN VarChar2, in_zip IN VarChar2, in_phone IN VarChar2, in_fax IN VarChar2) as begin Update Distributor Set address1 = in_street, city = in_city, provinceabbreviation = in_statecode, postalcode = in_zip, phone = in_phone, fax = in_fax Where distributorid = in_distributorid; Commit; end; Create or Replace Procedure UpdateAddress (in_distributorid In Integer, in_street IN VarChar2, in_city IN VarChar2, in_statecode IN VarChar2, in_zip IN VarChar2, in_phone IN VarChar2, in_fax IN VarChar2) as begin Update Distributor Set address1 = in_street, city = in_city, provinceabbreviation = in_statecode, postalcode = in_zip, phone = in_phone, fax = in_fax Where distributorid = in_distributorid; Commit; end;

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – A Definition Declaration Section Executable Section Exception Section PL/SQL is an Oracle language that extends the capabilities of SQL. A PL/SQL procedure contains three sections: Declaration, Executable, and Exception. In PL/SQL you can develop logic that can be executed in: SQL*Plus A Stored Procedure A Stored Function Database Trigger Package End; Variables and Cursors Procedural & SQL statements Error handling statements Create or Replace Procedure name AS

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL Procedures – A Definition The syntax for the Create Procedure command is as follows: Create Procedure Syntax: create [or replace] procedure procedurename [ (argument IN | OUT | IN OUT datatype) ] … as variable datatype; … begin … exception … end;

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. In addition to the normal Oracle SQL datatypes, PL/SQL allows you to declare variables with these datatypes. The maximum length of a variable name is 30 characters. BooleanCan be assigned the constants True or False. Binary_IntegerIntegers in the range –2,147,483,647 to 2,147,483,647. NaturalIntegers from 0 to 2,147,483,647. PositiveIntegers from 1 to 2,147,483,647. %TypeA Table.Column’s datatype. You must declare all variables and constants that are referenced in the PL/SQL statements. SQL Cursors must also be declared. Example: Create or Replace Procedure AddDistributor (in_distributorid IN Integer, in_name IN String) as my_addressDistributor.Address1%Type; begin My_Address := 'Unknown'; Insert into Distributor(DistributorID, DistributorName, Address1) values (in_distributorid, in_name, my_address); end; / PL/SQL – Datatypes

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – Operators & Delimiters +Addition Operator -Subtraction Operator *Multiplication Operator /Division Operator =Equality Operator <Less than Operator >Greater than Operator ;Statement terminator 'Character String Delimiter "Quoted String Delimiter <>Not Equal To Operator !=Same as <> <=Less Than Or Equal To Operator >=Greater Than or Equal To Operator :=Assignment Operator ||Concatenation Operator --Single Line Comment /* */Multiple Line Comments >Label Delimiters Space Tab Carriage return MyUser_Nm := 'Temp' || MyUser_ID; My_Address := 'Unknown'; My_discount := My_discount * 0.75; Examples: If MySalary < then RAISE Salary_Too_Low; End If;

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – If /Then / Else Syntax IF condition THEN statement; … statement; [ELSIF condition THEN statement; … statement;] [ELSIF condition THEN statement; … statement;] [ELSE statement; … statement;] END IF; Example: IF My_price < 5000 THEN My_price := My_price * 1; ELSE My_price := My_price * 0.75; END IF; Special Notes: The ELSIF and ELSE clauses are optional. An IF statement can have multiple ELSIF clauses but only one ELSE clause. ELSIF is valid. ELSEIF is invalid.

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – IS Null Condition The IS NULL condition will evaluate to TRUE only if the variable it is checking is NULL. If the variable IS NOT NULL, the condition will evaluate to FALSE. v_Number1Number; v_Number2Number, v_ResultVarchar2(5); begin; … IF v_Number1 IS NULL or v_Number2 IS NULL then v_Result := ‘Unknown’; ELSIF v_Number1 < v_Number2 then v_Result := ‘Yes”; ELSE v_Result := ‘No’; END IF; END;

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – Loop / End Loop Syntax LOOP statement; … statement; END LOOP; Example: create or replace procedure LoopSample as My_CountPositive := 1; Max_Loops constant positive :=100; begin LOOP My_Count := My_Count + 1; EXIT WHEN My_Count > Max_Loops; END LOOP; end; /

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – While / Loop Syntax WHILE condition LOOP statement; … statement; END LOOP; Example: create or replace procedure WhileLoopSample as MyUser_ID Positive := 1; MyUser_Nm VarChar2(30); begin WHILE MyUser_ID < 101 LOOP MyUser_Nm := ‘Temp’ || MyUser_ID; insert into Users (UserID, UserName, RoleID, Password) values (MyUser_ID, MyUser_Nm,5,'ChangeMe'); MyUser_ID := MyUserID + 1; END LOOP; end; /

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – For / Loop Syntax FOR loop-variable IN [REVERSE] lower..upper LOOP statement; … statement; END LOOP; Example: create or replace procedure ForLoopSample as MyUser_Nm VarChar2(30); Max_Loops Positive := 100; begin FOR MyUser_ID IN 1..Max_Loops LOOP MyUser_Nm := 'Temp' || MyUser_ID; INSERT INTO Users (UserID, UserName, RoleID, Password) VALUES (MyUser_ID, MyUser_Nm,5,'ChangeMe'); END LOOP; end; /

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – GOTO Statement GOTO Label; Example: cur_value positive := 1; max_loops positive := 10; begin loop if cur_value > max_loops then GOTO blast_off; else cur_value := cur_value + 1; end if; end loop; > …. end; /

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – SQL Syntax (Select) SELECT A SELECT statement retrieves data from the database into PL/SQL variables. The form of a SELECT statement is as follows: SELECT select-list INTO variable-list FROM table-reference WHERE where-clause GROUP BY group-by-clause ORDER BYorder-by-clause; Note: This form of the SELECT statement should return not more than one row. If more than one row must be return, you must use a CURSOR to retrieve each row individually. Example: select orderdate into in_orderdate from orders where orderid = in_orderid;

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – Cursor Processing A Cursor is used to process multiple rows retrieved from the database. Using a cursor, your program can step through the set of returned rows one at a time, processing each row in turn. Cursor Functions: DECLARE the recordset OPEN the recordset FETCH a row and move through the recordset CLOSE the recordset SQL Statement BASE TABLE CURSOR RecordSet

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – Cursor Processing Example Create or Replace Procedure unconfirmedOrders as my_orderid Orders.OrderID%type; cursor my_cursor is select orderID from orders where orderstatuscode = 'O'; begin -- Delete all records in the WIP table -- Then Open the cursor. -- Insert all cursor rows into the WIP Table delete from WIP; open my_cursor; loop fetch my_cursor into my_orderid; exit when my_cursor%notfound; insert into WIP(OrderID) values (my_orderid); end loop; commit; close my_cursor; end; / Use a Procedure with a Cursor to save all work in progress (or unshipped orders). Note: WIP  Work in Progress

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – SQL Syntax (Insert) INSERT The form of a INSERT statement is as follows: INSERT INTO table-reference ( column-name, column-name…) VALUES (expression, expression...); Example: Insert Into distributor (distributorid, distributorname, distributorfirstname, distributorlastname) Values (in_distributorid, in_distributorname, in_firstname, in_lastname); Note: Since all character fields are declared as VarChar2 fields, there is no need to enclose them in quotes.

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – SQL Syntax (Update) UPDATE The form of a UPDATE statement is as follows: Update table-reference SET column-name = expression, … WHERE where-clause; Example: Update Distributor Set address1 = in_street, city = in_city, provinceabbreviation = in_state, postalcode = in_zip Where distributorID = in_distributorid;

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – SQL Syntax (Delete) DELETE The form of a DELETE statement is as follows: DELETE FROM table-reference WHERE [where-clause] [CURRENT OF cursor-name]; Note: The Where Current of cursor-name option allows you to delete the record that is being pointed to by the Cursor. For this to work, the Cursor must be declared as an updateable Cursor. See Cursor Processing. Example: Delete from Orders Where OrderID = in_orderid;

Functions

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL Functions – A Definition A Function can return a value to the caller. The value is returned to the caller through the use of a RETURN keyword within the function. Functions can be referenced directly in SQL Queries. Create Function Syntax: create [or replace] function functionname [ (argument IN | OUT | IN OUT datatype) ] … return datatype is argument datatype; begin … return (argument); exception … end; Note: Every Function must have a return clause.

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL Function Example Create or Replace Function ShippingCharge(in_orderid IN Integer) return Integer is ShippingCharge integer; begin SELECT Sum(Weight*OrderQty*CarrierMileageRate*Mileage)+ (FixedCostAmount+DeliveryChargeRate) AS ShippingCost into ShippingCharge FROM Delivery, CARRIER, Orders, OrderDetail, Distributor, Product, Distance, v_weight WHERE Delivery.DeliveryCode = Orders.DeliveryCode AND CARRIER.CarrierID = Orders.CarrierID AND Orders.OrderID = OrderDetail.OrderID AND Orders.DistributorID = Distributor.DistributorID AND Distributor.WarehouseID = Distance.WarehouseID AND Orders.PRovinceID = Distance.ProvinceID AND OrderDetail.ProductID = Product.ProductID AND Product.ProductCode = v_weight.Model AND Orders.OrderID = in_orderid Group by FixedCostAmount,DeliveryChargeRate ; return ShippingCharge; end; Select OrderID, ShippingCharge(Orderid) as ShippingCharge from Orders Where OrderID = 1001;

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. PL/SQL – Handling Exceptions Predefined Exceptions: DUP_VAL_ON_INDEXDuplicate value for index column. INVALID_NUMBERSQL statement specifies an invalid number. NO_DATA_FOUNDSelect statement doesn’t return any rows. TOO_MANY_ROWSA Select statement has retrieved more than 1 row. VALUE_ERRORTruncation or conversion error. User-Defined Exceptions: Salary_Too_Low exception; MySalary NUMBER(10,2); begin Select Salary from Person Into MySalary Where person = in_person; If MySalary < then RAISE Salary_Too_Low; End If; return (‘Salary OK’); exception When Salary_Too_Low then return (‘Salary too low’); end;

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. Exception Handling Example Create or Replace Function ShippingCharge(in_orderid IN Integer) return Integer is ShippingCharge integer; begin SELECT Sum(Weight*OrderQty*CarrierMileageRate*Mileage)+ (FixedCostAmount+DeliveryChargeRate) AS ShippingCost into ShippingCharge FROM Delivery, CARRIER, Orders, OrderDetail, Distributor, Product, Distance, v_weight WHERE Delivery.DeliveryCode = Orders.DeliveryCode AND CARRIER.CarrierID = Orders.CarrierID AND Orders.OrderID = OrderDetail.OrderID AND Orders.DistributorID = Distributor.DistributorID AND Distributor.WarehouseID = Distance.WarehouseID AND Orders.PRovinceID = Distance.ProvinceID AND OrderDetail.ProductID = Product.ProductID AND Product.ProductCode = v_weight.Model AND Orders.OrderID = in_orderid Group by FixedCostAmount,DeliveryChargeRate; return ShippingCharge; exception when NO_DATA_FOUND then return(0); end; Note: This code uses a view named v_weight. This view is supplied in the _CreateViews.sql file within the student’s starter database folder.

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. Showing Errors Create or Replace Procedure UpdateAddress (in_distributorid In Integer, in_street IN VarChar2, in_city IN VarChar2, in_statecode IN VarChar2, in_zip IN VarCharxxx, in_phone IN VarChar2, in_fax IN VarChar2) as begin Update Distributor Set address1 = in_street, city = in_city, provinceabbreviation = in_statecode, postalcode = in_zip, phone = in_phone, fax = in_fax Where distributorid = in_distributorid; Commit; end; / show errors

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. Test Procedures Create or Replace Procedure UpdateAddress (in_distributorid In Integer, in_street IN VarChar2, in_city IN VarChar2, in_statecode IN VarChar2, in_zip IN VarChar2, in_phone IN VarChar2, in_fax IN VarChar2) as begin Update Distributor Set address1 = in_street, city = in_city, provinceabbreviation = in_statecode, postalcode = in_zip, phone = in_phone, fax = in_fax Where distributorid = in_distributorid; Commit; end; Create or Replace Procedure UpdateAddress (in_distributorid In Integer, in_street IN VarChar2, in_city IN VarChar2, in_statecode IN VarChar2, in_zip IN VarChar2, in_phone IN VarChar2, in_fax IN VarChar2) as begin Update Distributor Set address1 = in_street, city = in_city, provinceabbreviation = in_statecode, postalcode = in_zip, phone = in_phone, fax = in_fax Where distributorid = in_distributorid; Commit; end;

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. Test & Use the Function Create or Replace Function ShippingCharge(in_orderid IN Integer) return Integer is ShippingCharge integer; begin SELECT Sum(20*OrderQty*CarrierMileageRate*Mileage) +(FixedCostAmount+ DeliveryChargeRate) AS ShippingCost into ShippingCharge FROM Delivery, CARRIER, Orders, OrderDetail, Distributor, Product, distance WHERE Delivery.DeliveryCode = Orders.DeliveryCode AND CARRIER.CarrierID = Orders.CarrierID AND Orders.OrderID = OrderDetail.OrderID AND Orders.DistributorID = Distributor.DistributorID AND Distributor.WarehouseID = Distance.WarehouseID AND Orders.PRovinceID = Distance.ProvinceID AND OrderDetail.ProductID = Product.ProductID AND Orders.OrderID = in_orderid GROUP BY FixedCostAmount, DeliveryChargeRate; return ShippingCharge; exception when NO_DATA_FOUND then return(0); end; / show errors;

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. Test & Use the Function

Workshop

Confidential & Proprietary Copyright © 2009 Cardinal Directions, Inc. Exercise: Creating Procedures 1.Create a procedure to add an orderdetail line. Use any existing orderid Populate all orderdetail columns 2.Create an orderdetail update procedure Change the order quantity 3.Create a function to return the line amount (productprice * orderqty) for any order detail line. 4.Create a function to return the total order amount for any order.