2014/11/6,今天在练习存储过程的时候,to_char()函数和我小小的闹腾了一把。
/* PROCEDURE RaceInfo
** Join tables: BoatCrew,Boat and Person,
** to get the information:
** BoatCategory, BowNumber, Position, LastName, FirstName
** Note:
** the posible value of the column Position is between 0 and 9, if
** the position is 0, print 'Cox';
** others, print the string of three characters of the number.
** for an instance, if position is 1, print '001'
** Input: BoatCat -- the category of the Boat
** if BoatCat is 'ALL', fetch all the records,
** otherwise just print the records of the special
** boat category
** BowNo -- the bow number
** Output: just print the information
*/
CREATE OR REPLACE PROCEDURE RaceInfo
(BoatCat IN VARCHAR2, BowNo IN VARCHAR2) AS
v_Count INTEGER := 0;
v_Position VARCHAR(3);
CURSOR cv_allPerson IS
SELECT BoatCategory, BowNumber, Position,
LastName, FirstName
FROM BoatCrew JOIN Boat
USING (BoatID)
JOIN Person
USING (PersonID)
ORDER BY BoatCategory, BowNumber, Position;
CURSOR cv_onePerson IS
SELECT BoatCategory, BowNumber, Position,
LastName, FirstName
FROM BoatCrew JOIN Boat
USING (BoatID)
JOIN Person
USING (PersonID)
WHERE UPPER(BoatCategory) = UPPER(BoatCat)
AND UPPER(BowNumber) = UPPER(BowNo)
ORDER BY BoatCategory, BowNumber, Position;
BEGIN
SELECT COUNT(*)
INTO v_Count
FROM Boat
WHERE UPPER(BoatCategory) = UPPER(BoatCat)
AND UPPER(BowNumber) = UPPER(BowNo);
IF UPPER(BoatCat) = 'ALL' THEN
FOR X IN cv_allPerson LOOP
IF X.Position = 0 THEN
v_Position := 'Cox'