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_sal);

    end loop;

    close cur_emp;

end;
时间: 2024-10-24 21:38:56

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

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 - 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 - 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; Loo

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 - 01.定义变量、打印信息

declare v_sal number(5) := 6000; begin --if you could not see the output in console, you should set output on first use the command in command line : set serveroutput on dbms_output.put_line(v_sal); end;

Oracle PLSQL Demo - 11.定义包头[Define PACKAGE]

CREATE OR REPLACE PACKAGE temp_package_demo is v_demo NUMBER(3); PROCEDURE p_demo_1(userid NUMBER DEFAULT v_demo, SAL number); FUNCTION f_demo(userid NUMBER) RETURN BOOLEAN; END temp_package_demo;

Oracle PLSQL Demo - 12.定义包体[Define PACKAGE BODY]

CREATE OR REPLACE PACKAGE BODY temp_package_demo is FUNCTION f_demo(userid NUMBER) RETURN BOOLEAN IS v_temp varchar2(1); BEGIN SELECT 1 INTO v_temp FROM scott.emp WHERE empno = userid; RETURN TRUE; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN FALSE; END;

Oracle-35-隐式游标&显式游标

一.游标作用(或定义) 1.PL/SQL提供游标机制处理多行记录结果集: 2.游标类似于指针,使应用程序一次可以处理其中的一行记录,比如将游标放入一个for循环中,每循环一次就处理一行记录,那么循环n次就可以处理n行记录: 3.Oracle中,可以分为显式游标和隐式游标两种,比如select*fromstudent就是用隐式游标进行遍历student表,然后将查询结果展示: 4.在平常在进行SELECT查询.DML操作Oracle都会自动创建声明"隐式游标"来处理结果数据: 6.如果需

oracle 游标使用(显式游标)

1. Set Serveroutput on; declare Cursor tem_cursor is select * from xuesheng xs; v_row tem_cursor%rowtype; begin open tem_cursor; loop fetch tem_cursor into v_row; exit when tem_cursor%NOTFOUND; dbms_output.put_line(v_row.xing_ming); end loop; close t