--自动增长
create sequence seq_bbs
increment by 1
start with 1
--过程语句
create or replace procedure proc_add_cito_add(p_title varchar2,p_content varchar2,p_user varchar2,p_section varchar2,p_readid out varchar2)
is
v_readid bbs_topic.topic_id%type;
begin
  v_readid:='ID:'||seq_bbs.nextval;--问题在这里,我不能调用seq_bbs.nextval,我想增加一条内容并且返回帖子的编号
insert into bbs_topic values(v_readid,p_title,p_content,p_user,p_section);
update bbs_user set scores=scores+1 where user_id=p_user;--根据发帖版块里面用户名数量来更新
update bbs_section set topic_count=topic_count+1 where section_id=p_section;--发表在那个版块那个版块加分
commit;
p_readid:=v_readid;
exception
when others then
rollback;
end proc_add_cito_add;--调用过程语句
declare
pre_readid bbs_topic.topic_id%type;
begin
proc_add_cito_add('JavaEE问题','传参数','John','S1',pre_readid);  
proc_add_cito_add('数据库问题','传参数','sss','S2',pre_readid);
dbms_output.put_line(pre_readid);--输出帖子编号
end;

解决方案 »

  1.   

    v_readid:='ID:'||seq_bbs.nextval;--换成这个
    select 'ID:'||seq_bbs.nextval
    into v_readid
    from dual;
      

  2.   

    谢谢2楼的朋友提醒了我,我下面根据你得修改好了
    --过程语句
    create or replace procedure proc_add_cito_add(p_title varchar2,p_content varchar2,p_user varchar2,p_section varchar2,p_readid out varchar2)
    is
    --v_readid bbs_topic.topic_id%type;
    begin
    --v_readid:='ID:'||seq_bbs.nextval;
    select 'ID:'||seq_bbs.nextval into p_readid from dual;--这里我根据你得修改了,我做复杂了insert into bbs_topic values(p_readid,p_title,p_content,p_user,p_section);
    update bbs_user set scores=scores+1 where user_id=p_user;--根据发帖版块里面用户名数量来更新
    update bbs_section set topic_count=topic_count+1 where section_id=p_section;--发表在那个版块那个版块加分
    --select 'ID:'||seq_bbs.nextval into v_readid from dual;
    commit;
    exception
    when others then
    rollback;
    end proc_add_cito_add;