if exists(
select 1 from all_all_tables t where t.table_name = 'aaaa')
then 
 select * from aaaa 
else 
create table aaaa

解决方案 »

  1.   

    楼上完全错误,那是在ms sql server里面的写法,应该为:
    declare
      v_count number;
    begin
      select count(*) into v_count
      from user_tables
      where table_name = 'AAA';
      if v_count > 0 then
        select * from aaa;
      else
        execute immediate 'create table aaa(a int)';
      end if;
    end;
      

  2.   

    to: railgunman(堕落男人)
    oracle中类似于zsfww1205(努力学习oracle)所说的语句存在吗?
      

  3.   

    to: railgunman(堕落男人)
    语句执行有错误。帮忙再看看。
      

  4.   

    declare
      v_count number;
    begin
      select 1 into v_count from all_all_tables t where t.table_name = 'AAA';
      if v_count > 0 then
        select * from aaa;
      else
        execute immediate 'create table aaa(a int)';
      end if;
    end;
    注意搂住的要求是只要存在表就“select * from aaa”,而不是有数据才进行选择
      

  5.   

    to:zsfww1205(努力学习oracle) 
    语句执行仍有错误。错误同上。表或视图不存在。
      

  6.   

    to:zsfww1205(努力学习oracle) 
    再帮忙看看吧。
      

  7.   

    SQL> declare
      2  v_sql varchar2(200);
      3  v_temp number;
      4  begin
      5  select max(1) into v_temp from user_tables where table_name='TT';
      6  if v_temp is null then
      7     execute immediate 'create table tt (col number)';
      8  else
      9     execute immediate 'select col from tt where rownum=1' into v_temp;
     10  end if;
     11  dbms_output.put_line(v_temp);
     12  end;
     13  /PL/SQL 过程已成功完成。已用时间:  00: 00: 01.12
    SQL> desc tt;
     名称                                      空?      类型
     ----------------------------------------- -------- -----------------------
     COL                                                NUMBERSQL> insert into tt values (11);已创建 1 行。已用时间:  00: 00: 00.50已用时间:  00: 00: 00.00
    SQL> set serveroutput on
    SQL> declare
      2  v_sql varchar2(200);
      3  v_temp number;
      4  begin
      5  select max(1) into v_temp from user_tables where table_name='TT';
      6  if v_temp is null then
      7     execute immediate 'create table tt (col number)';
      8  else
      9     execute immediate 'select col from tt where rownum=1' into v_temp;
     10  end if;
     11  dbms_output.put_line(v_temp);
     12  end;
     13  /
    11PL/SQL 过程已成功完成。已用时间:  00: 00: 00.00
    SQL>
      

  8.   

    to:bzszp(SongZip) 当表中无数据时执行时提示有问题。不过,你给我提供了思路,深表谢意!!