【问题标题】:dBEAVER 7.3.3 how to execute oracle stored proceduredBEAVER 7.3.3 如何执行oracle存储过程
【发布时间】:2021-01-27 09:36:05
【问题描述】:

请您帮我在 dBEAVER 中运行/执行 oracle 程序吗? 这是您可以查看输入参数的块 enter image description here

【问题讨论】:

    标签: oracle procedure execute dbeaver


    【解决方案1】:

    使用 OUT 光标的过程

    我发现无法使用光标输出参数执行过程并将其显示在结果网格中。所以我认为除了在匿名块中绑定游标之外别无他法(然后用游标做你需要的)。

    CREATE PROCEDURE test_proc(
      datemin DATE,
      datemax DATE,
      RES OUT sys_refcursor
    )
    AS
    BEGIN
     OPEN res
     FOR SELECT datemin + LEVEL
           FROM dual
        CONNECT BY LEVEL < datemax - datemin;
    END;
    
    DECLARE
      l_cur sys_refcursor;
      l_datemin DATE;
      l_datemax DATE;
      l_date date;
    BEGIN
      l_datemin := to_date(:dmin, 'YYYY-MM-DD');
      l_datemax := to_date(:dmax, 'YYYY-MM-DD');
      
      -- execute the procedure
      test_proc(l_datemin, l_datemax, l_cur);
    
      -- do something with the cursor, here just print to output
      loop
        fetch l_cur into l_date;
        exit when l_cur%notfound;
        dbms_output.put_line(to_char(l_date, 'YYYY-MM-DD'));
      end loop;
    END;
    

    函数返回光标

    这种情况看起来更好,返回的光标可以显示在查询网格中并检查它的值(您可能会被问到在执行查询时阻止关闭光标的设置,选择保持光标向上的选项)。

    create or replace function test_fun(
      datemin DATE,
      datemax DATE
    ) return sys_refcursor
    AS
      l_res sys_refcursor;
    BEGIN
     OPEN l_res
     FOR SELECT datemin + LEVEL
           FROM dual
        CONNECT BY LEVEL < datemax - datemin;
     RETURN l_res;
    END;
    
    SELECT
      1 a,
      'xyz' b,
      test_fun(to_date(:dmin, 'YYYY-MM-DD'), to_date(:dmax, 'YYYY-MM-DD')) c
    FROM dual;
    

    【讨论】:

    • 你好我还是有问题,我是这样运行的:begin REQ_SK_SRB_BSE_ADR_LCC_DATA(:DATEMIN,:DATEMAX,:COUNTRY);结尾;但是光标呢,我应该把它也放在参数中吗?
    • 我已经通过使用游标的示例更新了我的答案
    猜你喜欢
    • 2010-12-23
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多