1

我很难将 oracle SP 转换为 MySQL 中的 SP。特别是对于“连接方式”和“类型”。

这是使用 Oracle 存储过程解决的问题。

有一个有 3 列的表

ID  |Last_Modified | Flag   
1   |2011-12-11 02:00:00|   0   
2   |2011-12-13 02:00:00|   0   
3   |2011-12-02 02:00:00|   0 
4   |2011-12-12 02:00:00|   0 

存储过程“getback(String pId, String pLast_Modified)。例如 pId =”1,2,3” 和 pLast_Modified = “2011-12-11 02:00:00, 2011-12-13 02:00:00, 2011-12-01 02:00:00”。

逻辑是,对于相同的 ID,如果表中的 last_modified 晚于传递的 last_modified,则将该记录的标志设置为“1”。

这是Oracle存储过程:

create or replace procedure test1(
p_ids varchar2,   
p_dates varchar2  
) IS

TYPE id_type IS TABLE OF NUMBER INDEX BY VARCHAR2(64);
TYPE date_type IS TABLE OF DATE INDEX BY VARCHAR2(64);

ids id_type;
last_updated date_type;
lvar1 varchar2(200);
lvar2 varchar2(200);



cursor c1 is 
With ids as (select rownum id, regexp_substr(p_ids,'[^,]+', 1, level) val from dual
connect by regexp_substr(p_ids, '[^,]+', 1, level) is not null), 
lupdated as (select rownum id, regexp_substr(p_dates,'[^,]+', 1, level) val from dual
connect by regexp_substr(p_dates, '[^,]+', 1, level) is not null)
select lut.id, 
case when lut.last_updated > to_date(lu.val,'yyyy-mm-dd hh24:mi:ss') then 1
          else 0
end flag
from last_updated_tbl lut,ids,lupdated lu
where lut.id = ids.val
and   ids.id = lu.id
;

BEGIN
open c1;
loop
 fetch c1 into lvar1,lvar2;
 exit when c1%notfound;

 dbms_output.put_line(lvar1||' flag:'||lvar2);

end loop;

close c1;

END;
4

0 回答 0