使用MyGeneration、doodads和Oracle XE,是否可以实现“自动编号主键”?方案?
使用MyGeneration、doodads和Oracle XE,是否可以实现“自动编号主键”方案?
问题事实: 我正在使用 Oracle XE。我已经实现了下表和触发器:
CREATE TABLE "USERS"
(
"ID" NUMBER(38,0),
"USER_NAME" VARCHAR2(50),
"PASSWORD" VARCHAR2(50),
"EMAIL" VARCHAR2(100),
CONSTRAINT "USERS_PK" PRIMARY KEY ("ID") ENABLE
)
/
CREATE OR REPLACE TRIGGER "BI_USERS"
before insert on "USERS"
for each row
begin
select "USERS_SEQ".nextval into :NEW.ID from dual;
end;
/
ALTER TRIGGER "BI_USERS" ENABLE
/
MyGeneration / Doodads 创建了以下存储过程...
CREATE OR REPLACE PROCEDURE "XXX"."PI_USERS"
(
p_ID IN USERS.ID%type,
p_USER_NAME IN USERS.USER_NAME%type,
p_PASSWORD IN USERS.PASSWORD%type,
p_EMAIL IN USERS.EMAIL%type
)
IS
BEGIN
INSERT
INTO USERS
(
ID,
USER_NAME,
PASSWORD,
EMAIL
)
VALUES
(
p_ID,
p_USER_NAME,
p_PASSWORD,
p_EMAIL
);
END PI_USERS;
序列和触发器组合工作正常。 C# 中的 BusinessEntity 类不会收到新 ID。
有什么推荐的方法可以让调用代码接收新的记录 ID?
Using MyGeneration, doodads, and Oracle XE, is it possible to implement an "auto number primary key" scheme?
Problem facts:
I am using Oracle XE. I have implemented the following table and trigger:
CREATE TABLE "USERS"
(
"ID" NUMBER(38,0),
"USER_NAME" VARCHAR2(50),
"PASSWORD" VARCHAR2(50),
"EMAIL" VARCHAR2(100),
CONSTRAINT "USERS_PK" PRIMARY KEY ("ID") ENABLE
)
/
CREATE OR REPLACE TRIGGER "BI_USERS"
before insert on "USERS"
for each row
begin
select "USERS_SEQ".nextval into :NEW.ID from dual;
end;
/
ALTER TRIGGER "BI_USERS" ENABLE
/
MyGeneration / Doodads created the following stored proc...
CREATE OR REPLACE PROCEDURE "XXX"."PI_USERS"
(
p_ID IN USERS.ID%type,
p_USER_NAME IN USERS.USER_NAME%type,
p_PASSWORD IN USERS.PASSWORD%type,
p_EMAIL IN USERS.EMAIL%type
)
IS
BEGIN
INSERT
INTO USERS
(
ID,
USER_NAME,
PASSWORD,
EMAIL
)
VALUES
(
p_ID,
p_USER_NAME,
p_PASSWORD,
p_EMAIL
);
END PI_USERS;
The sequence and trigger combination is working fine. The BusinessEntity class in C# does not receive the new ID.
Any recommended ways to allow the calling code receive the new record ID?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有使用过 Doodads,所以不确定这是否是它所期望的,但是如果您使用
returning
子句更改如下过程并将 p_ID 参数in out
执行后p_ID参数应该保存新添加的ID。I haven't used Doodads, so not sure if this is what it is expecting, but if you change the procedure like below using the
returning
clause and make the p_ID parameterin out
the p_ID parameter should hold the newly added ID after it is executed.为什么不使用序列呢?如果您偏好使用 TAPI,我仍然认为 ID 和 WHO 列最好在序列的触发器中提供。问题是需要一个没有跳过数字的纯净、密集的序列吗?
Why not use a sequence? If your preference is to use TAPI I still think the ID and WHO columns are best served in a trigger on a sequence. Is the issue the need for a pure, dense sequence where there are no skipped numbers?