stored procedures & operations navigator
DESCRIPTION
Stored Procedures & Operations Navigator. Week 10. SPL. SPL - Declarations. SPL supports all data types available in the Create Table statement SPL does not support User Defined Types SPL does not support Arrays Declare QtyToXfr Int Default 0; - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/1.jpg)
Stored Procedures& Operations Navigator
Week 10
![Page 2: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/2.jpg)
SPL
![Page 3: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/3.jpg)
SPL - Declarations
• SPL supports all data types available in the Create Table statement
• SPL does not support User Defined Types
• SPL does not support Arrays
Declare QtyToXfr Int Default 0;
Creates a variable called QtyToXfr as an integer and assigns 0 as the default value
![Page 4: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/4.jpg)
SPL - Assignment
Set XfrQtyActual = 0;
• Test a local variable or parameter
If QtyToXfr is not Null then…
![Page 5: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/5.jpg)
SPL – Data definition and Manipulation Statement
• Use SQL data definition and manipulation statements similar to embedded SQL.
• You don’t need to use Exec SQL and End-Exec.
• You don’t need to prefix variables with an ‘:’.
![Page 6: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/6.jpg)
SPL – Conditional (Selection) Statements
• If statementsIf XfrPartId = 123 then
set QtyToXfr = 1;ElseIf XfrToRqs > 100 then
set QtyToXfr = 100;Else
set QtyToXfr = XfrQtyRqs;End if;
• The above statement has 3 possible conditions– If the part number = 123– If the XfrToRqs > 100– otherwise
![Page 7: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/7.jpg)
SPL – Conditional (Selection) Statements
• Case StatementsCase PartId
When 123 thenSet QtrToXfr = 1;
When 234 then Set QtrToXfr = 10;
ElseSet QtyToXfr = XfrQtyRqs;
End Case;
• This statement has 3 conditions– If PartId = 123– If PartId = 234– otherwise
![Page 8: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/8.jpg)
SPL – Conditional (Selection) Statements
• Case StatementsCase
When XfrPartId = 123 thenSet QtyToXfr = 1;
When XfrPartId = 234 thenSet QtyToXfr = 100;
ElseSet QtyToXfr = XfrQtyRqs;
End Case;
• This condition has 3 conditions– If XfrPartId = 123– If XfrpartId = 234– Otherwise
![Page 9: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/9.jpg)
SPL – Loop Control Structures(Iteration)
• 4 loop structures– Loop
• infinite loop (use the Leave statement to exit)
– While • Test is at the beginning of the loop
– Repeat• Test is at the end of the loop
– For • Iterate over a set of rows
![Page 10: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/10.jpg)
SPL – Loop Control Structures(Iteration)
• Loop
Read: Loop
If EOF = ‘Y’ then
Leave Read;
End If;
End Loop Read;
![Page 11: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/11.jpg)
SPL – Loop Control Structures(Iteration)
• While
While (EOF = ‘N’) Do
End While;
![Page 12: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/12.jpg)
SPL – Loop Control Structures(Iteration)
• Repeat
Repeat
Until (EOF = ‘Y’)
End Repeat;
![Page 13: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/13.jpg)
SPL – Loop Control Structures(Iteration)
• For
For InvRow as InvCursor cursor for Select Qty
From InventoryWhere PartId = CurPartId
Do
End For;
• Builds a cursor full of data, reads a record from the cursor, process it, and then reads the next record. This loop continues until all the records in the cursor are processed.
![Page 14: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/14.jpg)
Write a Stored Procedure that:
• Reads through ACTRANSPF and updates records as follows:– Trans Type BD – change to 500– Trans Type FD – increase by 5%– Trans Type LS – change to 40
![Page 15: Stored Procedures & Operations Navigator](https://reader036.vdocuments.site/reader036/viewer/2022082712/56813a4a550346895da2406d/html5/thumbnails/15.jpg)
Operations Navigator