oracle 如何在光标上添加参数弹出

pbossiut  于 2023-06-22  发布在  Oracle
关注(0)|答案(2)|浏览(81)

我有一个游标,它从一个表中获取数据,并在特定的时间段内复制到另一个表,参数为fromdatetodate

select * from table where fromdate = date1 and todate = date2

当我运行的脚本应该打开一个弹出窗口输入从日期和日期输入参数。
我们可以在Oracle SQL开发人员游标中做到这一点。

fnx2tebb

fnx2tebb1#

如何选择你可以重复使用 * 无限期 *?如果使用匿名PL/SQL块,则必须保持SQL Developer处于打开状态,或者将代码保存到文件中,以便在需要时打开并运行。
如果您切换到存储过程,它将保留在数据库中,以备将来使用。就像这样:

SQL> create or replace procedure p_test (par_date_from in date) is
  2  begin
  3    for cur_r in (select ename, hiredate
  4                  from emp
  5                  where hiredate >= par_date_from   --> this is your parameter
  6                 )
  7    loop
  8      dbms_output.put_line(cur_r.ename ||' '|| to_char(cur_r.hiredate, 'dd.mm.yyyy'));
  9    end loop;
 10  end;
 11  /

Procedure created.

这样使用:

SQL> set serveroutput on
SQL> begin
  2    p_test (date '1982-01-01');      --> date parameter passed to a procedure
  3  end;
  4  /
SCOTT 09.12.1982
ADAMS 12.01.1983
MILLER 23.01.1982

PL/SQL procedure successfully completed.

SQL>
yjghlzjz

yjghlzjz2#

如果没有一个完整的脚本提供更多的上下文,看起来你想使用一个bind变量:

select * from table where fromdate = :date1 and todate = :date2

SQL Developer应提供一个允许您定义变量的弹出窗口(前提是您不以编程方式定义它们)。
你也可以尝试使用替代变量:

select * from table where fromdate = &date1 and todate = &date2

相关问题