要同时查询5个表的每个表最新的一条数据,根据时间来判断数据最新请问如何写一个存储过程实现?写具体点哦!

解决方案 »

  1.   


    --具体内容自己添加
    create or replace procedure test
    iscnt1 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;
    /
      

  2.   

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

  3.   

    根据rowid无法抽取出某个表中最后的数据。
    因为ROWID的排序不是按照插入到表中的先后来排序的。