java 里头对ORACLE中的自增字段如何插入呀?

quinton 2004-08-04 10:34:34
在JAVA 里头INSERT INTO TABLENAME (ID) VALUES (SEQ_NAME.NEXTVAL)老是报错,怎么回事.

老是说SEQ_NAME不认得?
...全文
227 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dinya2003 2004-08-04
  • 打赏
  • 举报
回复
--创建序列
create sequence seq_name
increment by 1
start with 1
maxvalue 99999999
nocycle
cache 10

这样才可以调用seq_name.nextval
Guohui 2004-08-04
  • 打赏
  • 举报
回复
你先用statement 检查一下权限,如果可以,那么你上面的语句是ok的,因为这个语句是在oracle 中执行的,和前端语言没关系
bzszp 2004-08-04
  • 打赏
  • 举报
回复
SEQ_NAME这个序列你创建了没有?
看一下你连接的用户是否有权限
yujiabian 2004-08-04
  • 打赏
  • 举报
回复
你首先应该明白你的SEQ_NAME序列创建了没有?如果创建了,那还要看你当前的链接用户有无权限
xqg1130 2004-08-04
  • 打赏
  • 举报
回复

REM =======關務料件每日使用量信息表======
REM id //自動增1的編號
REM dzzc_id //電子賬冊號
REM gwdm_id //關務代碼
REM cpba_id //成品備案號
REM version_id //成品版本號
REM ljba_id //料件備案號
REM gwyl //關務用量
REM ch_date //出貨日期
REM 本表根據系統中的出貨計劃計算每日的每個料件的關務使用量


drop table gwyl;
create table gwyl(
id number(15,0) not null,
dzzc_id varchar2(15 byte) not null,
gwdm_id varchar2(6 byte) not null,
cpba_id number(4,0) not null,
version_id number(3,0) not null,
ljba_id number(4,0) not null,
gwyl number(15,3) not null,
ch_date date not null,
constraint gwyl_id_pk primary key(id) using index tablespace cpindex
)TABLESPACE "LOGISTIC" PCTFREE 10 PCTUSED 0 INITRANS 1
MAXTRANS 255 STORAGE (
INITIAL 64K NEXT 0K MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0)
LOGGING ;


REM 創建一個自動增1的序列
drop sequence gwyl_id_seq;
create sequence gwyl_id_seq
nocycle
maxvalue 999999999999999
start with 1
order
increment by 1;


REM ==========創建執行自動增加主鍵字段的一個触發器=============
drop trigger gwyl_id_trigger;
create or replace trigger gwyl_id_trigger
before insert on gwyl
for each row
declare
next_id number;
begin
--get the next id from the sequence
select gwyl_id_seq.nextval
into next_id
from dual;
--use the sequence number as primary
--for the record begin inserted
:new.id:=next_id;
end ;
/


REM 創建一個防止ID字段被更新的触發器
drop trigger gwyl_id_upd;
create or replace trigger gwyl_id_upd
before update of id on gwyl
for each row
begin
raise_application_error(-2000,'update column id on table gwyl are not allowed.');
end;
/

17,088

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧