1

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?

4
  • yeah. that did it! Make it an answer and I will accept it. Commented Dec 30, 2015 at 14:08
  • Note: PL/SQL is based on Ada, not C, and as such you don't need to put parentheses after a function name to invoke it; as a matter of fact, if you DO put parentheses in where they're not wanted you'll get an error (as you've discovered). Best of luck. Commented Dec 31, 2015 at 2:37
  • the confusing thing was that I got an error that didn't lead me into thinking that there was a syntactical error. Commented Jan 4, 2016 at 13:06
  • Oracle is well known for producing error messages that are, to put it nicely, not obviously helpful. Best of luck. Commented Jan 4, 2016 at 16:17

2 Answers 2

2

Omit the parentheses after nextval:

#sql {INSERT INTO my_table (id, pattern) VALUES (my_seq.nextval, :(pattern))}; 
Sign up to request clarification or add additional context in comments.

Comments

2

Not expert on sqlJ, but in the SQL part you should use my_seq.nextVal, with no ()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.