-
-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does the extension method InsertGetId works for Oracle? #465
Comments
I don't think so, could you provide what is the correct way to fetch the last inserted id in Oracle so we can implement it |
Sorry I'm not an expert of Oracle but at the moment when I call the method InsertGetId with an Oracle database it returns an exception "The sequence is empty", by the way the row is inserted. After looking the code it seems not implemented for the Oracle compiler. Why not returning a NotImplementedException istead in this case with a message? I searched a bit now for a possible solution, I found https://oracle-base.com/articles/misc/dml-returning-into-clause. I tried it with the SqlDeveloper and seems working. The only problem seems that it is necessary tell the OracleCompiler what is the name of the autogenerated column (In my case "Id"). This is my try: SET SERVEROUTPUT ON DBMS_OUTPUT.put_line(last_generated_id); |
Actually the Oracle support is a bit struggling, since we don't have a ready environment for Oracle, throwing I will keep this open, since we need more research to evaluate what is the best way for different Oracle versions. |
Hi Ahmad, I am currently implementing Oracle support in my data library (which uses SqlKata) and today I confirmed that appending the following to my INSERT command does indeed work for Oracle: var identityField = "REGION_ID";
// Append Oracle identity query + output parameter
cmd.CommandText = cmd.CommandText + $" returning \"{identityField}\" into :outputParam";
var outputParam = cmd.CreateParameter();
outputParam.ParameterName = "outputParam";
outputParam.DbType = System.Data.DbType.Decimal;
outputParam.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outputParam);
await cmd.ExecuteNonQueryAsync();
var returnId = System.Convert.ChangeType(outputParam.Value, typeof(int)); Oracle table definition: CREATE TABLE regions
(
region_id NUMBER(10,0) GENERATED BY DEFAULT AS IDENTITY
START WITH 5 PRIMARY KEY,
region_name VARCHAR2(50) NOT NULL
); It's a little different from SQL Server in that you must use an output parameter + |
Also, if you are using Docker for your test databases, I would be happy to contribute the custom Oracle docker image that I am in the process of tweaking now for Oracle development in my project. |
Hello, thanks for developing this project.
Does the extension method InsertGetId works for Oracle?
The text was updated successfully, but these errors were encountered: