题目有问题,修改,是表每增加一条记录,METHOD_ID字段自动加1。

解决方案 »

  1.   

    首先,你的sequence不能在此创建,在外边创建好了,在这里直接用即可。
    第二,使用时。
    insert into dssf_suply_limit_fact(method_id)  values(month_id.next_val)
      

  2.   

    看了一下你写的过程,感觉有些错误
    1,pl/sql中只能使用DML语句,不能使用DDL语句,所以不能在过程中创建sequence。也可以使用动态sql创建

    declare
     v_exist user_objects.object_name%type;
    begin
     select uo.object_name
     into v_exist
     from user_objects uo
     where uo.object_name = upper('month_id'); dbms_output.put_line('sequence already exist');exception
        when others then
        execute immediate 'create sequence month_id '||
                          'increment by 1 '||
                          'start with 1 '||
                          'nomaxvalue '||
                          'nominvalue '||
                          'noorder '||
                          'nocycle '||
                          'cache 10';
        commit;    
        dbms_output.put_line('create new sequence');
    end;插入数据的时候直接使用 month_id.nextval 就可以了
      

  3.   

    讲CONTEXT字段的值插入到METHOD_CONTEXT字段中。两个字段都是BOOL型的。可以直接插吗?
      

  4.   

    用rownum实现:CREATE OR REPLACE procedure pipe_gy_suply_limit
    (
    time_year char,
    time_mont char,
    v_result out varchar2
    )
    AS
    v_month number(10);
    v_year number(4) ;
    v_mon number(2) ;
    i_maxID number(32);
    begin
                v_month:=to_number(to_char(to_date(trim(time_year)||'-'||trim(time_mont)||'-01','yyyy-mm-dd')));
        v_year := to_number(to_char(v_begin_date,'yyyy'));
        v_mon := to_number(to_char(v_begin_date,'mm'));            SELECT MAX(method_id) INTO i_maxID FROM dssf_suply_limit_fact; --删除原表对应数据
    delete  from dssf_suply_limit_fact where day_id=v_month;
    commit;
    --插入值
                            insert into dssf_suply_limit_fact
                            (
                                day_id,
                                unit_code,
                                dept_id,
                                bureau_id,
                                flag,
                                method_name,
                                method_context,
                                method_id
                            )
                            select
                            v_month,
                            dime_valu_id,
                            40,
                            1,
                            1,
                            re,
                            context,
                            i_maxID+ROWNUM
                            from dbo.report_stat_content@gynd a,dssd_unit b where b.dime_valu_id=a.dpt_no
                            and a.report_no='sjr003' 
                            and to_number(to_char(to_date(a.stat_date,'yyyy-mm')))=to_number(time_year||time_mont);
                            commit;

    v_result:='业扩报装事实数据抽取成功!';
    exception
    when others then
    rollback;
    v_result:='业扩报装事实数据抽取失败!';
     end;
    /