declare
    a int;
    begin
    select  max(ec_id)  into a from easybuy_comment;  
   create sequence  commentid 
   minvalue 1
   maxvalue 999999
   start with  a
   increment by 1
   case 20;
   end;

解决方案 »

  1.   

    declare
      a int;
      begin
      select max(ec_id) into a from easybuy_comment; 
      --DDL在PL/SQL中只能动态执行
      execute immediate
      'create sequence commentid 
      minvalue 1
      maxvalue 999999
      start with '|||a|'
      increment by 1
      case 20';
    end;
      

  2.   

     create sequence commentid  --创建序列名字commentid
      minvalue 1     --  最小值
      maxvalue 999999  --  最大值
      start with 1    --   开始值  
      increment by 1  --每次增长值
      cache 20;   --缓存大小  
      

  3.   


    declare
      a     int;
      v_sql varchar2(500);
    begin
      select max(ec_id) into a from easybuy_comment;
      --ddl语句不能直接在plsql里执行,要通过动态语句执行
      v_sql := 'create sequence commentid minvalue 1 maxvalue 9999 start with ' || a ||
               ' increment by 1 case 20';
      execute immediate v_sql;
    end;
      

  4.   


    create or replace procedure p_createseq(tablename in varchar2) is
      strsql varchar2(500);
      a      NUMBER(4) := 0;
    begin
      select 100 into a from dual;
      strsql := 'create sequence seq_' || tablename ||
                ' minvalue 1000 maxvalue 99999999 start with 1000 increment by ' || a ||
                ' nocache';
      execute immediate strsql;
    end p_createseq;
      

  5.   


    create or replace procedure p_createseq(tablename in varchar2) is
      strsql varchar2(500);
      a      NUMBER(4) := 0;
    begin
     select max(ec_id) into a from easybuy_comment;
      strsql := 'create sequence seq_' || tablename ||
                ' minvalue 1000 maxvalue 99999999 start with 1000 increment by ' || a ||
                ' nocache';
      execute immediate strsql;
    end p_createseq;
      

  6.   


    create or replace procedure p_createseq(tablename in varchar2) is
      strsql varchar2(500);
      a      NUMBER(4) := 0;
    begin
     select max(ec_id) into a from easybuy_comment;
      strsql := 'create sequence seq_' || tablename ||
                ' minvalue 1000 maxvalue 99999999 start with 1000 increment by ' || a ||
                ' nocache';
      execute immediate strsql;
    end p_createseq;
      

  7.   

    还是搞不定,总是说SQL命令未正确结束.
      

  8.   


    create or replace procedure p_createseq(tablename in varchar2) is
       /*错误位置在case需要改成cache*/
      strsql varchar2(500);
      a      NUMBER(4) := 0;
    begin
      select max(ec_id) into a from easybuy_comment;
      strsql := 'create sequence seq_' || tablename ||
                ' minvalue 1 maxvalue 9999 start with :a
                increment by 1 cache 20'; 
      execute immediate strsql using a;
    end p_createseq;
      

  9.   


    create or replace procedure p_createseq(tablename in varchar2) is
       /*错误位置在case需要改成cache 这个是正确的 */
      strsql varchar2(500);
      a      NUMBER(4) := 0;
    begin
      select max(ec_id) into a from easybuy_comment;
      strsql := 'create sequence seq_' || tablename ||
                ' minvalue 1 maxvalue 9999 start with '||a||'
                increment by 1 cache 20'; 
      execute immediate strsql;
    end p_createseq;
      

  10.   

    declare
      a     int;
      v_sql varchar2(500);
    begin
      select max(id) into a from sys_user;
      --ddl语句不能直接在plsql里执行,要通过动态语句执行
      v_sql := 'create sequence commentid minvalue 1 maxvalue 9999 start with ' || a ||
              ' increment by 1 cache 20'; --3楼这里写错了 是cache不是case 这个语句应该是没错的
      execute immediate v_sql;
    end;