尝试定义一个ID,以便每次运行游标时游标都不必通过where子句查找ID。有办法吗?我尝试编译代码没有成功:(下面是我的代码:(预先感谢)
create or replace PROCEDURE PROC
is
CURSOR Sample IS
SELECT distinct lpad(DATA_DATE, 7, 0) as DATA_DAY
from (
select
v.DATA_DATE,
v.HR,
sv.submission_value_id
from value v
inner join submission s on s.value_id = v.value_id
where sv.SUBMISSIONE_ID NOT IN (
SELECT SUBMISSION_ID FROM FLAG WHERE FLAG.FLAG_ID = (SELECT FLAG_ID from FLAG where FLAG_TX = 'Processed / Calculated'))
and v.data_date is not null
)
where data_date is not null;
l_day days%ROWTYPE;
BEGIN
SELECT FLAG_ID into v_flag_id from FLAG where FLAG_TX = 'Processed / Calculated';
我想做的是保存游标,使其不必一直查找该flag_id,而已对其进行了定义,以便游标可以拉出它。可以这样做吗?
答案 0 :(得分:1)
如果我理解您的要求(通过阅读标题而不是您提供的示例),我想您需要一个参数化游标。这是一个基于Scott模式的示例:
SQL> set serveroutput on;
SQL> declare
2 l_deptno dept.deptno%type;
3
4 cursor c_emp (par_deptno in dept.deptno%type) is
5 select ename
6 from emp
7 where deptno = par_deptno;
8 c_emp_r c_emp%rowtype;
9 begin
10 l_deptno := 10;
11 open c_emp(l_deptno);
12 loop
13 fetch c_emp into c_emp_r;
14 exit when c_emp%notfound;
15 dbms_output.put_line(c_emp_r.ename);
16 end loop;
17 close c_emp;
18 end;
19 /
CLARK
KING
MILLER
PL/SQL procedure successfully completed.
SQL>