如何将不同表中的列加载到游标中并显示它们?

时间:2014-10-08 17:38:51

标签: sql oracle

我想在GAMETABLE中显示所有行,并在HOWTOPLAY中显示其中一行。我已经google了但是无法弄清楚如何将2个表中的列加载到一个游标中并显示它们。

使用oracle 11g。

这是我的存储过程代码:

  PROCEDURE GetLotteryGame (lg_id IN number, lg_ref OUT lotg_ref_cursor) IS
   BEGIN
   OPEN lg_ref FOR
    SELECT a.GAMEDETAILSID,a.GAMENAME,a.GAMECOST,a.GAMEDESCRIPTION,a.WHERETOPLAY,b.HOWTOPLAYINFO
      FROM GAMEDETAILS a 
        INNER JOIN HOWTOPLAY b
          on b.GAMEDETAILSID = a.GAMEDETAILSID
     WHERE a.GAMEDETAILSID >= lg_id;
END GetLotteryGame;

这是我的通话程序代码:

SET SERVEROUTPUT ON size 100000

DECLARE 
v_cursor             LOTTERYGAMEPKG.lotg_ref_cursor;
v_gamedetailsid      GAMEDETAILS.gamedetailsID%type;
v_gamename           GAMEDETAILS.gamename%type;
v_gamecost           GAMEDETAILS.gamecost%type;
v_gamedescription    GAMEDETAILS.gamedescription%type;
v_wheretoplay        GAMEDETAILS.wheretoplay%type;
v_howtoplayinfo      HOWTOPLAY.howtoplayinfo%type;
BEGIN
LOTTERYGAMEPKG.GetLotteryGame(lg_id => 1,
                          lg_ref => v_cursor);

LOOP
  FETCH v_cursor
  INTO v_gamedetailsID, v_gamename, v_gamecost, v_gamedescription, v_wheretoplay,         v_howtoplayinfo;
EXIT WHEN v_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_gamedetailsID || ',' || v_gamename || ',' || v_gamecost || ',' || v_gamedescription || ',' || v_wheretoplay || ',' v_howtoplayinfo);
END LOOP;
CLOSE v_cursor;
END;

错误报告:

Error report -
ORA-06550: line 17, column 143:
PLS-00103: Encountered the symbol "V_HOWTOPLAYINFO" when expecting one of the following:

) , * & = - + < / > at in is mod remainder not rem =>
<an exponent (**)> <> or != or ~= >= <= <> and or like like2
like4 likec as between from using || member submultiset
The symbol "," was substituted for "V_HOWTOPLAYINFO" to continue.
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

1 个答案:

答案 0 :(得分:0)

您忘记了',' v_howtoplayinfo)之间的联合运算符。

应为',' || v_howtoplayinfo)

顺便说一下,你可以打破这么长的路线。如果你这样做,你可以阅读它们而不必向右滚动,你更有可能自己发现这些错误。