使用存储过程参数修改游标select语句

use stored procedure parameter modify cursor select statement

我有一个存储过程,可以根据其他几个创建 table。我有一个名为 "filterDown" 的存储过程参数,它将是一个 ID。如果 filterDown 为 =0,那么我想包括所有 ID。如果filterDown是别的,我只想select那个ID。

这是我在代码中的游标声明:

    create or replace PROCEDURE country ( 
      fromDate IN DATE,
      toDate IN DATE,
      filterDown IN INT,
      chunkSize IN INT
      ) AS 

    --cursor
    cursor cc is
      select c.id, cd.population_total_count, cd.evaluation_date, cf.gdp_total_dollars
      from countries c
      join country_demographics cd on c.id = cd.country_id
      join country_financials cf on cd.country_id = cf.country_id and cf.evaluation_date = cd.evaluation_date
      where cd.evaluation_date > fromDate and cd.evaluation_date < toDate
      order by c.id,cd.evaluation_date;

--lots more code down here.....

换句话说,存储过程应该可以根据国家/地区ID使用此参数进行过滤,默认值表示应包括所有国家/地区。当程序完成时,不符合标准的国家不应出现在派生 table 中。

我如何在我的光标中指定做这样的事情?

编辑: 以下是我调用过程的方式:

create or replace procedure testing as
  UPPER1 DATE;
  LOWER1 DATE;
  FILTERON1 NUMBER;
  CHUNKSIZE1 NUMBER;
BEGIN
  UPPER1 := TO_DATE('2000/01/01','yyyy/mm/dd');
  LOWER1 := TO_DATE('2005/01/01','yyyy/mm/dd');
  FILTERON1 := 143;
  CHUNKSIZE1 := 250;

  country(UPPER1,LOWER1,FILTERON1,CHUNKSIZE1);

END;

最简单的方法是在 WHERE 子句中添加类似这样的内容

...
where cd.evaluation_date > fromDate 
  and cd.evaluation_date < toDate
  and (filterDown = 0 or c.id = filterDown)
...