declare
  d Number;
begin
  select DepartId into d from MMT_USERS M INNER JOIN CNT_Employee C on M.EMP_ID = C.ID where M.NAME = 'bht';
  if d = 0 THEN
    select * from 表A;
  else
    select * from 表B;
  end if;
end;
在oracle这样把查询到的一个ID结果赋值给声明的变量d,然后用d来做判断条件进行表的显示。  有点问题,请大家帮忙修正一下,谢谢!!!

解决方案 »

  1.   

    ORACLE的过程、函数、匿名块中不允许select   *   from   表A; 
    必须使用select col1,col2...coln into var1,var2..varn from tablename;
      

  2.   

    declare 
        d   Number; 
    begin 
        select   DepartId   into   d   from   MMT_USERS   M   INNER   JOIN   CNT_Employee   C   on   M.EMP_ID   =   C.ID   where   M.NAME   =   'bht '; 
        if   d   =   0   THEN 
            select   field1,.. into ......   from   表A; 
        else 
            select   field1,.. into ......    from   表B; 
        end   if; 
    end; 
    你的思路是对的,但是语法不正确
      

  3.   

    declare 
        d   Number;
        type table_cur is ref cursor;
        table_ab table_cur;
    begin 
        select   DepartId   into   d   from   MMT_USERS   M   INNER   JOIN   CNT_Employee   C   on   M.EMP_ID   =   C.ID   where   M.NAME   =   'bht '; 
        if   d   =   0   THEN 
           open table_ab for select   *   from   表A; 
        else 
           open table_ab for select   *   from   表B; 
        end   if; 
    end;