Oracle PLSQL Demo - 20.弱类型REF游标[没有指定查询类型,也不指定返回类型]

declare

    Type ref_cur_variable IS REF cursor;
    cur_variable ref_cur_variable;

    v_ename varchar2(10);
    v_deptno number(2);
    v_sal number(7,2);

    v_sql varchar2(100) := ‘select t.ename, t.deptno, t.sal from scott.emp t‘;

begin

    Open cur_variable For v_sql;

    Loop
        fetch cur_variable
            InTo v_ename, v_deptno, v_sal;
        Exit When cur_variable%NotFound;
        dbms_output.put_line(cur_variable%rowcount || ‘ -> ‘ || v_ename ||
                             ‘   ‘ || v_deptno || ‘   ‘ || v_sal);
    End Loop;
    Close cur_variable;

end;
时间: 2024-12-20 17:56:45

Oracle PLSQL Demo - 20.弱类型REF游标[没有指定查询类型,也不指定返回类型]的相关文章

Oracle PLSQL Demo - 16.弱类型REF游标[没有指定查询类型,已指定返回类型]

declare Type ref_cur_variable IS REF cursor; cur_variable ref_cur_variable; rec_emp scott.emp%RowType; v_sql varchar2(100) := 'select * from scott.emp t'; begin Open cur_variable For v_sql; Loop fetch cur_variable InTo rec_emp; Exit When cur_variable

Oracle PLSQL Demo - 10.For Loop遍历游标[FOR LOOP CURSOR]

declare cursor cur_emp is select t.* from scott.emp t; begin for r_emp in cur_emp loop dbms_output.put_line(r_emp.empno || ' ' || r_emp.sal); end loop; end;

Oracle PLSQL Demo - 08.定义显式游标[Define CURSOR, Open, Fetch, Close CURSOR]

declare v_empno scott.emp.empno%type; v_sal scott.emp.sal%type; cursor cur_emp is select t.empno, t.sal from scott.emp t; begin open cur_emp; loop fetch cur_emp into v_empno, v_sal; exit when cur_emp%notfound; dbms_output.put_line(v_empno || ' ' || v

转: 在hibernate中查询使用list,map定制返回类型

在使用hibernate进行查询时,使用得最多的还是通过构建hql进行查询了.在查询的过程当中,除使用经常的查询对象方法之外,还会遇到查询一个属性,或一组聚集结果的情况.在这种情况下,我们通常就需要对返回的结构进行处理.    一般情况下,我们通过构建hql,并通过设置query的resultTransformer来定制返回结果的类型,一般设置为map属性,如下所示: 1 Query query = session.createQuery("hql"); 2 query.setResu

Oracle PLSQL Demo - 15.强类型REF游标[预先指定查询类型与返回类型]

declare Type ref_cur_emp IS REF CURSOR RETURN scott.emp%RowType; cur_emp ref_cur_emp; rec_emp cur_emp%RowType; v_sql varchar2(100) := 'select * from scott.emp t'; begin -- xxx Open cur_emp For v_sql; Open cur_emp For select * from scott.emp t; Loop f

Oracle PLSQL Demo - 17.游标查询个别字段(非整表)

declare Type ref_cur_variable IS REF cursor; cur_variable ref_cur_variable; v_empno scott.emp.empno%type; v_ename scott.emp.ename%type; v_sql varchar2(100) := 'select t.empno, t.ename from scott.emp t'; begin Open cur_variable For v_sql; Loop fetch c

Oracle PLSQL Demo - 14.定义定参数的显示游标

declare v_empno scott.emp.empno%type; v_sal scott.emp.sal%type; cursor cur_emp(v_empno number default 7369) is select t.empno, t.sal from scott.emp t where t.empno = v_empno; begin open cur_emp(7566); loop fetch cur_emp into v_empno, v_sal; exit when

Oracle PLSQL Demo - 09.Open、Fetch遍历游标[Open, Fetch, Close Record CURSOR]

declare r_emp scott.emp%rowtype; cursor cur_emp is select t.* from scott.emp t; begin open cur_emp; loop fetch cur_emp into r_emp; exit when cur_emp%notfound; dbms_output.put_line(r_emp.empno || ' ' || r_emp.sal); end loop; close cur_emp; end;

Oracle PLSQL Demo - 13.游标的各种属性[Found NotFound ISOpen RowCount CURSOR]

declare r_emp scott.emp%rowtype; cursor cur_emp is select t.* from scott.emp t; begin open cur_emp; if cur_emp%isopen then dbms_output.put_line('is open...'); end if; loop fetch cur_emp into r_emp; if cur_emp%found then dbms_output.put_line('found...