帮个忙啊,A表中的一个字段为varchar2类型,里面存放的是B表的表名,我想查B表
select * from table(select subs_type_tbname from A where subs_svc_type = 2001) 
请问错在什么地方啊?
在线等

解决方案 »

  1.   


    select * from table(select subs_type_tbname from A where subs_svc_type = 2001)  a
    加歌任意字母试一试
     
      

  2.   

    A表中的一个字段为varchar2类型 ,存储的是字符串,字符串当然不能用在table()了,如果是nest table就可以这么用。像你的这种使用字符串存表名的方法,只能用execute immediate访问你的表.
      

  3.   

    execute immediate?说详细点好不?
      

  4.   

    没看错的话你这个写法是嵌套表的写法啊.
    如果你真的是访问的嵌套表的话改成这样就好了.
    select * from table(select t.subs_type_tbname from A t where t.subs_svc_type = 2001) 
      

  5.   

    select * from (select subs_type_tbname from A as a_table where subs_svc_type = 2001)很久没用oracle了,不知道这么写可不可以
    其实你那个地方可以不要写table你试一试吧
      

  6.   

    没用table,执行sql语句,可以,使用oracle sql develop
      

  7.   

    declare 
    v_sql varchar2(200);
    begin 
     v_sql:='select * from table(select t.subs_type_tbname from A t where t.subs_svc_type = 2001) ';
     execute immediate v_sql;
    end;
      

  8.   


    要这么用!!DECLARE
      V_SQL VARCHAR2(200);
      l_i INT;
    BEGIN
      select t.subs_type_tbname INTO V_SQL from A t where t.subs_svc_type = 2001;
      V_SQL := 'select count(*) from '||V_SQL;
      EXECUTE IMMEDIATE V_SQL INTO l_i;
      dbms_output.put_line(l_i);
    END;
    /