2012-05-07 74 views
1

試圖完成以下:打印行情

CREATE OR REPLACE 
PROCEDURE POPULATE_ACTOR_QUOTES (id_actor char) 
AS 
    CURSOR quote_recs IS 
     SELECT m.title, 
      m.year, 
      r.roleName, 
      q.quotechar 
     from quote q, 
      role r, 
      rolequote rq, 
      actor a, 
      movie m 
     where rq.quoteID = q.quoteID 
     AND rq.roleID = r.roleID 
     AND r.actorID = a.actorID 
     AND r.movieID = m.movieID 
     AND a.actorID = id_actor; 
BEGIN 
    FOR row IN quote_recs 
    LOOP 
     INSERT INTO table(
     SELECT quotes 
     FROM actor_quotes aq 
     WHERE aq.actorId = id_actor) 
     VALUES(
     ACTOR_QUOTE_TYPE(row.title, row.year, row.roleName, row.quotechar) 
    ); 
    end loop; 
END POPULATE_ACTOR_QUOTES; 
/

創建PL/SQL程序稱爲PRINT_ACTOR_QUOTES(通過修改程序POPULATE_ACTOR_QUOTES)與一個單一的參數:打印出對應於名字和姓氏屬性在actorId來(actorId來是過程參數)從演員表以及從嵌套引用表

這打印出所有的報價信息是什麼,我已經創建了:

CREATE OR REPLACE PROCEDURE PRINT_ACTOR_QUOTES (id_actor char) 
AS 
CURSOR quote_recs IS 
SELECT a.firstName,a.lastName, m.title, m.year, r.roleName ,q.quotechar from quote q, role r, 
rolequote rq, actor a, movie m 
where 
rq.quoteID = q.quoteID 
AND 
rq.roleID = r.roleID 
AND 
r.actorID = a.actorID 
AND 
r.movieID = m.movieID 
AND 
a.actorID = id_actor; 
BEGIN 
FOR row IN quote_recs 
LOOP 
    DBMS_OUTPUT.PUT_LINE(row.firstName || ' ' || row.lastName); 

END LOOP; 

END PRINT_ACTOR_QUOTES; 
/

輸出

SQL> EXECUTE PRINT_ACTOR_QUOTES ('00070') 

Dustin     Hoffman 

需要創建一個輸出,它看起來像:

傑夫·戈德布拉姆

|Title   | Year |  Role  |    Quote        | 
---------------------------------------------------------------------------------------------- 
|THE FLY   |1986 |SETH BRUNDLE | 「I’m free and you don’t like it’’ | 
|INDEPENDENCE DAY| 1996 | DAVID LEVINSON | 「I’ve given it a virus」   | 

我有名字和第二名字 - 需要從嵌套的信息QUOTES表

幫助需要!

我有這帶來了從嵌套quotes-所需的信息下面的SELECT查詢只需要將其添加到 - 程序PRINT_ACTOR_QUOTES

SELECT REC.* 
    FROM ACTOR_QUOTES A,TABLE(A.QUOTES) REC 
    WHERE ACTORID = ('00070') 
+0

你的問題不明確,會發生什麼,當您嘗試遍歷這個查詢結果? –

+0

我已創建了第一個和最後一個名稱的輸出中,但我有麻煩下DBMS_OUTPUT.PUT_LINE添加表(row.firstName ||「」 || row.lastName);顯示標題,年份,角色,報價 –

回答

0

我可能失去了一些東西...

CREATE OR REPLACE PROCEDURE PRINT_ACTOR_QUOTES (id_actor char) 
AS 
CURSOR quote_recs IS 
SELECT a.firstName,a.lastName, m.title, m.year, r.roleName ,q.quotechar from quote q, role r, 
rolequote rq, actor a, movie m 
where 
rq.quoteID = q.quoteID 
AND 
rq.roleID = r.roleID 
AND 
r.actorID = a.actorID 
AND 
r.movieID = m.movieID 
AND 
a.actorID = id_actor; 

is_first boolean := true; 

BEGIN 
FOR row IN quote_recs 
LOOP 
if is_first then 
    DBMS_OUTPUT.PUT_LINE(row.firstName || ' ' || row.lastName); 
    DBMS_OUTPUT.PUT_LINE('Title | Year | Role  |  Quote '); 
    is_first := false; 
end if; 

    DBMS_OUTPUT.PUT_LINE(row.title|| ' ' || row.year|| ' ' || row.role || ' ' || row.quotechar); 

END LOOP; 

END PRINT_ACTOR_QUOTES; 
/