从嵌套表打印报价

时间:2012-05-07 07:45:59

标签: oracle plsql oracle10g

尝试完成以下操作:

    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;
/

创建名为PRINT_ACTOR_QUOTES的PL / SQL PROCEDURE(通过修改程序POPULATE_ACTOR_QUOTES),其中包含以下参数:从ACTOR表中打印出与ACTORID相对应的firstname和lastname属性(ACTORID是过程参数)以及打印输出嵌套QUOTES表中的所有引用信息

这就是我创造的:

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

需要创建一个类似于:

的输出

JEFF GOLDBLUM

|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表的信息

需要帮助!

我有以下选择查询从嵌套引号中显示所需信息 - 只需将其添加到 - PROCEDURE PRINT_ACTOR_QUOTES

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

1 个答案:

答案 0 :(得分: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;
/