我想检验我的A表中有多少条记录,超过5条后,就把A中的数据给B表,然后删除A表,现在出现错误,
想请教高手为什么错了??????
create or replace procedure Pro_Tab_A_B
is
tab_a_count integer;
begin
  select count(pid) tab_a_count from A;
  if tab_a_count > 5 then
    create or replace table B as select * from A;
    delete from A;
  end if;
end;
/

解决方案 »

  1.   

    select count(pid) into tab_a_count from A;
      

  2.   

    create or replace procedure Pro_Tab_A_B
    is
    tab_a_count number;
    begin
      select count(pid) into tab_a_count from A;
      if tab_a_count > 5 then
        insert into B as select * from A;
        delete from A;
        commit;
      end if;
    end;
    /
      

  3.   

    变更一下insert into B as select * from A;as 去掉
      

  4.   

    create or replace table B as select * from A; 改成:
    EXECUTE IMMEDIATE 'create  table B as select * from A';试试
      

  5.   

    我觉得还是不要在pl/sql里面动态执行sql了,直接先建表,把B建好,然后按照miaoyuli的方法应该就能搞定了:)
      

  6.   

    可是没有道理啊,我刚才按照miaoyuli得方法作了,我现在有表了,但是还是出现"编译错误"。。
    这个存储过程很难么????
      

  7.   

    这个其实是非常简单的,可能有用户的问题吧,你把表前面加上相应的用户名试试,select count(pid) into tab_a_count from A;改成select count(pid) into tab_a_count from username.A;以此类推
      

  8.   

    用户都是scott,我就是用scott用户。。
      

  9.   

    create or replace procedure Pro_Tab_A_B
    is
    tab_a_count number;
    begin
      select count(pid) into tab_a_count from scott.A;
      if tab_a_count > 5 then
        insert into scott.B  select * from scott.A;
        delete from scott.A;
        commit;
      end if;
    end;
    /
      

  10.   

    你没有讲清楚,特别是报什么错误,那一行代码错了。
    另外,你两个表结构是否一样?如果不一样,这样是错的。
    你是想drop table A还是删除里面数据?还有,
    select count(pid) tab_a_count from A;改成 select count(*) into tab_a_count from A;
    试试看
      

  11.   

    create or replace procedure Pro_Tab_A_B
    is
    tab_a_count number;
    begin
      select count(pid) into tab_a_count from scott.A;
      if tab_a_count > 5 then
        insert into scott.B  select * from scott.A;
        delete from scott.A;
        commit;
      end if;
    end;
    /