• Oracle游标


    游标是用于临时存储一个查询返回的多行数据(结果集),通过遍历游标,可以逐行访问处理改结果集的数据。

    1、使用方式

      声明——>打开——>读取——>关闭

    2、语法

      游标声明

      CURSOR 游标名[(参数列表)] IS 查询语句;

      游标打开:

      OPEN 游标名;

      游标读取:

      FETCH 游标名 INTO 变量列表;

      游标关闭:

      CLOSE 游标名;

    3、游标属性

    游标的属性   返回值类型   说明  
    %ROWCOUNT   整型 获得FETCH语句返回的数据行数
    %FOUND   布尔型 最近的FETCH语句返回的一行数据则为证,否则为假
    %NOTFOUND     布尔型   与%FOUND属性返回值相反
    %ISOPEN   布尔型   游标已经打开时值为真,否则为假

      无参数游标

    declare
        --声明游标
        cursor c_emp is select ename,sal from emp;
        --声明变量
        v_ename emp.ename%type;
        v_sal emp.sal%type;
    begin
        --打开游标
        open c_emp;
        --遍历循环
        loop
            --获取游标中的数据
            fetch c_emp into v_ename,v_sal;
            
            exit when c_emp%notfound;
            dbms_output.put_line('姓名:'||v_name||'工资:'||v_sal);
        end loop;
        --关闭游标
        close c_emp;
        
    end;
    View Code

      有参数游标

    declare
        --声明游标
        cursor c_emp(v_deptno emp.deptno%type) is select ename,sal from emp where deptno=v_deptno;
        --声明变量
        v_ename emp.ename%type;
        v_sal emp.sal%type;
    begin
        --打开游标
        open c_emp(10);
        --遍历循环
        loop
            --获取游标中的数据
            fetch c_emp into v_ename,v_sal;
            
            exit when c_emp%notfound;
            dbms_output.put_line('姓名:'||v_name||'工资:'||v_sal);
        end loop;
        --关闭游标
        close c_emp;
        
    end;
    View Code
  • 相关阅读:
    C# 自定义泛型类,并添加约束
    WPF DataGrid 的RowDetailsTemplate的使用
    jquery腾讯微博
    WPF DataGrid的LoadingRow事件
    WPF DataGrid自定义列DataGridTextColumn.ElementStyle和DataGridTemplateColumn.CellTemplate
    WPF DataGrid支持的列类型
    WPF DataGrid自动生成列
    WPF DataTemplateSelector的使用
    WPF数据模板的数据触发器的使用
    UVa 1601 || POJ 3523 The Morning after Halloween (BFS || 双向BFS && 降维 && 状压)
  • 原文地址:https://www.cnblogs.com/ZJ199012/p/11630111.html
Copyright © 2020-2023  润新知