日期:2014-05-16  浏览次数:20672 次

求一个简单的存储过程
要同时查询5个表的每个表最新的一条数据,根据时间来判断数据最新。。。

请问如何写一个存储过程实现?写具体点哦!

------解决方案--------------------
SQL code

--具体内容自己添加
create or replace procedure test
is

cnt1 number default 0;
cnt2 number default 0;
cnt3 number default 0;
cnt4 number default 0;
cnt5 number default 0;

begin
   with tab as (select 20110920 dt from dual )
select max(dt) into cnt1 from tab;
--select max(dt) into cnt1 from tab2;
--select max(dt) into cnt1 from tab3;
--select max(dt) into cnt1 from tab4;
--select max(dt) into cnt1 from tab5;

if cnt1 > cnt2 then
   DBMS_OUTPUT.PUT_LINE('cnt1 is the biggest');
end if;

end;
/

------解决方案--------------------
楼上理解的不对吧,是检索5个表,把每个表中最后的数据抽出来。关键是判断最新数据,不能根据表中的某个表示时间的字段来判断吗?如果没有这样的字段的话,根据rowid不知道行不行?
------解决方案--------------------
探讨
楼上理解的不对吧,是检索5个表,把每个表中最后的数据抽出来。关键是判断最新数据,不能根据表中的某个表示时间的字段来判断吗?如果没有这样的字段的话,根据rowid不知道行不行?