zoukankan      html  css  js  c++  java
  • oracle游标应用难点 sys_refcursor 和 cursor(转)

    sys_refcursor 和 cursor 优缺点比较

    优点比较

    优点一:sys_refcursor,可以在存储过程中作为参数返回一个table格式的结构集(我把他认为是table类型,容易理解,其实是一个游标集), cursor 只能用在存储过程,函数,包等的实现体中,不能做参数使用。

    优点二:sys_refcursor 这东西可以使用在包中做参数,进行数据库面向对象开放。哈哈。我喜欢。cursor就不能。

    缺点比较:

    缺点:sys_refcursor 不能用open,close ,fetch 进行操作。不好学,难理解。

    cursor可以用 open,close ,fetch操作,容易学,易懂

    其他就目前不知道,至于游标的的基础概念,去google,百度一大堆的。这里就不累赘了。看例子:

    建立一个存储过程

    create or replace procedure up_test(o out sys_refcursor) is
    begin
    open o for select * from lq_test;
    end;

    返回的类型是sys_refcursor;

    建立第二个存储过程

    create or replace procedure up_getData(aMsg out varchar2) is
    type p_table_type is table of lq_test%rowtype;
    p_table p_table_type;
    v sys_refcursor;
    begin
    up_test(v);
    fetch v bulk collect into p_table;
    for i in 1..p_table.count loop
    dbms_output.put_line('字段1:'||p_table(i).v1 || ' 字段2:' || p_table(i).v2);
    end loop;
    end;

    这里要注意fetch 带参数的用法,bulk collect ,这是第集合的操作,必须先定义一个结合类。见上面的例子,还不懂就google了。用法就简单,没啥好介绍的。

    取集合的值应该这样p_table(i).v1,其中i标识几行,带上字段,即可了。呵呵,容易理解。

    原文: http://blog.sina.com.cn/s/blog_638978a40100qjzc.html

  • 相关阅读:
    Can't remove netstandard folder from output path (.net standard)
    website项目的reference问题
    The type exists in both DLLs
    git常用配置
    Map dependencies with code maps
    How to check HTML version of any website
    Bootstrap UI 编辑器
    网上职位要求对照
    Use of implicitly declared global variable
    ResolveUrl in external JavaScript file in asp.net project
  • 原文地址:https://www.cnblogs.com/YangBinChina/p/2629686.html
Copyright © 2011-2022 走看看