PLSQL:可以在运行时创建记录类型的oracle变量

时间:2014-11-03 09:48:56

标签: oracle plsql

DECLARE 
LV_COL_NAME VARCHAR2(100);
LV_QUERY VARCHAR2(4000);

  type cur is ref cursor;
  select_cur cur;

  type rec is select_cur%rowtype;
  LT_REC rec;


BEGIN 


SELECT COL_NAME INTO LV_COL_NAME FROM TEST; --contains column info of emp table.

  cursor select_cur
  for 'SELECT '||LV_COL_NAME||'
       FROM HMCNSPROD.HM_CONSUMER WHERE ROWNUM=1';

  fetch select_cur bulk collect INTO LT_REC;    
  DBMS_OUTPUT.PUT_LINE('LT_REC: '||LT_REC.count); 
  close select_cur;        


EXCEPTION
  WHEN OTHERS
    THEN
    DBMS_OUTPUT.PUT_LINE('ERROR: '||SQLERRM); 
END;

1 个答案:

答案 0 :(得分:0)

您不能对引用游标使用%rowtype声明。也许它适用于强大的"定义了引用游标,但我没有测试。

强有力的宣言如下:

type recis ref cursor return HMCNSPROD.HM_CONSUMER%rowtype;