菜鸟一个存储过程。要METHOD_ID字段每插入一条记录便加1。大家帮忙修改
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) ;
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'));
create sequence month_id
increment by 1
start with 1
maxvalue 999999999
nocycle
cache 10
--删除原表对应数据
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,
remark,
context,
month_id
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;
/
问题点数:0、回复次数:8Top
1 楼z000001(阳光天时)回复于 2005-04-01 11:53:02 得分 0
题目有问题,修改,是表每增加一条记录,METHOD_ID字段自动加1。Top
2 楼gaosikai()回复于 2005-04-01 13:19:19 得分 0
首先,你的sequence不能在此创建,在外边创建好了,在这里直接用即可。
第二,使用时。
insert into dssf_suply_limit_fact(method_id) values(month_id.next_val)
Top
3 楼fuxia(双子星)回复于 2005-04-01 13:28:14 得分 0
是month_id.nextval!!Top
4 楼sohu98(天天)回复于 2005-04-01 13:51:47 得分 0
看了一下你写的过程,感觉有些错误
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 就可以了Top
5 楼z000001(阳光天时)回复于 2005-04-01 13:54:58 得分 0
讲CONTEXT字段的值插入到METHOD_CONTEXT字段中。两个字段都是BOOL型的。可以直接插吗?Top
6 楼z000001(阳光天时)回复于 2005-04-01 14:54:25 得分 0
只好自己顶一下Top
7 楼gzhughie(hughie)回复于 2005-04-01 19:31:20 得分 0
不用建sequence就可以实现Top
8 楼gzhughie(hughie)回复于 2005-04-01 19:35:00 得分 0
用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,
remark,
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;
/Top




