Skip to content
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

Retrieve auto-generated ID from Oracle database #1466

Open
mchajii opened this issue May 25, 2021 · 0 comments
Open

Retrieve auto-generated ID from Oracle database #1466

mchajii opened this issue May 25, 2021 · 0 comments

Comments

@mchajii
Copy link

mchajii commented May 25, 2021

I'm using Oracle database and I'm facing an issue when trying to retrieve the last generated ID via an insert statement.
Oracle provides the possibility to retrieve the auto-generated keys using the getGeneratedKeys() method.

I built the below query following the doobie documentation:

          sql"insert into person (name, age) values ($name, $age)"
            .update
            .withUniqueGeneratedKeys[Long]("id")

Unfortunately, it doesn't work. I'm getting the following error:
java.sql.SQLSyntaxErrorException: ORA-00931: missing identifier

However, if I rewrite the query as follows it works fine:

        val sql = "insert into person (name, age) values ($name, $age)"
        Update[(String, Int)](sql)
          .withUniqueGeneratedKeys[Long]("id")(("Bob", 12))

I don't understand why the first query is failing. Is there any difference between the 2 queries ?

doobie version used: 0.12.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant