javaoracle-databasesqlj

using a sequence in sqlj?


I'm new to sqlj and try to insert data with an id generated by a sequence. This is my current code:

String pattern = ...;
#sql {INSERT INTO my_table (id, pattern) VALUES (my_seq.nextVal(), :(pattern))};

but I keep getting and ORA-02287 Error. Do I need to do it differently?


Solution

  • Omit the parentheses after nextval:

    #sql {INSERT INTO my_table (id, pattern) VALUES (my_seq.nextval, :(pattern))};