Oracle get id of inserted row with identity always [duplicate]

孤街浪徒 提交于 2021-01-04 04:23:17

问题


Currently I have a table with this structure:

CREATE TABLE "DUMMY_SCHEMA"."NAMES"
(
  "ID" NUMBER(10,0) GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1 CACHE 20) NOT NULL 
, "NAME" NVARCHAR2(1024) NOT NULL 
, CONSTRAINT "NAMES_PK" PRIMARY KEY ("ID")
);

In SQL Server I only need to do following to get the Id of the inserted row.

INSERT INTO [NAMES]([NAME])VALUES('Random'); SELECT SCOPE_IDENTITY() Id

What would be the equivalent for Oracle 12c?


回答1:


The equivalent is

INSERT INTO dummy_schema.names (name) VALUES ('Random') 
RETURNING id INTO :myvalue;

The mechanism how to pick up the returned ID depends on the host language (Java, PL/SQL, SQL*Plus etc).



来源:https://stackoverflow.com/questions/51050491/oracle-get-id-of-inserted-row-with-identity-always

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!