create or replace procedure p_complte_d_rank(filterStr varchar2 , p_period varchar2) is
type c_total is ref cursor;
v_total c_total; -- 游标记录每行值
v_unitid SGCC_FACT_COMPLETE_D.unit_id%type; -- 单位ID
v_total_value number; -- 总得分
v_rank number ; -- 排名
beginopen v_total for
select unit_id from sgcc_fact_complete_d
where sj_type= p_period and unit_id = filterStr; -- 这样写就没有值循环
-- select unit_id from sgcc_fact_complete_d
-- where sj_type= '201104' and unit_id = '501101010000009112'; 这样写就有值循环
LOOP
fetch v_total into v_unitid ;
exit when v_total%notfound;
dbms_output.put_line(v_unitid);
end LOOP ;
end p_complte_d_rank;我来描述下问题, 我的输入参数是 '201104' ,'501101010000009112' , 如果我用输入参数来代替 p_period , filterStr的值, 就没有值循环, 如果我直接把时间 , 和单位编号写固定, 就有值可以进行循环, 请问各位大神, 这是什么原因造成的, 小弟不才, 在线等 。。
解决方案 »
- 哪个有比较好的oracle ODI开发资料?先谢了........
- 修改计算机名后,OracleDBConsole不能启动
- 在线高分求解:PL SQL Procedure/Function
- identify怎么用?
- 关于oracle 10g的问题
- 查询出来的俩个字段如何相加啊 ??
- 请问OracleDatabase10G可以在vista上装吗?急
- 有一个看似简单的需求,请高手帮忙看看有没有办法实现,谢谢了
- 在update的时候,怎么让别的表条件也要满足的时候才能执行呢?
- 请问各位 传统dba和etl 这2个职位有什么区别?
- oracle 根据当前时间+时间段=时间期限问题
- 如何在Program Units中定義一個全局變量的數組,給ITEM級觸發器WHEN-VALIDATE-ITME調用???????????
open v_total for
select unit_id from sgcc_fact_complete_d
where sj_type= p_period and unit_id = filterStr;
begin
...
按照你的意思, 我改成如下, 还是不行呢, 没有值进行循环create or replace procedure p_complte_d_rank(filterStr varchar2 , p_period varchar2) is
v_unitid SGCC_FACT_COMPLETE_D.unit_id%type; -- 单位ID
v_total_value number; -- 总得分
v_rank number ; -- 排名
cursor c_total is select unit_id from sgcc_fact_complete_d
where sj_type= p_period and unit_id = filterStr;
begin
for data in c_total
loop
dbms_output.put_line('111');
end loop;
end p_complte_d_rank;
CREATE OR REPLACE PROCEDURE p_complte_d_rank(filterStr VARCHAR2,
p_period VARCHAR2) IS
TYPE c_total IS REF CURSOR;
v_total c_total; -- 游标记录每行值
v_unitid SGCC_FACT_COMPLETE_D.unit_id%TYPE; -- 单位ID
v_total_value NUMBER; -- 总得分
v_rank NUMBER; -- 排名
BEGIN OPEN v_total FOR 'SELECT unit_id
FROM sgcc_fact_complete_d
WHERE sj_type = ''' || p_period || ''' AND unit_id = ''' || filterStr || '''';
LOOP
FETCH v_total
INTO v_unitid;
EXIT WHEN v_total%NOTFOUND;
dbms_output.put_line(v_unitid);
END LOOP;
END p_complte_d_rank;
open v_total for
select unit_id from sgcc_fact_complete_d
where sj_type= ''||p_period||'' and unit_id = ''||filterStr ||'';
多个值的话。
open v_total for
select unit_id from sgcc_fact_complete_d
where sj_type= ''||p_period||'' and unit_id in (这里要怎么用单引号
);
select unit_id from sgcc_fact_complete_d
where sj_type= ''||p_period||'' and substr(',' || filterStr || ',',',' || unit_id || ',') > 0
;
如果用in就得动态sql了.
open v_total for
select unit_id from sgcc_fact_complete_d
where sj_type= ''||p_period||'' and instr(',' || filterStr || ',',',' || unit_id || ',') > 0
;
select unit_id from sgcc_fact_complete_d
where sj_type= "||p_period||" and unit_id in ("|| REPLACE( '||filterStr||',',','","' ))
);这个尝试一下
select * from where unit_id in (501101010000009112,501101010000009113,501101010000009111)
等价于:
select * from where and instr(',501101010000009112,501101010000009113,501101010000009111,',',' || unit_id || ',') > 0
意思是字符串',501101010000009112,501101010000009113,501101010000009111,'中包含',unit_id,',加逗号是为了确定你传递参数中查询的条件,比如:',501101010000009112,'表示501101010000009112是你的检索条件。