插入序列并选择

发布于 2024-11-19 01:40:12 字数 479 浏览 3 评论 0原文

我正在尝试插入到一个表中,其中 ID 是序列中的下一个,并且从表中提取一些其他值。我知道这行不通:

INSERT INTO ORDERS(order_id, foo1, foo2, foo3
VALUES(SEQUENCE_ORDERS.nextval,(SELECT foo1, foo2, foo3
                                FROM bar
                                WHERE X = Y))

我刚刚尝试过,但出现“值不足”错误。

我想知道让它工作的正确语法是什么。我在 Oracle DB 中使用 PLSQL(我正在编写的过程的一部分)。

我知道选择不应位于 VALUES() 内部,但如何添加序列?我能想到的唯一选择是插入物上的触发器,但我宁愿不必这样做。

编辑:谢谢大家,正如我所想的那样,每个人都发帖了。不知道在选择中包含序列是否可以。

I'm trying to insert into a table, where the ID is the next in a sequence, and some of the other values are pulled from a table. I know that this won't work:

INSERT INTO ORDERS(order_id, foo1, foo2, foo3
VALUES(SEQUENCE_ORDERS.nextval,(SELECT foo1, foo2, foo3
                                FROM bar
                                WHERE X = Y))

I just tried, and it I get a "not enough values" error.

I wanted to know what the correct syntax was to get this to work. I'm using PLSQL in an Oracle DB (part of a procedure I'm writing).

I know that the select should not be inside the VALUES() but how do I also add the sequence? The only option I can think of would be a trigger on the insert, but I'd rather not have to do that.

EDIT: thank you all, just as I figured it out, everyone posted. Didn't know it was ok to have the sequence in the select.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

坐在坟头思考人生 2024-11-26 01:40:12
INSERT INTO ORDERS(order_id, foo1, foo2, foo3)
SELECT SEQUENCE_ORDERS.nextval,foo1, foo2, foo3
                                FROM bar
                                WHERE X = Y
INSERT INTO ORDERS(order_id, foo1, foo2, foo3)
SELECT SEQUENCE_ORDERS.nextval,foo1, foo2, foo3
                                FROM bar
                                WHERE X = Y
蝶…霜飞 2024-11-26 01:40:12

尝试:

INSERT INTO ORDERS(order_id, foo1, foo2, foo3
SELECT SEQUENCE_ORDERS.nextval, foo1, foo2, foo3
                                FROM bar
                                WHERE X = Y

Try:

INSERT INTO ORDERS(order_id, foo1, foo2, foo3
SELECT SEQUENCE_ORDERS.nextval, foo1, foo2, foo3
                                FROM bar
                                WHERE X = Y
我只土不豪 2024-11-26 01:40:12

尝试将 SEQUENCE 移至 SELECT 语句。

Try moving the SEQUENCE over to the SELECT statement.

驱逐舰岛风号 2024-11-26 01:40:12

插入 DON AUDITI(DON SEO_ID.NEXTVAL、I OLDCUSTED、I MENCUSTED)
值('T_CRED NEXUS _CUST ACCESS',I.PEOPLEVISE_ID,I_CREATEDBY,SYSDATE);

INSERT into DON AUDITI (DON SEO_ID. NEXTVAL, I OLDCUSTED, I MENCUSTED)
values ('T_CRED NEXUS _CUST ACCESS' , I. PEOPLEVISE_ID, I_CREATEDBY, SYSDATE);

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