返回最后 5 轮并将它们传递到 select 中的位置

returning last 5 rounds and passing them into where in select

    create or replace function get_last_5_rounds(i_party_id in number) return SYS_REFCURSOR as  
      resault_set SYS_REFCURSOR;
       v_round VAR_ROUND:=VAR_ROUND();

 begin  
SELECT round
    BULK COLLECT INTO v_round  
    FROM (SELECT DISTINCT session_id,
        ROUND
      FROM super_six_tickets
      where party_id = i_party_id
      ORDER BY session_id DESC
      )
    WHERE ROWNUM <= 5;
 OPEN RESAULT_SET for  
      select rp.session_id, s.symbol_name_in_number ball_number,
             rp.position ,
             rp.additional_symbol
      from   rp_deck rp,
             symbols s
      where  session_id MEMBER OF v_round 
      and    s.game_name_id in  38
      and    s.id = rp.card_name_id
      and    s.client_id = 1
      and    rp.position < 36
     order by rp.position ;  
  RETURN RESAULT_SET;
end get_last_5_rounds;

我有一个函数可以 return ball_number,最后 5 轮的位置 (p_round)。

在第一个 select 中,我得到了 5 个回合,但在第二个 select 中我也遇到了错误 select:

an INTO clause is expected in this select

我如何通过第一个 select 开始的所有回合并用 ,(逗号)分隔它们以将它们包含在子句中?

谢谢!

已编辑:

现在我得到这个:

我需要将所有位置和球号分开以获得唯一的会话 ID。现在我正在按位置排序。 我该怎么做?

In first select I get 5 rounds, but I am also getting error on the second select:

即使您的第一个 select 也会抛出错误,因为您试图将多行放在一个维度变量中。在您的情况下,您需要 loop 并填充您的变量,或者您需要创建一个 collection 并执行 bulk 操作以适合所有行。

How will I pass all rounds from first select and separate them with , (comma) to include them IN clause ?

您需要 nested table 才能达到您的要求。请参阅下面的工作代码并阅读内联解释以进行理解。

表格:

CREATE TABLE super_six_tickets(session_id NUMBER,ROUND NUMBER);
/
CREATE TABLE  rp_deck (session_id NUMBER, position NUMBER,additional_symbol VARCHAR2(10));
/
CREATE TABLE symbols(symbol_name_in_number NUMBER);
/
 --Create a type of number to hold the result of you first query.
CREATE TYPE VAR_ROUND IS TABLE OF NUMBER;
/

函数:

CREATE OR REPLACE  FUNCTION get_last_5_rounds
    RETURN SYS_REFCURSOR
  AS
    resault_set SYS_REFCURSOR;

    --Initialization of varaible of nested table type 
    v_round VAR_ROUND:=VAR_ROUND();

BEGIN

    SELECT round
    BULK COLLECT INTO v_round  --<--Fetching the rounds information in the variable
    FROM
      (SELECT DISTINCT session_id,
        ROUND
      FROM super_six_tickets
      ORDER BY session_id DESC
      )
    WHERE ROWNUM <= 5;

--Opening Sys_refcursor to get the result.
    OPEN RESAULT_SET for   
    SELECT s.symbol_name_in_number ball_number,
           rp.position,
           rp.additional_symbol
    FROM rp_deck rp,
         symbols s
    WHERE rp.session_id MEMBER OF v_round --<-- checking In clause. 
    -- You can use this as well. However `MEMBER OF` clause is provided by Oracle to handle such situations.  
    --> rp.session_id in (Select column_value from table(v_round)) 
    ORDER BY rp.position ASC;

    RETURN RESAULT_SET;

  END get_last_5_rounds;