
























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to sql programming using persistent stored modules (psm), specifically focusing on creating procedures, if statements, and cursors. The syntax and usage of these features in both sql and pl/sql, as well as their applications in real-world scenarios. Students will gain a solid understanding of how to write and invoke procedures, use if statements for conditional logic, and work with cursors to manipulate data.
Typology: Slides
1 / 64
This page cannot be seen from the preview
Don't miss anything!

























































Persistent Stored Modules (PSM)
PL/SQL Embedded SQL
CREATE PROCEDURE (
)
;
CREATE FUNCTION (
) RETURNS
CREATE PROCEDURE JoeMenu (
IN b CHAR(20), IN p REAL
)
INSERT INTO Sells
VALUES(’Joe’’s Bar’, b, p);
8
Parameters are both read-only, not changed
The body --- a single insertion
CREATE FUNCTION Rate (IN b CHAR(20) ) RETURNS CHAR(10) DECLARE cust INTEGER; BEGIN SET cust = (SELECT COUNT(*) FROM Frequents WHERE bar = b); IF cust < 100 THEN RETURN ’unpopular’ ELSEIF cust < 200 THEN RETURN ’average’ ELSE RETURN ’popular’ END IF; END; (^14)
Number of customers of bar b
Return occurs here, not at one of the RETURN statements
Nested IF statement
loop1: LOOP
... LEAVE loop1; ...
END LOOP;
16
If this statement is executed...
Control winds up here
SELECT price INTO p FROM Sells WHERE bar = ’Joe’’s Bar’ AND beer = ’Bud’;