Database Systems: The Complete Book- P5
Thông tin tài liệu:
Nội dung trích xuất từ tài liệu:
Database Systems: The Complete Book- P5 3 76 CHAPTER 8. SYSTEM ASPECTS OF SQL 8.2. PROCEDURES STORED IN THE SCHEAIA 377 1) CREATE FUNCTION GetYear (t VARCHAR(255) ) RETURNS INTEGER Since GetYear returns NULL if there is not a unique movie by the name of Remember the Titans, it is possible that this insertion will have NULL in the 2) DECLARE Not-Found CONDITION FOR SQLSTATE 02000; middle component. 0 3) DECLARE Too-Many CONDITION FOR SQLSTATE 21000; 8.2.9 Exercises for Section 8.2 BEGIN Exercise 8.2.1 : Using our running movie database: 4) DECLARE EXIT HANDLER FOR Not-Found, Too-Many 5) RETURN NULL ; Movie(title, year, length, incolor, studiolame, producerC#) 6) RETURN (SELECT year FROM Movie WHERE title = t); StarsIn(movieTitle, movieyear, starName) END ; MovieStar(name, address, gender, birthdate) MovieExec(name, address, cert#, networth) Figure 8.14: Handling exceptions in which a single-row select returns other than Studio(name, address, presC#) one tuple write PSM procedures or functions t o perform the following tasks: Line (6) is the statement that does the work of the function GetYear. It is * a) Given the name of a movie studio, produce the net worth of its president. a SELECT statement that is expected t o return exactly one integer, since that is * b) Given a name and address, return 1 if the person is a movie star but not what the function GetYear returns. If there is exactly one movie with title t (the an executive, 2 if the person is a n executive but not a star, 3 if both, and input parameter of the function), then this value will be returned. However. if 4 if neither. a n exception is raised at line (6), either because there is no movie with title t or several movies with that title, then the handler is invoked, and NULL instead *! c) Given a studio name. assign t o output parameters the titles of the two becomes the return-value. Also, since the handler is an EXIT handler, control longest movies by that studio. Assign NULL to one or both parameters if next passes to the point after the END. Since that point is the end of the funrtion. there is no such movie (e.g., if there is only one m o ~ i e a studio, there by GetYear returns a t that time, with the return-value NULL. 0 is no Lsecond-longesti) . ! d) Given a star name, find the earliest (lowest year) movie of more than 120 8.2.8 Using PSM Functions and Procedures minutes length in u-hich they appeared. If there is no such movie, return As we mentioned in Section 8.2.2, we can call a PSM function or procedtire the year 0. from a program with embedded SQL, from PSLI code itself, or from ordinary e) Given an address. find the name of the unique star with that address if SQL commands issued to the generic interface. The use of these procedures there is exactly one, and return NULL if there is none or more than one. and functions is the same as in most programming languages, with procedures invoked by CALL, and functions appearing as past of an expression. K e shall f) Given the name of a star, delete them from Moviestar and delete all their give one example of how a function can be called from the generic interface. movies from StarsIn and Movie. ...
Tìm kiếm theo từ khóa liên quan:
Oracle cơ bản giáo trình cơ sở dữ liệu bảo mật cơ sở dữ liệu cơ sở dữ liệu Mysql giáo trình sqlGợi ý tài liệu liên quan:
-
62 trang 402 3 0
-
Giáo trình Cơ sở dữ liệu: Phần 2 - TS. Nguyễn Hoàng Sơn
158 trang 294 0 0 -
Giáo trình Cơ sở dữ liệu: Phần 2 - Đại học Kinh tế TP. HCM
115 trang 176 0 0 -
Giáo trình Cơ sở dữ liệu: Phần 1 - Sở Bưu chính Viễn Thông TP Hà Nội
48 trang 171 1 0 -
Giáo Trình về Cơ Sở Dữ Liệu - Phan Tấn Quốc
114 trang 119 1 0 -
Giáo trình cơ sở dữ liệu quan hệ_3
26 trang 106 0 0 -
Giáo trình Cơ sở dữ liệu (Ngành: Công nghệ thông tin - Trung cấp) - Trường Cao đẳng Xây dựng số 1
49 trang 100 0 0 -
54 trang 70 0 0
-
134 trang 62 1 0
-
0 trang 57 0 0
-
Bài giảng cơ sở dữ liệu - chương 1 - ĐH KHTN Tp.HCM
46 trang 48 0 0 -
Giáo trình Cơ sở dữ liệu: Phần 1 - ĐH công nghiệp Tp.HCM
41 trang 42 0 0 -
57 trang 40 1 0
-
Giáo trình Cơ sở dữ liệu - Phần 2: SQL Server - ĐH Công nghiệp Tp.HCM
147 trang 39 2 0 -
Giáo trình Cơ sở dữ liệu: Phần 2 - Cao Thị Nhạn, Nguyễn Thị Thanh Bình
55 trang 36 0 0 -
Asp.Net 3.5 In Simple Steps- P6
10 trang 35 0 0 -
Asp.Net 3.5 In Simple Steps- P4
10 trang 35 0 0 -
Thực hành cơ sở dữ liệu: Phần 2
92 trang 34 0 0 -
THỰC HÀNH LAB : PHƯƠNG PHÁP TẤN CÔNG CỦA HACKER VÀO CÁC ỨNG DỤNG WEB BỊ LỖI SQL INJECTION
124 trang 34 1 0 -
Asp.Net 3.5 In Simple Steps- P5
10 trang 33 0 0