使用MyGeneration、doodads和Oracle XE,是否可以实现“自动编号主键”?方案?

发布于 2024-08-29 18:45:51 字数 1101 浏览 4 评论 0原文

使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Smile简单爱 2024-09-05 18:45:51

我没有使用过 Doodads,所以不确定这是否是它所期望的,但是如果您使用 returning 子句更改如下过程并将 p_ID 参数 in out 执行后p_ID参数应该保存新添加的ID。

CREATE OR REPLACE PROCEDURE "XXX"."PI_USERS"
(
    p_ID IN OUT 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
    )
    RETURNING ID INTO p_ID;

END PI_USERS;

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 parameter in out the p_ID parameter should hold the newly added ID after it is executed.

CREATE OR REPLACE PROCEDURE "XXX"."PI_USERS"
(
    p_ID IN OUT 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
    )
    RETURNING ID INTO p_ID;

END PI_USERS;
骄傲 2024-09-05 18:45:51

为什么不使用序列呢?如果您偏好使用 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文