在 Cursor 中动态查询 %rowtype

Dynamic query in Cursor for %rowtype

我需要创建一个记录类型来包含上述

查询的结果集
V_SQL VARCHAR2(200) := 'SELECT T1.'||record_id||',T1.'||card_no||',T2.TEST_CARD_NO, T1.'||type_cc||' FROM '|| table_name||' T1 
                INNER JOIN TEST T2 ON 
                T2.ID = T1.'||record_id;

这样我就可以在循环执行语句

中使用 t1 C_BRNGB_EXTRACT%ROWTYPE(在 l_BRNGB_EXTRACT 内为 t2.col4%TYPE 加上另一列)
CREATE OR REPLACE PROCEDURE "GCCPMAINT"."FUNCTION_CURSOR"(table_name VARCHAR2,record_id VARCHAR2,card_no VARCHAR2,type_cc VARCHAR2)
AS
limit_in NUMBER:=100;
V_SQL VARCHAR2(200) := 'SELECT T1.'||record_id||',T1.'||card_no||',T2.TEST_CARD_NO, T1.'||type_cc||' FROM '|| table_name||' T1 
            INNER JOIN TEST T2 ON 
            T2.ID = T1.'||record_id;

  TYPE BRNGB_EXTRACT IS REF CURSOR;
  C_BRNGB_EXTRACT BRNGB_EXTRACT;
  TYPE BRNGB_EXTRACT1 IS TABLE OF C_BRNGB_EXTRACT%ROWTYPE;
  l_BRNGB_EXTRACT BRNGB_EXTRACT1;    

BEGIN

OPEN C_BRNGB_EXTRACT FOR V_SQL;

   LOOP
       FETCH C_BRNGB_EXTRACT BULK COLLECT INTO l_BRNGB_EXTRACT LIMIT limit_in;
               EXIT WHEN l_BRNGB_EXTRACT.COUNT = 0;
                           FORALL indx IN 1 .. l_BRNGB_EXTRACT.COUNT
        EXECUTE IMMEDIATE 'UPDATE table_name SET CARD_NO=:1 WHERE CARD_NO=:2 AND RECORD_ID=:3' USING l_BRNGB_EXTRACT(indx).test_card_no,l_BRNGB_EXTRACT(indx).CARD_NO,l_BRNGB_EXTRACT(indx).RECORD_ID;
END LOOP;
CLOSE C_BRNGB_EXTRACT;
COMMIT;
END;

对于上述存储过程,我收到以下错误

PLS-00320: the declaration of the type of this expression is incomplete or malformed PL/SQL: Item ignored PLS-00597: expression 'L_BRNGB_EXTRACT' in the INTO list is of wrong type PL/SQL: SQL Statement ignored PLS-00487: Invalid reference to variable 'C_BRNGB_EXTRACT%ROWTYPE'

请帮我解决这个问题。

我得到了解决方案

 TYPE BRNGB_EXTRACT IS REF CURSOR;
  C_BRNGB_EXTRACT BRNGB_EXTRACT;
 -- TYPE BRNGB_EXTRACT1 IS TABLE OF C_BRNGB_EXTRACT%ROWTYPE;

  TYPE BRNGB_EXTRACT1 IS RECORD  (
  record_id varchar(30),
  card_no varchar(30),
  TEST_CARD_NO varchar(30)
  );
  type test_rec_arr is table of BRNGB_EXTRACT1 index by pls_integer;
  l_BRNGB_EXTRACT test_rec_arr;