存储过程中使用 type接受*的数据,报错没有足够的值。不想改动type,如何解决?

解决方案 »

  1.   

    增加虚拟列值
    如:
    select a.col1,a.col2,null into my_arr from a;存储过程最好不要用select *之类的写法,写出实际的列,影响性能,扩展性,可维护性,并易出问题。
      

  2.   

    当不知道表中列的数据类型时,使用 type 变量名%rowtype即可以将*(表中所有列的数据类型定义)
    例:
    declare
    type t_emp_cursor is ref cursor;
    v_cursor t_emp_cursor;
    v_emp emp%rowtype;begin
    open v_cursor for
    select *
    from emp e 
    where deptno=20 ;
    loop
    fetch v_cursor into v_emp;
    exit when v_cursor%notfound;
    dbms_output.put_line(
    'no:'||v_emp.empno||
    ',name:'||v_emp.ename||
    ',sal:'||v_emp.sal
    );
    close v_cursor;
    end loop;