菜鸟一个存储过程。要METHOD_ID字段每插入一条记录便加1。大家帮忙修改 题目有问题,修改,是表每增加一条记录,METHOD_ID字段自动加1。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先,你的sequence不能在此创建,在外边创建好了,在这里直接用即可。第二,使用时。insert into dssf_suply_limit_fact(method_id) values(month_id.next_val) 看了一下你写的过程,感觉有些错误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 就可以了 讲CONTEXT字段的值插入到METHOD_CONTEXT字段中。两个字段都是BOOL型的。可以直接插吗? 用rownum实现:CREATE OR REPLACE procedure pipe_gy_suply_limit(time_year char,time_mont char,v_result out varchar2)ASv_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:='业扩报装事实数据抽取成功!';exceptionwhen others thenrollback;v_result:='业扩报装事实数据抽取失败!'; end;/ OracleServiceORCL服务和OracleServiceORA服务 导入DMP 初学oracle,调用过程出错,思考很久没有答案,望大大指教,谢谢! 帮忙给写个修改oracle 里面修改一个字段的sql吧 如何导出oracle数据库的sql 脚本? oracle中为什么无发输入中文 在程序中如何判断Oracle 的Listen是否启动? 2000 ad server下安装oracle 9时要求插入磁盘 2?怎么解决? 急寻学习oracle的资料 一个小问题谢谢。查找凶手? pro*c的问题 弱弱的问题 比较急 求教数据库读取问题
第二,使用时。
insert into dssf_suply_limit_fact(method_id) values(month_id.next_val)
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 就可以了
(
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;
/